Merge branch 'master' into master

pull/21/head
Pahansith Gunathilake 2 years ago
commit 72fa4554ae

@ -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

@ -674,7 +674,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")) {

@ -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;
}

Loading…
Cancel
Save