[NO-TICKET] *expand device registration info
[platform/core/security/suspicious-activity-monitor.git] / server / src / main / java / com / samsung / samserver / web / rest / service / RegisterDeviceRestService.java
index b65ac7c..cb5cfd9 100644 (file)
@@ -40,16 +40,19 @@ public class RegisterDeviceRestService {
     public ResponseEntity<String> registerDevice(@Valid @RequestBody DInfo dInfo) {
         log.debug("request to register device : {}", dInfo);
 
-        Optional<DeviceType> dt =  deviceTypeService.findOne(dInfo.getType());
+        String dtype = dInfo.getType().toLowerCase();
+        Optional<DeviceType> dt =  deviceTypeService.findOne(dtype);
         if (!dt.isPresent()) {
-            throw new DeviceServiceError.DeviceTypeNotFoundException();
+            dt = Optional.of(new DeviceType(dtype,"new type: created sn "+dInfo.getSn()));
+            deviceTypeService.save(dt.get());
         }
 
-        String duid = deviceService.getDeviceUID(dInfo.getType(), dInfo.getModel(), dInfo.getSn());
+        String duid = deviceService.getDeviceUID(dtype, dInfo.getModel(), dInfo.getSn());
         deviceService.findOne(duid).ifPresent(d -> {throw new DeviceServiceError.DeviceAlreadyRegisteredException();});
 
         Device result = deviceService.save(
-            new Device(duid, dInfo.getModel(), dInfo.getDos(), dInfo.getSn(), dInfo.getDescr(), dt.get()));
+            new Device(duid, dInfo.getModel(), dInfo.getLocation(), dInfo.getSn(), dInfo.getDescr(), dt.get(),
+                dInfo.getSw(), dInfo.getOsname(), dInfo.getOsver()));
 
         return ResponseEntity.ok()
             .headers(new HttpHeaders())
@@ -69,9 +72,8 @@ public class RegisterDeviceRestService {
         @NotNull
         private String model;
 
-        @JsonProperty("dos")
-        @NotNull
-        private String dos;
+        @JsonProperty("location")
+        private String location;
 
         @JsonProperty("sn")
         @NotNull
@@ -79,6 +81,17 @@ public class RegisterDeviceRestService {
 
         @JsonProperty("descr")
         private String descr;
+
+        @JsonProperty("sw")
+        private String sw;
+
+        @JsonProperty("osname")
+        @NotNull
+        private String osname;
+
+        @JsonProperty("osver")
+        @NotNull
+        private String osver;
     }
 
 }