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 1b85a4c9ba..cabd2f8b9b 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,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (HttpReportingUtil.isTrackerEnabled()) { String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); - JSONObject obj = new JSONObject(DeviceMgtAPIUtils.getDeviceAPIClientService().returnUser(currentUser)); + JSONObject obj = new JSONObject(DeviceAPIClientServiceImpl.returnUser(currentUser)); if (obj.has("error")) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build(); @@ -535,11 +535,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { TrackerDeviceInfo trackerDevice; for (Device device : devices.getList()) { trackerDevice = deviceAPIClientService.getTrackerDevice(device.getId(), tenantId); - if(trackerDevice == null) { - String msg = "Tracker device not found for the device ID: " + device.getId(); - log.error(msg); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); - } else { + if(trackerDevice != null) { int traccarDeviceId = trackerDevice.getTraccarDeviceId(); boolean getPermission = deviceAPIClientService.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); traccarValidIdList.add(traccarDeviceId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java index a3d1ccf8af..8066bc311c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java @@ -31,7 +31,10 @@ import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.TrackerManagementDAOUtil; import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants; -import java.sql.*; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -106,8 +109,8 @@ public class TrackerDAOImpl implements TrackerDAO { TrackerDeviceInfo trackerDeviceInfo = null; try { Connection conn = TrackerManagementDAOFactory.getConnection(); - String sql = "SELECT ID, TRACCAR_DEVICE_ID, DEVICE_ID, TENANT_ID, STATUS FROM DM_EXT_DEVICE_MAPPING WHERE " + - "DEVICE_ID = ? AND TENANT_ID = ? ORDER BY ID DESC LIMIT 1"; + String sql = "SELECT DM_EXT_DEVICE_MAPPING.ID, DM_EXT_DEVICE_MAPPING.TRACCAR_DEVICE_ID, DM_EXT_DEVICE_MAPPING.DEVICE_ID, DM_EXT_DEVICE_MAPPING.TENANT_ID, DM_EXT_DEVICE_MAPPING.STATUS FROM DM_EXT_DEVICE_MAPPING JOIN DM_DEVICE ON DM_EXT_DEVICE_MAPPING.DEVICE_ID=DM_DEVICE.ID WHERE " + + "DM_EXT_DEVICE_MAPPING.DEVICE_ID = ? AND DM_EXT_DEVICE_MAPPING.TENANT_ID = ? ORDER BY DM_EXT_DEVICE_MAPPING.ID DESC LIMIT 1"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, deviceId); stmt.setInt(2, tenantId); 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 73aca76059..0aea251f31 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 65734d1f3c..c9ffbe9064 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 @@ -178,7 +178,6 @@ public class TraccarClientFactory { } } } - return TraccarHandlerConstants.Types.USER_NOT_FOUND; } 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 6a113ca72e..f6a0e3fc73 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,8 +114,8 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { client.deleteGroup(groupId, tenantId); } - @Override - public String returnUser(String userName) { +// @Override + public static String returnUser(String userName) { TraccarClientFactory client = TraccarClientFactory.getInstance(); try { return client.returnUser(userName);