/**
+ * GET /device?id=<device_id>: get the device
+ *
+ * @return the ResponseEntity with status 200 (OK) and the device in body
+ */
+ @ApiOperation(value = "get device", notes = "The “get device” operation is used to obtain registered device.")
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "OK. Request executed successfully."),
+ @ApiResponse(code = 400, message = "Bad Request. The reason is contained in the tags “errorKey”, “message”, “title”"),
+ @ApiResponse(code = 500, message = "Internal server error. The user has to repeat action.")
+ })
+ @RequestMapping(value ="/device", method = RequestMethod.GET)
+ @ResponseStatus(HttpStatus.OK)
+ public ResponseEntity<UIDevice> getDevice(
+ @ApiParam(value = "device id", required = true) @RequestParam(value = "id") Long id);
+
+
+ /**
* POST request login
*
* @return the ResponseEntity with status 200 (OK) and JWT
import org.springframework.stereotype.Service;
import org.springframework.http.*;
import org.slf4j.*;
+import org.springframework.web.bind.annotation.RequestParam;
+
import java.util.*;
/**
- * REST service implementation for get updates.
+ * REST service implementation for get device.
*
* @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
* @version 1.0
private GeoIPService geoIPService;
public ResponseEntity<List<UIDevice>> getAllDevices(Pageable pageable) {
- log.debug("UI request to get all devices"); //NOSONAR
+ log.debug("UI request: {}", "get all devices");
Page<Device> devices = deviceService.findAll(pageable);
List<UIDevice> uiDevices = new ArrayList<>();
for (Device device: devices) {
return new ResponseEntity<>(page.getContent() , headers, HttpStatus.OK);
}
+
+ public ResponseEntity<UIDevice> getDevice(@RequestParam(value = "id") Long id) {
+ log.debug("UI request: {}", "get device");
+ Device device = deviceService.findOne(id);
+ UIDevice uiDevice = UIDevice.builder()
+ .id(device.getId())
+ .duid(device.getDuid())
+ .ctime(device.getCtime())
+ .model(device.getModel())
+ .ipaddr(device.getIpaddr())
+ .sn(device.getSn())
+ .descr(device.getDescr())
+ .locked(device.getLocked()!=null && !device.getLocked().equals("0") ? 1:0)
+ .uiDeviceOS(new UIDevice.UIDeviceOS(device.getSw(), device.getOsname(), device.getOsver()))
+ .uiDeviceType(new UIDevice.UIDeviceType(device.getDtype().getName(), device.getDtype().getDescr()))
+ .geoIP(geoIPService.getGeo(device.getIpaddr()))
+ .build();
+
+ final HttpHeaders httpHeaders = new HttpHeaders();
+ httpHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
+ return new ResponseEntity<>(uiDevice , httpHeaders, HttpStatus.OK);
+ }
+
}
\ No newline at end of file