From ce0d0a1903fdc212faadf41ff9dc9559de2540c3 Mon Sep 17 00:00:00 2001 From: Rushdi Date: Wed, 31 Aug 2022 16:07:34 +0530 Subject: [PATCH 1/2] revert changes --- .../service/impl/DeviceManagementServiceImpl.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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 6cebe78026..8fef89fd10 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 @@ -497,6 +497,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build(); } else { int userId = obj.getInt("id"); + String msg = ""; List traccarValidIdList = new ArrayList<>(); /*Get Device Id List*/ try { @@ -558,24 +559,28 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { getAllUserDevice.getTraccarDeviceId(), TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE); } + } catch (JSONException e) { + msg = "not a JSONObject. "; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (DeviceManagementException e) { - String msg = "Error occurred while fetching all enrolled devices"; + msg = "Error occurred while fetching all enrolled devices. "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (DeviceAccessAuthorizationException e) { - String msg = "Error occurred while checking device access authorization"; + msg = "Error occurred while checking device access authorization. "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (ExecutionException e) { - String msg = "ExecutionException occured "; + msg = "ExecutionException occurred "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (InterruptedException e) { - String msg = "InterruptedException occured "; + msg = "InterruptedException occurred "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } From df60140f9c40a2c115c2a119d9a51ae9b65eec7b Mon Sep 17 00:00:00 2001 From: Rushdi Date: Wed, 31 Aug 2022 20:38:33 +0530 Subject: [PATCH 2/2] Remove unwanted codelines and handle exceptions --- .../api/service/DeviceAPIClientService.java | 29 ++-- .../traccar/api/service/TraccarClient.java | 40 +++-- .../api/service/addons/TraccarClientImpl.java | 164 +++++++++--------- .../impl/DeviceAPIClientServiceImpl.java | 24 +-- .../config/TraccarConfigurationException.java | 38 ---- 5 files changed, 128 insertions(+), 167 deletions(-) delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/config/TraccarConfigurationException.java 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 28511f2868..605d4f7a46 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 @@ -23,8 +23,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; -import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException; - +import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import java.util.concurrent.ExecutionException; public interface DeviceAPIClientService { @@ -34,15 +33,16 @@ public interface DeviceAPIClientService { * * @param device to be added to update location of the device * @param deviceLocation to be added to update location of the device - * @throws TraccarConfigurationException errors thrown while inserting location of a device traccar configuration + * @throws TrackerManagementDAOException errors thrown while inserting location of a traccar device */ - void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) throws ExecutionException, InterruptedException; + void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) throws + ExecutionException, InterruptedException; /** * Create device Traccar configuration records * * @param device to be added - * @throws TraccarConfigurationException errors thrown while creating a device traccar configuration + * @throws TrackerManagementDAOException errors thrown while creating a traccar device */ void addDevice(Device device, int tenantId) throws ExecutionException, InterruptedException; @@ -50,32 +50,35 @@ public interface DeviceAPIClientService { * Delete a device Traccar configuration records * * @param deviceId to be delete a device - * @throws TraccarConfigurationException errors thrown while deleting a device traccar configuration + * @throws TrackerManagementDAOException errors thrown while deleting a traccar device */ - void disEnrollDevice(int deviceId, int tenantId); + void disEnrollDevice(int deviceId, int tenantId) throws ExecutionException, InterruptedException; /** * Delete a device Traccar configuration records * * @param group to be add a group - * @throws TraccarConfigurationException errors thrown while adding a group traccar configuration + * @throws TrackerManagementDAOException errors thrown while adding a traccar group */ - void addGroup(DeviceGroup group, int groupID, int tenantId) throws TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException; + void addGroup(DeviceGroup group, int groupID, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; /** * Delete a device Traccar configuration records * * @param group to be update the group - * @throws TraccarConfigurationException errors thrown while adding a group traccar configuration + * @throws TrackerManagementDAOException errors thrown while adding a traccar group */ - void updateGroup(DeviceGroup group, int groupID, int tenantId) throws ExecutionException, InterruptedException, TraccarConfigurationException, TrackerAlreadyExistException; + void updateGroup(DeviceGroup group, int groupID, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; /** * Delete a device Traccar configuration records * * @param groupId to delete a group * @param tenantId to delete a group - * @throws TraccarConfigurationException errors thrown while adding a group traccar configuration + * @throws TrackerManagementDAOException errors thrown while adding a traccar group */ - void deleteGroup(int groupId, int tenantId) throws ExecutionException, InterruptedException, TraccarConfigurationException; + void deleteGroup(int groupId, int tenantId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClient.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClient.java index c74db398ac..e8beae1053 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClient.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClient.java @@ -27,7 +27,6 @@ import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarGroups; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarUser; -import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException; import java.sql.SQLException; import java.util.List; @@ -35,41 +34,46 @@ import java.util.concurrent.ExecutionException; public interface TraccarClient { - //String fetchDevicesByUniqueId(String uniqueId) throws ExecutionException, InterruptedException; - void addDevice(TraccarDevice deviceInfo, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException, TrackerManagementDAOException; + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; void updateLocation(TraccarDevice device, TraccarPosition deviceInfo, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException, TrackerManagementDAOException; + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; - void disEnrollDevice(int traccarDeviceId, int tenantId) throws TraccarConfigurationException; + void disEnrollDevice(int traccarDeviceId, int tenantId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException; + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; - void updateGroup(TraccarGroups groupInfo, int groupId, int tenantId) - throws TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException; + void updateGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException; - void deleteGroup(int traccarGroupId, int tenantId) throws TraccarConfigurationException, ExecutionException, InterruptedException; + void deleteGroup(int traccarGroupId, int tenantId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; - void setPermission(int userId, int deviceId) throws TrackerManagementDAOException, ExecutionException, InterruptedException; + void setPermission(int userId, int deviceId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; - void removePermission(int userId, int deviceId, int removeType) throws ExecutionException, InterruptedException; + void removePermission(int userId, int deviceId, int removeType) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; - List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws TrackerManagementDAOException; + List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) + throws TrackerManagementDAOException; - boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws TraccarConfigurationException, SQLException, TrackerManagementDAOException; + boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws + TrackerManagementDAOException, SQLException; - TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TraccarConfigurationException, SQLException, TrackerManagementDAOException; + TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws + TrackerManagementDAOException, SQLException; - String fetchAllUsers() throws TraccarConfigurationException, ExecutionException, InterruptedException; + String fetchAllUsers() throws TrackerManagementDAOException, ExecutionException, InterruptedException; - String fetchUserInfo(String userName) throws TraccarConfigurationException, ExecutionException, InterruptedException; + String fetchUserInfo(String userName) throws TrackerManagementDAOException, ExecutionException, InterruptedException; String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException; String updateUser(TraccarUser traccarUser, int userId) throws ExecutionException, InterruptedException; - String returnUser(String userName) throws TraccarConfigurationException, TrackerManagementDAOException; + String returnUser(String userName) 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/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 a4602bc3b0..bbeab321c5 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 @@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.traccar.api.service.addons; -import com.google.gson.Gson; import okhttp3.ConnectionPool; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -47,7 +46,6 @@ import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarGroups; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarUser; -import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException; import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarGateway; import org.wso2.carbon.device.mgt.core.traccar.common.util.TraccarUtil; import org.wso2.carbon.device.mgt.core.traccar.core.config.TraccarConfigurationManager; @@ -99,12 +97,6 @@ public class TraccarClientImpl implements TraccarClient { private String authorizeKey; private String serverUri; - private OkHttpClientThreadPool(String publisherUrlWithContext, JSONObject payload, String method, String authorizeKey) { - this.publisherUrlWithContext = publisherUrlWithContext; - this.payload = payload; - this.method = method; - this.authorizeKey = authorizeKey; - } private OkHttpClientThreadPool(String publisherUrlWithContext, JSONObject payload, String method, String authorizeKey, String serverUri) { this.publisherUrlWithContext = publisherUrlWithContext; @@ -150,7 +142,6 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String res = result.get(); - //executor.shutdown(); return res; } @@ -239,8 +230,6 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - //executor.shutdown(); - return result; } @@ -253,11 +242,11 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - //executor.shutdown(); return result; } - public void setPermission(int userId, int deviceId) throws ExecutionException, InterruptedException, TrackerManagementDAOException { + public void setPermission(int userId, int deviceId) + throws ExecutionException, InterruptedException, TrackerManagementDAOException { JSONObject payload = new JSONObject(); payload.put("userId", userId); payload.put("deviceId", deviceId); @@ -269,31 +258,33 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - //executor.shutdown(); + if(result==""){ + String msg = ""; try { TrackerManagementDAOFactory.beginTransaction(); trackerDAO.addTrackerUserDevicePermission(userId, deviceId); TrackerManagementDAOFactory.commitTransaction(); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } }else{ - log.error("Couldnt add the permission record: "+ result); + log.error("Couldn't add the permission record: "+ result); } } - public void removePermission(int userId, int deviceId, int removeType) throws ExecutionException, InterruptedException { + public void removePermission(int userId, int deviceId, int removeType) + throws TrackerManagementDAOException, ExecutionException, InterruptedException { JSONObject payload = new JSONObject(); payload.put("userId", userId); payload.put("deviceId", deviceId); @@ -305,40 +296,42 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - //executor.shutdown(); if(result!=null){ + String msg = ""; try { TrackerManagementDAOFactory.beginTransaction(); trackerDAO.removeTrackerUserDevicePermission(deviceId, userId, removeType); TrackerManagementDAOFactory.commitTransaction(); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); - //throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); - //throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } } } - public List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws TrackerManagementDAOException { + public List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) + throws TrackerManagementDAOException { + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); return trackerDAO.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally { @@ -347,15 +340,16 @@ public class TraccarClientImpl implements TraccarClient { } public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); return trackerDAO.getTrackerDevice(deviceId, tenantId); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (TrackerManagementDAOException e) { - String msg="Could not add new device location"; + msg="Could not add new device location"; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally{ @@ -363,17 +357,19 @@ public class TraccarClientImpl implements TraccarClient { } } - public boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws TrackerManagementDAOException { + public boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) + throws TrackerManagementDAOException { Boolean result = false; + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); result = trackerDAO.getUserIdofPermissionByDeviceIdNUserId(deviceId, userId); } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally { @@ -386,25 +382,26 @@ public class TraccarClientImpl implements TraccarClient { * Add Traccar Device operation. * @param traccarDevice with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId * Model, Contact, Category, fenceIds - * @throws TraccarConfigurationException Failed while add Traccar Device the operation + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation */ public void addDevice(TraccarDevice traccarDevice, int tenantId) throws - TrackerAlreadyExistException, ExecutionException, InterruptedException, TrackerManagementDAOException { + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TrackerDeviceInfo trackerDeviceInfo = null; + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); trackerDeviceInfo = trackerDAO.getTrackerDevice(traccarDevice.getId(), tenantId); if(trackerDeviceInfo!=null){ - String msg = "The device already exist"; + msg = "The device already exist"; log.error(msg); - //throw new TrackerAlreadyExistException(msg); + throw new TrackerAlreadyExistException(msg); } } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally { @@ -421,7 +418,6 @@ 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")){ @@ -438,12 +434,12 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.commitTransaction(); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally { @@ -455,24 +451,25 @@ public class TraccarClientImpl implements TraccarClient { } } } - //executor.shutdown(); } /** * Add Device GPS Location operation. * @param deviceInfo with DeviceIdentifier, Timestamp, Lat, Lon, Bearing, Speed, ignition */ - public void updateLocation(TraccarDevice device, TraccarPosition deviceInfo, int tenantId) throws TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + public void updateLocation(TraccarDevice device, TraccarPosition deviceInfo, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TrackerDeviceInfo trackerDeviceInfo = null; + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); trackerDeviceInfo = trackerDAO.getTrackerDevice(device.getId(), tenantId); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection ."; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } catch (TrackerManagementDAOException e) { - String msg="Could not add new device location"; + msg = "Could not add new device location"; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); } finally{ @@ -495,28 +492,25 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, null, method, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), "http://localhost:")); - //executor.shutdown(); } } /** * Dis-enroll a Device operation. * @param deviceId identified via deviceIdentifier - * @throws TraccarConfigurationException Failed while dis-enroll a Traccar Device operation + * @throws TrackerManagementDAOException Failed while dis-enroll a Traccar Device operation */ - public void disEnrollDevice(int deviceId, int tenantId) throws TraccarConfigurationException { + public void disEnrollDevice(int deviceId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { TrackerDeviceInfo trackerDeviceInfo = null; List trackerPermissionInfo = null; - //JSONObject trackerDevice = null; + String msg = ""; try { TrackerManagementDAOFactory.beginTransaction(); trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId); - log.info("------deviceId-----" + deviceId); - log.info(trackerDeviceInfo); + log.info("deviceId - " + deviceId); if(trackerDeviceInfo!=null){ - //trackerDevice = new JSONObject(trackerDeviceInfo); int status = trackerDAO.removeTrackerDevice(deviceId, tenantId); log.info("Status" + status); TrackerManagementDAOFactory.commitTransaction(); @@ -525,14 +519,14 @@ public class TraccarClientImpl implements TraccarClient { } } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection"; + msg = "Error occurred establishing the DB connection"; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with deviceId"; + msg = "Error occurred while mapping with deviceId"; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } @@ -546,7 +540,6 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, null, method, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); - //executor.shutdown(); //remove permissions try { @@ -556,10 +549,7 @@ public class TraccarClientImpl implements TraccarClient { TraccarHandlerConstants.Types.REMOVE_TYPE_MULTIPLE); } catch (ExecutionException e) { log.error("ExecutionException : " + e); - //throw new RuntimeException(e); - } catch (InterruptedException e) { - log.error("InterruptedException : " + e); - //throw new RuntimeException(e); + throw new ExecutionException(e); } } } @@ -567,27 +557,28 @@ public class TraccarClientImpl implements TraccarClient { /** * Add Traccar Device operation. * @param groupInfo with groupName - * @throws TraccarConfigurationException Failed while add Traccar Device the operation + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation */ public void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TrackerGroupInfo trackerGroupInfo = null; + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId); if (trackerGroupInfo!=null){ - String msg = "The group already exit"; + msg = "The group already exit"; log.error(msg); throw new TrackerAlreadyExistException(msg); } } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with groupId."; + msg = "Error occurred while mapping with groupId."; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection."; + msg = "Error occurred establishing the DB connection."; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } @@ -617,15 +608,15 @@ public class TraccarClientImpl implements TraccarClient { trackerDAO.updateTrackerGroupIdANDStatus(trackerGroupInfo.getTraccarGroupId(), groupId, tenantId, 1); } } catch (TrackerManagementDAOException e) { - String msg = "Error occurred while mapping with deviceId ."; + msg = "Error occurred while mapping with deviceId. "; log.error(msg, e); TrackerManagementDAOFactory.rollbackTransaction(); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (TransactionManagementException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection. "; log.error(msg, e); TrackerManagementDAOFactory.rollbackTransaction(); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } @@ -635,25 +626,25 @@ public class TraccarClientImpl implements TraccarClient { }else{ log.error("Something went wrong_2: " + result); } - //executor.shutdown(); } /** * update Traccar Group operation. * @param groupInfo with groupName - * @throws TraccarConfigurationException Failed while add Traccar Device the operation + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation */ public void updateGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TrackerGroupInfo res = null; + String msg = ""; try { TrackerManagementDAOFactory.openConnection(); res = trackerDAO.getTrackerGroup(groupId, tenantId); } catch (SQLException e) { - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection. "; log.error(msg, e); } catch (TrackerManagementDAOException e) { - String msg="Could not find traccar group details"; + msg="Could not find traccar group details. "; log.error(msg, e); } finally{ TrackerManagementDAOFactory.closeConnection(); @@ -670,14 +661,14 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.commitTransaction(); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg="Could not update the traccar group"; + msg="Could not update the traccar group. "; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection ."; + msg = "Error occurred establishing the DB connection. "; log.error(msg, e); - throw new TraccarConfigurationException(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally{ TrackerManagementDAOFactory.closeConnection(); } @@ -694,18 +685,18 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, payload, method, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); - //executor.shutdown(); } } /** * Add Traccar Device operation. * @param groupId - * @throws TraccarConfigurationException Failed while add Traccar Device the operation + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation */ - public void deleteGroup(int groupId, int tenantId) throws TraccarConfigurationException, ExecutionException, InterruptedException { + public void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { TrackerGroupInfo res = null; JSONObject obj = null; + String msg = ""; try { TrackerManagementDAOFactory.beginTransaction(); res = trackerDAO.getTrackerGroup(groupId, tenantId); @@ -721,17 +712,18 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, null, method, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); - //executor.shutdown(); } } } catch (TransactionManagementException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred establishing the DB connection"; + msg = "Error occurred establishing the DB connection. "; log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); } catch (TrackerManagementDAOException e) { TrackerManagementDAOFactory.rollbackTransaction(); - String msg = "Error occurred while mapping with groupId"; + msg = "Error occurred while mapping with groupId. "; log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); } finally { TrackerManagementDAOFactory.closeConnection(); } 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 9559ac262c..540dcfb8df 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 @@ -26,7 +26,6 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; -import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; @@ -36,7 +35,6 @@ import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarGroups; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarUser; -import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException; import java.util.Date; import java.util.List; @@ -85,31 +83,32 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { } } - public void disEnrollDevice(int deviceId, int tenantId) { + public void disEnrollDevice(int deviceId, int tenantId) throws ExecutionException, InterruptedException{ TraccarClientImpl client = new TraccarClientImpl(); try { client.disEnrollDevice(deviceId, tenantId); - } catch (TraccarConfigurationException e) { + } catch (TrackerManagementDAOException e) { String msg = "Error occurred while dis-enrolling the device"; log.error(msg, e); } } public void addGroup(DeviceGroup group, int groupId, int tenantId) throws - TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); TraccarGroups traccarGroups = new TraccarGroups(group.getName()); client.addGroup(traccarGroups, groupId, tenantId); } - public void updateGroup(DeviceGroup group, int groupId, int tenantId) throws TraccarConfigurationException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + public void updateGroup(DeviceGroup group, int groupId, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); TraccarGroups traccarGroups = new TraccarGroups(group.getName()); client.updateGroup(traccarGroups, groupId, tenantId); } public void deleteGroup(int groupId, int tenantId) throws - TraccarConfigurationException, ExecutionException, InterruptedException { + TrackerManagementDAOException, ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); client.deleteGroup(groupId, tenantId); } @@ -131,14 +130,13 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { return client.getUserIdofPermissionByDeviceIdNUserId(deviceId, userId); } - public static String createUser(TraccarUser traccarUser) throws - TrackerManagementDAOException, ExecutionException, InterruptedException { + public static String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); return client.createUser(traccarUser); } public static String updateUser(TraccarUser traccarUser, int userId) throws - TrackerManagementDAOException, ExecutionException, InterruptedException { + ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); return client.updateUser(traccarUser, userId); } @@ -161,12 +159,14 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { client.setPermission(userId, deviceId); } - public static void removeTrackerUserDevicePermission(int userId, int deviceId, int removeType) throws TrackerManagementDAOException, ExecutionException, InterruptedException { + public static void removeTrackerUserDevicePermission(int userId, int deviceId, int removeType) throws + TrackerManagementDAOException, ExecutionException, InterruptedException { TraccarClientImpl client = new TraccarClientImpl(); client.removePermission(userId, deviceId, removeType); } - public static List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws TrackerManagementDAOException { + public static List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws + TrackerManagementDAOException { TraccarClientImpl client = new TraccarClientImpl(); return client.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/config/TraccarConfigurationException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/config/TraccarConfigurationException.java deleted file mode 100644 index ba60114041..0000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/common/config/TraccarConfigurationException.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2018 - 2022 Entgra (Pvt) Ltd, Inc - All Rights Reserved. - * - * Unauthorised copying/redistribution of this file, via any medium is strictly prohibited. - * - * Licensed under the Entgra Commercial License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://entgra.io/licenses/entgra-commercial/1.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.core.traccar.common.config; - -public class TraccarConfigurationException extends Exception { - public TraccarConfigurationException() { - super(); - } - - public TraccarConfigurationException(String message) { - super(message); - } - - public TraccarConfigurationException(String message, Throwable cause) { - super(message, cause); - } - - public TraccarConfigurationException(Throwable cause) { - super(cause); - } -}