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 cabd2f8b9b..b8c626cb41 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 @@ -493,7 +493,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (HttpReportingUtil.isTrackerEnabled()) { String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); - JSONObject obj = new JSONObject(DeviceAPIClientServiceImpl.returnUser(currentUser)); + DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService(); + JSONObject obj = new JSONObject(deviceAPIClientService.returnUser(currentUser)); if (obj.has("error")) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build(); @@ -503,7 +504,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { /*Get Device Id List*/ try { DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); - DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService(); DeviceAccessAuthorizationService deviceAccessAuthorizationService = DeviceMgtAPIUtils.getDeviceAccessAuthorizationService(); PaginationRequest request = new PaginationRequest(0, 0); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java index 0aea251f31..73aca76059 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java @@ -86,7 +86,7 @@ public interface DeviceAPIClientService { void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException; -// String returnUser(String username); + String returnUser(String username); TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java index c9ffbe9064..193bdb211c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java @@ -183,7 +183,7 @@ public class TraccarClientFactory { public String returnUser(String userName) throws TrackerManagementDAOException { try { - String result = DeviceAPIClientServiceImpl.fetchUserInfo(userName); + String result = fetchUserInfo(userName); Date today = new Date(); LocalDateTime tomorrow = LocalDateTime.from(today.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); String token = DeviceAPIClientServiceImpl.generateRandomString(TraccarHandlerConstants.Types.TRACCAR_TOKEN); @@ -224,6 +224,7 @@ public class TraccarClientFactory { } DeviceAPIClientServiceImpl.updateUser(traccarUser, obj.getInt("id")); } + result = fetchUserInfo(userName); return result; } catch (InterruptedException | ExecutionException e) { JSONObject obj = new JSONObject(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java index f6a0e3fc73..9095f3dd5b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java @@ -114,11 +114,11 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { client.deleteGroup(groupId, tenantId); } -// @Override - public static String returnUser(String userName) { + @Override + public String returnUser(String username) { TraccarClientFactory client = TraccarClientFactory.getInstance(); try { - return client.returnUser(userName); + return client.returnUser(username); } catch (TrackerManagementDAOException e) { JSONObject obj = new JSONObject(); String msg = "Error occurred while creating a user: "+ e;