[NO-TICKET] +add geoIP
[platform/core/security/suspicious-activity-monitor.git] / server / src / main / java / com / samsung / samserver / web / rest / service / GetDevicesUIRestService.java
index 2564e58..4d4bbb3 100644 (file)
@@ -8,6 +8,7 @@ package com.samsung.samserver.web.rest.service;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import com.samsung.samserver.domain.Device;
 import com.samsung.samserver.service.DeviceService;
+import com.samsung.samserver.service.impl.GeoIPService;
 import com.samsung.samserver.web.rest.util.PaginationUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.*;
@@ -18,6 +19,8 @@ import java.time.Instant;
 import java.util.*;
 import lombok.*;
 
+import static com.samsung.samserver.service.impl.GeoIPService.GeoIP;
+
 /**
  * REST service implementation for get updates.
  *
@@ -32,6 +35,9 @@ public class GetDevicesUIRestService {
     @Autowired
     private DeviceService deviceService;
 
+    @Autowired
+    private GeoIPService geoIPService;
+
     public ResponseEntity<List<GetDevicesUIRestService.UIDevice>> getAllDevices(Pageable pageable) {
         log.debug("UI request to get all devices"); //NOSONAR
         Page<Device> devices = deviceService.findAll(pageable);
@@ -48,6 +54,7 @@ public class GetDevicesUIRestService {
             uiDevice.setLocked(device.getLocked()!=null && !device.getLocked().equals("0") ? 1:0);
             uiDevice.setUiDeviceOS(new UIDeviceOS(device.getSw(), device.getOsname(), device.getOsver()));
             uiDevice.setUiDeviceType(new UIDeviceType (device.getDtype().getName(), device.getDtype().getDescr()));
+            uiDevice.setGeoIP(geoIPService.getGeo(device.getIpaddr()));
             uiDevices.add(uiDevice);
         }
         Page<UIDevice> page = new PageImpl(uiDevices, pageable, devices.getTotalPages());
@@ -86,6 +93,9 @@ public class GetDevicesUIRestService {
 
         @JsonProperty("os")
         private UIDeviceOS uiDeviceOS;
+
+        @JsonProperty("geo")
+        private GeoIP geoIP;
     }
 
     @Getter @Setter @ToString