Add spi to data holder

pull/81/head
shamalka 2 years ago
parent 3c9234d79c
commit 83df14febd

@ -79,6 +79,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.report.mgt.ReportManagementService;
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.common.spi.OTPManagementService;
import org.wso2.carbon.device.mgt.common.spi.TraccarManagementService;
import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
@ -295,6 +296,19 @@ public class DeviceMgtAPIUtils {
return deviceTypeGeneratorService;
}
public static TraccarManagementService getTraccarManagementService() {
TraccarManagementService traccarManagementService;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
traccarManagementService = (TraccarManagementService) ctx.getOSGiService(
TraccarManagementService.class, null);
if (traccarManagementService == null) {
String msg = "Traccar management service not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
return traccarManagementService;
}
public static boolean isValidDeviceIdentifier(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
Device device = getDeviceManagementService().getDevice(deviceIdentifier, false);
if (device == null || device.getDeviceIdentifier() == null ||

@ -1,9 +1,13 @@
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.Device;
public interface TraccarManagementService {
String updateLocation();
String getToken();
String getToken(String username);
void addDevice(Device device);
}

@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.common.geo.service.GeoLocationProviderService;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.common.spi.DeviceTypeGeneratorService;
import org.wso2.carbon.device.mgt.common.spi.TraccarManagementService;
import org.wso2.carbon.device.mgt.core.app.mgt.config.AppManagementConfig;
import org.wso2.carbon.device.mgt.core.config.license.LicenseConfig;
import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager;
@ -85,6 +86,7 @@ public class DeviceManagementDataHolder {
private ExecutorService eventConfigExecutors;
private OperationTimeoutTaskManagerService operationTimeoutTaskManagerService;
private DeviceAPIClientService deviceAPIClientService;
private TraccarManagementService traccarManagementService;
private final Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap<>());
@ -359,4 +361,12 @@ public class DeviceManagementDataHolder {
public void setDeviceAPIClientService(DeviceAPIClientService deviceAPIClientService) {
this.deviceAPIClientService = deviceAPIClientService;
}
public TraccarManagementService getTraccarManagementService() {
return traccarManagementService;
}
public void setTraccarManagementService(TraccarManagementService traccarManagementService) {
this.traccarManagementService = traccarManagementService;
}
}

@ -430,17 +430,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
//enroll Traccar device
if (HttpReportingUtil.isTrackerEnabled()) {
try {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().addDevice(device, tenantId);
} catch (ExecutionException e) {
log.error("ExecutionException : " + e);
//throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
} catch (InterruptedException e) {
log.error("InterruptedException : " + e);
//throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
}
// try {
// DeviceManagementDataHolder.getInstance().getDeviceAPIClientService().addDevice(device, tenantId);
// } catch (ExecutionException e) {
// log.error("ExecutionException : " + e);
// //throw new RuntimeException(e);
// //Exception was not thrown due to being conflicted with non-traccar features
// } catch (InterruptedException e) {
// log.error("InterruptedException : " + e);
// //throw new RuntimeException(e);
// //Exception was not thrown due to being conflicted with non-traccar features
// }
DeviceManagementDataHolder.getInstance().getTraccarManagementService().addDevice(device);
} else {
log.info("Traccar is disabled");
}

@ -777,3 +777,16 @@ CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING (
TRACCAR_USER_ID INT DEFAULT 0
);
-- END OF DM_EXT_PERMISSION_MAPPING TABLE--
-- DM_TRACCAR_UNSYNCED_DEVICES TABLE --
CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES (
ID INT NOT NULL AUTO_INCREMENT,
DEVICE_NAME VARCHAR(100) NOT NULL,
IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE,
TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL,
TRACCAR_USENAME VARCHAR(100) NULL,
STATUS VARCHAR(100) NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE --

Loading…
Cancel
Save