Update traccar configuration

master
navodzoysa 2 years ago
parent 49a1ab9516
commit 93684174d4

@ -26,6 +26,7 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP; 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.common.exceptions.EventPublishingException;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import java.io.IOException; import java.io.IOException;
@ -39,6 +40,7 @@ public class HttpReportingUtil {
private static final String TRACKER_SERVER_URI = "trackerServer"; private static final String TRACKER_SERVER_URI = "trackerServer";
private static final String TRACKER_PASSWORD = "trackerPassword"; private static final String TRACKER_PASSWORD = "trackerPassword";
private static final String TRACKER_USER = "trackerUsername"; private static final String TRACKER_USER = "trackerUsername";
private static final String TRACKER_CONFIG = "locationPublishing";
public static String getReportingHost() { public static String getReportingHost() {
return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST); return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST);
@ -63,47 +65,49 @@ public class HttpReportingUtil {
public static boolean isPublishingEnabledForTenant() { public static boolean isPublishingEnabledForTenant() {
Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED); Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED);
if (configuration != null) { if (configuration != null) {
return Boolean.valueOf(configuration.toString()); return Boolean.parseBoolean(configuration.toString());
} }
return false; return false;
} }
public static boolean isLocationPublishing() { public static boolean isLocationPublishing() {
Object configuration = DeviceManagerUtil.getConfiguration(IS_LOCATION_PUBLISHING_ENABLED); return getTrackerBooleanValues(IS_LOCATION_PUBLISHING_ENABLED);
if (configuration != null) {
return Boolean.valueOf(configuration.toString());
}
return false;
} }
public static boolean isTrackerEnabled() { public static boolean isTrackerEnabled() {
Object configuration = DeviceManagerUtil.getConfiguration(IS_TRACKER_ENABLED); return getTrackerBooleanValues(IS_TRACKER_ENABLED);
if (configuration != null) {
return Boolean.valueOf(configuration.toString());
}
return false;
} }
public static String trackerServer() { public static String trackerServer() {
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_SERVER_URI); return getTrackerStringValues(TRACKER_SERVER_URI);
if (configuration != null) {
return configuration.toString();
}
return null;
} }
public static String trackerPassword() { 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) { 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() { public static String getTrackerStringValues(String trackerConfigKey) {
Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_USER); Object configuration = DeviceManagerUtil.getConfiguration(TRACKER_CONFIG);
if (configuration != null) { if (configuration != null) {
return configuration.toString(); JSONObject locationConfig = new JSONObject(configuration.toString());
if (locationConfig.has(trackerConfigKey)) {
return locationConfig.get(trackerConfigKey).toString();
}
} }
return null; return null;
} }

Loading…
Cancel
Save