diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 71646f98cd..d4939b313f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -532,12 +532,15 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { for (Device device : devices.getList()) { TrackerDeviceInfo trackerDevice = DeviceAPIClientServiceImpl .getTrackerDevice(device.getId(), tenantId); - int traccarDeviceId = trackerDevice.getTraccarDeviceId(); - boolean getPermission = DeviceAPIClientServiceImpl.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); - traccarValidIdList.add(traccarDeviceId); - if (!getPermission) { - DeviceAPIClientServiceImpl.addTrackerUserDevicePermission(userId, traccarDeviceId); + if (trackerDevice != null) { + int traccarDeviceId = trackerDevice.getTraccarDeviceId(); + boolean getPermission = DeviceAPIClientServiceImpl.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); + traccarValidIdList.add(traccarDeviceId); + if (!getPermission) { + DeviceAPIClientServiceImpl.addTrackerUserDevicePermission(userId, traccarDeviceId); + } } + } //Remove necessary List getAllUserDevices = @@ -569,6 +572,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } + /*Get Device Id List*/ return Response.status(Response.Status.OK).entity(obj.getString("token")).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java index 526de67f61..3efaefb191 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java @@ -465,6 +465,7 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.closeConnection(); } + //check if the device is already exist before updating the location if (trackerDeviceInfo == null) { //add device if not exist @@ -481,7 +482,8 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), - "http://localhost:")); + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[0] + ":" + + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[1] + ":")); } } @@ -579,7 +581,7 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - + log.info("---------result--------"); if (result.charAt(0) == '{') { JSONObject obj = new JSONObject(result); if (obj.has("id")) {