From e5d7512d0a3d3c03f89be23a4d6054fc93897306 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Thu, 24 Nov 2022 18:26:18 +0530 Subject: [PATCH 1/3] fix traccar nullpointer error --- .../mgt/core/traccar/api/service/TraccarClientFactory.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 193bdb211c..e0124c53ef 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 @@ -626,7 +626,9 @@ public class TraccarClientFactory { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar."); + if (null != trackerGroupInfo) { + log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar."); + } if (res.isDone() && result.charAt(0) == '{') { JSONObject obj = new JSONObject(result); if (obj.has("id")) { From 93684174d4157ada385cfbb724c725c1a60550bb Mon Sep 17 00:00:00 2001 From: navodzoysa Date: Thu, 24 Nov 2022 19:57:38 +0530 Subject: [PATCH 2/3] Update traccar configuration --- .../mgt/core/util/HttpReportingUtil.java | 48 ++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java index 139eb00430..f32c187820 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/util/HttpReportingUtil.java @@ -26,6 +26,7 @@ import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.protocol.HTTP; +import org.json.JSONObject; import org.wso2.carbon.device.mgt.common.exceptions.EventPublishingException; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import java.io.IOException; @@ -39,6 +40,7 @@ public class HttpReportingUtil { private static final String TRACKER_SERVER_URI = "trackerServer"; private static final String TRACKER_PASSWORD = "trackerPassword"; private static final String TRACKER_USER = "trackerUsername"; + private static final String TRACKER_CONFIG = "locationPublishing"; public static String getReportingHost() { return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST); @@ -63,47 +65,49 @@ public class HttpReportingUtil { public static boolean isPublishingEnabledForTenant() { Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED); if (configuration != null) { - return Boolean.valueOf(configuration.toString()); + return Boolean.parseBoolean(configuration.toString()); } return false; } public static boolean isLocationPublishing() { - Object configuration = DeviceManagerUtil.getConfiguration(IS_LOCATION_PUBLISHING_ENABLED); - if (configuration != null) { - return Boolean.valueOf(configuration.toString()); - } - return false; + return getTrackerBooleanValues(IS_LOCATION_PUBLISHING_ENABLED); } public static boolean isTrackerEnabled() { - Object configuration = DeviceManagerUtil.getConfiguration(IS_TRACKER_ENABLED); - if (configuration != null) { - return Boolean.valueOf(configuration.toString()); - } - return false; + return getTrackerBooleanValues(IS_TRACKER_ENABLED); } public static String trackerServer() { - Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_SERVER_URI); - if (configuration != null) { - return configuration.toString(); - } - return null; + return getTrackerStringValues(TRACKER_SERVER_URI); } public static String trackerPassword() { - Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_PASSWORD); + return getTrackerStringValues(TRACKER_PASSWORD); + } + + public static String trackerUser() { + return getTrackerStringValues(TRACKER_USER); + } + + public static boolean getTrackerBooleanValues(String trackerConfigKey) { + Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_CONFIG); if (configuration != null) { - return configuration.toString(); + JSONObject locationConfig = new JSONObject(configuration.toString()); + if (locationConfig.has(trackerConfigKey)) { + return Boolean.parseBoolean(locationConfig.get(trackerConfigKey).toString()); + } } - return null; + return false; } - public static String trackerUser() { - Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_USER); + public static String getTrackerStringValues(String trackerConfigKey) { + Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_CONFIG); if (configuration != null) { - return configuration.toString(); + JSONObject locationConfig = new JSONObject(configuration.toString()); + if (locationConfig.has(trackerConfigKey)) { + return locationConfig.get(trackerConfigKey).toString(); + } } return null; } From 7c2b4bd6871a5d5ac2d752447fd92435c0c5cdfd Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 25 Nov 2022 09:31:57 +0530 Subject: [PATCH 3/3] Fix group delete --- .../GroupManagementProviderServiceImpl.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index c036e752af..66a8ba9362 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -54,12 +54,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.GroupAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupManagementException; import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException; import org.wso2.carbon.device.mgt.common.group.mgt.RoleDoesNotExistException; -import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.dao.GroupDAO; -import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException; -import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor; import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; @@ -76,6 +71,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @@ -299,8 +295,16 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid //procees to delete a group from traccar starts if (HttpReportingUtil.isTrackerEnabled()) { - DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() - .deleteGroup(groupId, tenantId); + try { + DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() + .deleteGroup(groupId, tenantId); + } catch (TrackerManagementDAOException e) { + String msg = "Failed while deleting traccar group " + groupId; + log.error(msg, e); + } catch (ExecutionException | InterruptedException e) { + String msg = "Failed while deleting traccar group "+groupId+" due to concurrent execution failure"; + log.error(msg, e); + } } //procees to delete a group from traccar ends