SECARSP-274 +Get device function
authorm.dalakov <m.dalakov@samsung.com>
Wed, 28 Mar 2018 14:38:48 +0000 (17:38 +0300)
committerm.dalakov <m.dalakov@samsung.com>
Wed, 28 Mar 2018 14:39:30 +0000 (17:39 +0300)
server/samserver/src/main/java/com/samsung/samserver/web/rest/controller/IRestDashboard.java
server/samserver/src/main/java/com/samsung/samserver/web/rest/controller/impl/RestDashboard.java
server/samserver/src/main/java/com/samsung/samserver/web/rest/service/ui/GetDevicesRestService.java
server/samserver/src/main/java/com/samsung/samserver/web/rest/service/ui/UpdateDevicePoliciesRestService.java
server/samserver/src/main/java/com/samsung/samserver/web/rest/service/ui/UpdateDevicesRestService.java

index 24fc686..9af1c1f 100644 (file)
@@ -41,6 +41,23 @@ public interface IRestDashboard {
 
 
     /**
+     * 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
index a3c07c2..9570d5d 100644 (file)
@@ -57,6 +57,16 @@ public class RestDashboard  implements IRestDashboard {
     }
 
     /**
+     * GET  /device?id=<device_id>: get the device
+     *
+     * @return the ResponseEntity with status 200 (OK) and the device in body
+     */
+    @Override
+    public ResponseEntity<UIDevice> getDevice(@RequestParam(value = "id") Long id) {
+        return getDevicesRestService.getDevice(id);
+    }
+
+    /**
      * POST request login
      *
      * @return the ResponseEntity with status 200 (OK) and JWT
index fc47461..123da2c 100644 (file)
@@ -15,10 +15,12 @@ import org.springframework.data.domain.*;
 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
@@ -35,7 +37,7 @@ public class GetDevicesRestService {
     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) {
@@ -59,4 +61,27 @@ public class GetDevicesRestService {
         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
index 8636d44..07016ac 100644 (file)
@@ -26,7 +26,7 @@ import static com.samsung.samserver.web.rest.service.vm.UIPoliciesUpdate.*;
 import static com.samsung.samserver.web.rest.service.vm.UIPolicies.*;
 
 /**
- * REST service implementation for get updates.
+ * REST service implementation for update device policy.
  *
  * @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
  * @version 1.0
index 2d3cd22..ddbc97d 100644 (file)
@@ -18,7 +18,7 @@ import javax.validation.Valid;
 import java.util.*;
 
 /**
- * REST service implementation for get updates.
+ * REST service implementation for update device.
  *
  * @author <A HREF="mailto:m.dalakov@samsung.com">Mykhailo Dalakov</A>
  * @version 1.0