Fixed the bugs

feature/traccar-sync
Rushdi Mohamed 3 years ago
parent d1f2bdb296
commit 44ac5c8a8f

@ -16,7 +16,7 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.common.group.mgt; package org.wso2.carbon.device.mgt.common;
/** /**
* This class represents a custom exception specified for group management * This class represents a custom exception specified for group management

@ -28,6 +28,7 @@ public class TrackerDeviceInfo implements Serializable {
private int traccarDeviceId; private int traccarDeviceId;
private int deviceId; private int deviceId;
private int tenantId; private int tenantId;
private int status;
public TrackerDeviceInfo() { public TrackerDeviceInfo() {
} }
@ -69,4 +70,12 @@ public class TrackerDeviceInfo implements Serializable {
public void setTenantId(int tenantId) { public void setTenantId(int tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
} }

@ -28,6 +28,7 @@ public class TrackerGroupInfo implements Serializable {
private int traccarGroupId; private int traccarGroupId;
private int groupId; private int groupId;
private int tenantId; private int tenantId;
private int status;
public TrackerGroupInfo() { public TrackerGroupInfo() {
} }
@ -69,4 +70,12 @@ public class TrackerGroupInfo implements Serializable {
public void setTenantId(int tenantId) { public void setTenantId(int tenantId) {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
} }

@ -27,12 +27,10 @@ import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineExc
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.impl.*; import org.wso2.carbon.device.mgt.core.dao.impl.*;
import org.wso2.carbon.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.device.GenericDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.device.GenericDeviceDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.device.OracleDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.device.OracleDeviceDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.device.PostgreSQLDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.device.PostgreSQLDeviceDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.device.SQLServerDeviceDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.device.SQLServerDeviceDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.impl.DeviceDetailsDAOImpl; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.impl.DeviceDetailsDAOImpl;

@ -23,16 +23,80 @@ import org.wso2.carbon.device.mgt.common.TrackerGroupInfo;
public interface TrackerDAO { public interface TrackerDAO {
Boolean addTraccarDevice(int traccarDeviceId, int deviceId, int tenantId) throws TrackerManagementDAOException; /**
* Add new Device.
* @param traccarDeviceId to be added.
* @param deviceId of the device.
* @param tenantId of the group.
* @return boolean value.
* @throws TrackerManagementDAOException
*/
Boolean addTrackerDevice(int traccarDeviceId, int deviceId, int tenantId) throws TrackerManagementDAOException;
int removeTraccarDevice(int deviceId, int tenantId) throws TrackerManagementDAOException; /**
* get trackerDevice info.
* @param groupId of the device.
* @param tenantId of the group.
* @return Tracker Device Info.
* @throws TrackerManagementDAOException
*/
TrackerDeviceInfo getTrackerDevice(int groupId, int tenantId) throws TrackerManagementDAOException;
TrackerDeviceInfo getTraccarDevice(int groupId, int tenantId) throws TrackerManagementDAOException; /**
* update trackerDevice status and traccarDeviceId.
* @param traccarDeviceId of the Device.
* @param deviceId of the device.
* @param tenantId of the group.
* @param status of the device.
* @return Tracker Device Info.
* @throws TrackerManagementDAOException
*/
Boolean updateTrackerDeviceIdANDStatus(int traccarDeviceId, int deviceId, int tenantId, int status) throws TrackerManagementDAOException;
Boolean addTraccarGroup(int traccarGroupId, int groupId, int tenantId) throws TrackerManagementDAOException; /**
* Remove a Device.
* @param deviceId of the device.
* @param tenantId of the group.
* @return sql execution result.
* @throws TrackerManagementDAOException
*/
int removeTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException;
int removeTraccarGroup(int id) throws TrackerManagementDAOException; /**
* Add new Group.
* @param traccarGroupId to be added.
* @param groupId of the group.
* @param tenantId of the group.
* @return boolean value.
* @throws TrackerManagementDAOException
*/
Boolean addTrackerGroup(int traccarGroupId, int groupId, int tenantId) throws TrackerManagementDAOException;
TrackerGroupInfo getTraccarGroup(int groupId, int tenantId) throws TrackerManagementDAOException; /**
* Update status and traccarGroupId of a Group.
* @param traccarGroupId to be added.
* @param groupId of the group.
* @param tenantId of the group.
* @param status of the group.
* @return boolean value.
* @throws TrackerManagementDAOException
*/
Boolean updateTrackerGroupIdANDStatus(int traccarGroupId, int groupId, int tenantId, int status) throws TrackerManagementDAOException;
/**
* Remove a Group.
* @param id mapping table.
* @throws TrackerManagementDAOException
*/
int removeTrackerGroup(int id) throws TrackerManagementDAOException;
/**
* get trackerGroup info.
* @param groupId of the device.
* @param tenantId of the group.
* @return Tracker Device Info.
* @throws TrackerManagementDAOException
*/
TrackerGroupInfo getTrackerGroup(int groupId, int tenantId) throws TrackerManagementDAOException;
} }

@ -26,7 +26,7 @@ import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementExcepti
import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.dao.impl.TrackerDAOImpl; import org.wso2.carbon.device.mgt.core.dao.impl.tracker.TrackerDAOImpl;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import javax.sql.DataSource; import javax.sql.DataSource;

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.mgt.core.dao.impl; package org.wso2.carbon.device.mgt.core.dao.impl.tracker;
import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo;
import org.wso2.carbon.device.mgt.common.TrackerGroupInfo; import org.wso2.carbon.device.mgt.common.TrackerGroupInfo;
@ -33,7 +33,7 @@ import java.sql.SQLException;
public class TrackerDAOImpl implements TrackerDAO { public class TrackerDAOImpl implements TrackerDAO {
@Override @Override
public Boolean addTraccarDevice(int traccarDeviceId, int deviceId, int tenantId) throws TrackerManagementDAOException { public Boolean addTrackerDevice(int traccarDeviceId, int deviceId, int tenantId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = TrackerManagementDAOFactory.getConnection(); Connection conn = TrackerManagementDAOFactory.getConnection();
@ -53,7 +53,29 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
@Override @Override
public int removeTraccarDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { public Boolean updateTrackerDeviceIdANDStatus(int traccarDeviceId, int deviceId, int tenantId, int status) throws TrackerManagementDAOException {
PreparedStatement stmt = null;
try {
Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "UPDATE DM_EXT_DEVICE_MAPPING SET STATUS=?, TRACCAR_DEVICE_ID=? WHERE DEVICE_ID=? AND TENANT_ID=?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, status);
stmt.setInt(2, traccarDeviceId);
stmt.setInt(3, deviceId);
stmt.setInt(4, tenantId);
stmt.execute();
return true;
} catch (SQLException e) {
String msg = "Error occurred while updating trackerDevice mapping table";
throw new TrackerManagementDAOException(msg, e);
} finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public int removeTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int status = -1; int status = -1;
@ -70,20 +92,20 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return status; return status;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while removing traccar device", e); throw new TrackerManagementDAOException("Error occurred while removing trackerDevice", e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null); TrackerManagementDAOUtil.cleanupResources(stmt, null);
} }
} }
@Override @Override
public TrackerDeviceInfo getTraccarDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
TrackerDeviceInfo trackerDeviceInfo = null; TrackerDeviceInfo trackerDeviceInfo = null;
try { try {
Connection conn = TrackerManagementDAOFactory.getConnection(); Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "SELECT ID, TRACCAR_DEVICE_ID, DEVICE_ID, TENANT_ID FROM DM_EXT_DEVICE_MAPPING WHERE " + String sql = "SELECT ID, TRACCAR_DEVICE_ID, DEVICE_ID, TENANT_ID, STATUS FROM DM_EXT_DEVICE_MAPPING WHERE " +
"DEVICE_ID = ? AND TENANT_ID = ? ORDER BY ID DESC LIMIT 1"; "DEVICE_ID = ? AND TENANT_ID = ? ORDER BY ID DESC LIMIT 1";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
@ -94,23 +116,24 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
return trackerDeviceInfo; return trackerDeviceInfo;
} catch (SQLException e) { } catch (SQLException e) {
throw new TrackerManagementDAOException("Error occurred while retrieving the traccar device information ", e); throw new TrackerManagementDAOException("Error occurred while retrieving the trackerDevice information ", e);
} finally { } finally {
TrackerManagementDAOUtil.cleanupResources(stmt, rs); TrackerManagementDAOUtil.cleanupResources(stmt, rs);
} }
} }
@Override @Override
public Boolean addTraccarGroup(int traccarGroupId, int groupId, int tenantId) throws TrackerManagementDAOException { public Boolean addTrackerGroup(int traccarGroupId, int groupId, int tenantId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
int status = 1 ;
try { try {
Connection conn = TrackerManagementDAOFactory.getConnection(); Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "INSERT INTO DM_EXT_GROUP_MAPPING(TRACCAR_GROUP_ID, GROUP_ID, TENANT_ID) VALUES(?, ?, ?)"; String sql = "INSERT INTO DM_EXT_GROUP_MAPPING(TRACCAR_GROUP_ID, GROUP_ID, TENANT_ID, STATUS) VALUES(?, ?, ?, ?)";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, traccarGroupId); stmt.setInt(1, traccarGroupId);
stmt.setInt(2, groupId); stmt.setInt(2, groupId);
stmt.setInt(3, tenantId); stmt.setInt(3, tenantId);
stmt.setInt(4, status);
stmt.execute(); stmt.execute();
return true; return true;
@ -123,7 +146,29 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
@Override @Override
public int removeTraccarGroup(int id) throws TrackerManagementDAOException { public Boolean updateTrackerGroupIdANDStatus(int traccarGroupId, int groupId, int tenantId, int status) throws TrackerManagementDAOException {
PreparedStatement stmt = null;
try {
Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "UPDATE DM_EXT_GROUP_MAPPING SET STATUS=?, TRACCAR_GROUP_ID=? WHERE GROUP_ID=? AND TENANT_ID=?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, status);
stmt.setInt(2, traccarGroupId);
stmt.setInt(3, groupId);
stmt.setInt(4, tenantId);
stmt.execute();
return true;
} catch (SQLException e) {
String msg = "Error occurred while updating traccar group mapping table";
throw new TrackerManagementDAOException(msg, e);
} finally {
TrackerManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public int removeTrackerGroup(int id) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
int status = -1; int status = -1;
@ -146,14 +191,14 @@ public class TrackerDAOImpl implements TrackerDAO {
} }
@Override @Override
public TrackerGroupInfo getTraccarGroup(int groupId, int tenantId) throws TrackerManagementDAOException { public TrackerGroupInfo getTrackerGroup(int groupId, int tenantId) throws TrackerManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
TrackerGroupInfo trackerGroupInfo = null; TrackerGroupInfo trackerGroupInfo = null;
try { try {
Connection conn = TrackerManagementDAOFactory.getConnection(); Connection conn = TrackerManagementDAOFactory.getConnection();
String sql = "SELECT ID, TRACCAR_GROUP_ID, GROUP_ID, TENANT_ID FROM DM_EXT_GROUP_MAPPING WHERE " + String sql = "SELECT ID, TRACCAR_GROUP_ID, GROUP_ID, TENANT_ID, STATUS FROM DM_EXT_GROUP_MAPPING WHERE " +
"GROUP_ID = ? AND TENANT_ID = ?"; "GROUP_ID = ? AND TENANT_ID = ? ORDER BY ID DESC LIMIT 1";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, groupId); stmt.setInt(1, groupId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -175,6 +220,7 @@ public class TrackerDAOImpl implements TrackerDAO {
trackerGroupInfo.setTraccarGroupId(rs.getInt("TRACCAR_GROUP_ID")); trackerGroupInfo.setTraccarGroupId(rs.getInt("TRACCAR_GROUP_ID"));
trackerGroupInfo.setGroupId(rs.getInt("GROUP_ID")); trackerGroupInfo.setGroupId(rs.getInt("GROUP_ID"));
trackerGroupInfo.setTenantId(rs.getInt("TENANT_ID")); trackerGroupInfo.setTenantId(rs.getInt("TENANT_ID"));
trackerGroupInfo.setStatus(rs.getInt("STATUS"));
return trackerGroupInfo; return trackerGroupInfo;
} }
@ -184,6 +230,7 @@ public class TrackerDAOImpl implements TrackerDAO {
trackerDeviceInfo.setTraccarDeviceId(rs.getInt("TRACCAR_DEVICE_ID")); trackerDeviceInfo.setTraccarDeviceId(rs.getInt("TRACCAR_DEVICE_ID"));
trackerDeviceInfo.setDeviceId(rs.getInt("DEVICE_ID")); trackerDeviceInfo.setDeviceId(rs.getInt("DEVICE_ID"));
trackerDeviceInfo.setTenantId(rs.getInt("TENANT_ID")); trackerDeviceInfo.setTenantId(rs.getInt("TENANT_ID"));
trackerDeviceInfo.setStatus(rs.getInt("STATUS"));
return trackerDeviceInfo; return trackerDeviceInfo;
} }
} }

@ -386,12 +386,12 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
// ); // );
} }
//Traccar update GPS Location //Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) { if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId()); .updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId());
} }
//Traccar update GPS Location //Tracker update GPS Location
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {

@ -80,7 +80,7 @@ import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderServiceImpl;
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.TraccarAPIClientServiceImpl; import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl;
import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer; import org.wso2.carbon.device.mgt.core.util.DeviceManagementSchemaInitializer;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.core.util.DeviceMgtTenantMgtListener; import org.wso2.carbon.device.mgt.core.util.DeviceMgtTenantMgtListener;
@ -307,7 +307,7 @@ public class DeviceManagementServiceComponent {
bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null); bundleContext.registerService(DeviceManagementProviderService.class.getName(), deviceManagementProvider, null);
/* Registering Device API Client Service */ /* Registering Device API Client Service */
DeviceAPIClientService deviceAPIClientService = new TraccarAPIClientServiceImpl(); DeviceAPIClientService deviceAPIClientService = new DeviceAPIClientServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceAPIClientService(deviceAPIClientService); DeviceManagementDataHolder.getInstance().setDeviceAPIClientService(deviceAPIClientService);
bundleContext.registerService(DeviceAPIClientService.class.getName(), deviceAPIClientService, null); bundleContext.registerService(DeviceAPIClientService.class.getName(), deviceAPIClientService, null);

@ -43,7 +43,6 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.TrackerGroupInfo;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException;
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest; import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
@ -55,20 +54,16 @@ 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.GroupManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.GroupNotExistException; 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.common.group.mgt.RoleDoesNotExistException;
import org.wso2.carbon.device.mgt.common.group.mgt.TrackerAlreadyExistException;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; 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.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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.GroupDAO;
import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOException; 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.GroupManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.dao.TrackerDAO;
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException;
import org.wso2.carbon.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor; 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.geo.task.GeoFenceEventOperationManager;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMgtConstants;
import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfigurationException;
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil; import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil;
import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserRealm;

@ -17,9 +17,9 @@
* under the License. * under the License.
*/ */
package org.wso2.carbon.device.mgt.core.traccar.common; package org.wso2.carbon.device.mgt.core.traccar.api.service;
import org.wso2.carbon.device.mgt.common.group.mgt.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.TrackerAlreadyExistException;
import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; 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.TraccarGroups;
import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition;

@ -19,7 +19,6 @@
package org.wso2.carbon.device.mgt.core.traccar.api.service.addons; package org.wso2.carbon.device.mgt.core.traccar.api.service.addons;
import com.google.gson.Gson;
import okhttp3.ConnectionPool; import okhttp3.ConnectionPool;
import okhttp3.MediaType; import okhttp3.MediaType;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -28,16 +27,14 @@ import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo;
import org.wso2.carbon.device.mgt.common.TrackerGroupInfo; import org.wso2.carbon.device.mgt.common.TrackerGroupInfo;
import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.group.mgt.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.TrackerAlreadyExistException;
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.TrackerDAO; import org.wso2.carbon.device.mgt.core.dao.TrackerDAO;
import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.traccar.common.TraccarClient;
import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants; import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants;
import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; 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.TraccarGroups;
@ -55,8 +52,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
public class TrackerClient implements TraccarClient { public class TraccarClient implements org.wso2.carbon.device.mgt.core.traccar.api.service.TraccarClient {
private static final Log log = LogFactory.getLog(TrackerClient.class); private static final Log log = LogFactory.getLog(TraccarClient.class);
private static final int THREAD_POOL_SIZE = 50; private static final int THREAD_POOL_SIZE = 50;
private final OkHttpClient client; private final OkHttpClient client;
private final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); private final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
@ -70,7 +67,7 @@ public class TrackerClient implements TraccarClient {
private final TrackerDAO trackerDAO; private final TrackerDAO trackerDAO;
public TrackerClient() { public TraccarClient() {
client = new OkHttpClient.Builder() client = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS)
@ -82,6 +79,7 @@ public class TrackerClient implements TraccarClient {
private class TrackerExecutor implements Runnable { private class TrackerExecutor implements Runnable {
final int deviceId; final int deviceId;
final int groupId;
final int tenantId; final int tenantId;
final JSONObject payload; final JSONObject payload;
final String context; final String context;
@ -89,9 +87,10 @@ public class TrackerClient implements TraccarClient {
private final String method; private final String method;
private final String type; private final String type;
private TrackerExecutor(int deviceId, int tenantId, String publisherUrl, String context, JSONObject payload, private TrackerExecutor(int id, int tenantId, String publisherUrl, String context, JSONObject payload,
String method, String type) { String method, String type) {
this.deviceId = deviceId; this.deviceId = id;
this.groupId = id;
this.tenantId = tenantId; this.tenantId = tenantId;
this.payload = payload; this.payload = payload;
this.context = context; this.context = context;
@ -122,14 +121,23 @@ public class TrackerClient implements TraccarClient {
response = client.newCall(request).execute(); response = client.newCall(request).execute();
if(method==TraccarHandlerConstants.Methods.POST){ if(method==TraccarHandlerConstants.Methods.POST){
JSONObject obj = new JSONObject(response.body().string()); JSONObject obj = new JSONObject(response.body().string());
response.close();
if (obj != null){ if (obj != null){
int traccarId = obj.getInt("id"); int traccarId = obj.getInt("id");
try { try {
TrackerManagementDAOFactory.beginTransaction(); TrackerManagementDAOFactory.beginTransaction();
if(type==TraccarHandlerConstants.Types.DEVICE){ if(type==TraccarHandlerConstants.Types.DEVICE){
trackerDAO.addTraccarDevice(traccarId, deviceId, tenantId); trackerDAO.addTrackerDevice(traccarId, deviceId, tenantId);
TrackerDeviceInfo res = trackerDAO.getTrackerDevice(deviceId, tenantId);
if(res.getStatus()==0){
trackerDAO.updateTrackerDeviceIdANDStatus(res.getTraccarDeviceId(), deviceId, tenantId, 1);
}
}else if(type==TraccarHandlerConstants.Types.GROUP){ }else if(type==TraccarHandlerConstants.Types.GROUP){
trackerDAO.addTraccarGroup(traccarId, deviceId, tenantId); trackerDAO.addTrackerGroup(traccarId, groupId, tenantId);
TrackerGroupInfo res = trackerDAO.getTrackerGroup(groupId, tenantId);
if(res.getStatus()==0){
trackerDAO.updateTrackerGroupIdANDStatus(res.getTraccarGroupId(), groupId, tenantId, 1);
}
} }
TrackerManagementDAOFactory.commitTransaction(); TrackerManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
@ -154,7 +162,7 @@ public class TrackerClient implements TraccarClient {
log.debug("Successfully the request is proceed and communicated with Traccar"); log.debug("Successfully the request is proceed and communicated with Traccar");
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Error occurred", e); log.error("Couldnt connect to traccar.", e);
} }
} }
} }
@ -169,9 +177,11 @@ public class TrackerClient implements TraccarClient {
TrackerDeviceInfo res = null; TrackerDeviceInfo res = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
res = trackerDAO.getTraccarDevice(deviceInfo.getId(), tenantId); res = trackerDAO.getTrackerDevice(deviceInfo.getId(), tenantId);
if(res!=null){ if(res!=null){
throw new TrackerAlreadyExistException("The device already exit"); String msg = "The device already exit";
log.error(msg);
throw new TrackerAlreadyExistException(msg);
} }
} catch (TrackerManagementDAOException e) { } catch (TrackerManagementDAOException e) {
String msg = "Error occurred while mapping with deviceId ."; String msg = "Error occurred while mapping with deviceId .";
@ -193,7 +203,7 @@ public class TrackerClient implements TraccarClient {
} }
/** /**
* Add Traccar Device operation. * update Traccar Device operation.
* @param deviceInfo with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId * @param deviceInfo with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId
* Model, Contact, Category, fenceIds * Model, Contact, Category, fenceIds
* @throws TraccarConfigurationException Failed while add Traccar Device the operation * @throws TraccarConfigurationException Failed while add Traccar Device the operation
@ -202,7 +212,7 @@ public class TrackerClient implements TraccarClient {
TrackerDeviceInfo res = null; TrackerDeviceInfo res = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
res = trackerDAO.getTraccarDevice(deviceInfo.getId(), tenantId); res = trackerDAO.getTrackerDevice(deviceInfo.getId(), tenantId);
} catch (TrackerManagementDAOException e) { } catch (TrackerManagementDAOException e) {
String msg = "Error occurred while mapping with deviceId ."; String msg = "Error occurred while mapping with deviceId .";
log.error(msg, e); log.error(msg, e);
@ -215,13 +225,12 @@ public class TrackerClient implements TraccarClient {
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
if(res==null){ if ((res==null) || (res.getTraccarDeviceId()==0)){
try { try {
TrackerClient trackerClient = new TrackerClient();
TraccarDevice device = deviceInfo; TraccarDevice device = deviceInfo;
String lastUpdatedTime = String.valueOf((new Date().getTime())); String lastUpdatedTime = String.valueOf((new Date().getTime()));
device.setLastUpdate(lastUpdatedTime); device.setLastUpdate(lastUpdatedTime);
trackerClient.addDevice(deviceInfo, tenantId); addDevice(deviceInfo, tenantId);
} catch (TraccarConfigurationException e) { } catch (TraccarConfigurationException e) {
String msg = "Error occurred while mapping with groupId"; String msg = "Error occurred while mapping with groupId";
log.error(msg, e); log.error(msg, e);
@ -231,6 +240,21 @@ public class TrackerClient implements TraccarClient {
log.error(msg, e); log.error(msg, e);
throw new TrackerAlreadyExistException(msg, e); throw new TrackerAlreadyExistException(msg, e);
} }
}else if (res!=null && (res.getTraccarDeviceId()!=0 && res.getStatus()==0)){
//update the traccarGroupId and status
try {
TrackerManagementDAOFactory.beginTransaction();
trackerDAO.updateTrackerDeviceIdANDStatus(res.getTraccarDeviceId(), deviceInfo.getId(), tenantId, 1);
TrackerManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
} catch (TrackerManagementDAOException e) {
String msg="Could not add the traccar group";
log.error(msg, e);
} finally{
TrackerManagementDAOFactory.closeConnection();
}
}else{ }else{
JSONObject payload = payload(deviceInfo); JSONObject payload = payload(deviceInfo);
String context = defaultPort+"/api/devices"; String context = defaultPort+"/api/devices";
@ -267,7 +291,7 @@ public class TrackerClient implements TraccarClient {
TrackerDeviceInfo res = null; TrackerDeviceInfo res = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
res = trackerDAO.getTraccarDevice(device.getId(), tenantId); res = trackerDAO.getTrackerDevice(device.getId(), tenantId);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred establishing the DB connection ."; String msg = "Error occurred establishing the DB connection .";
log.error(msg, e); log.error(msg, e);
@ -280,13 +304,7 @@ public class TrackerClient implements TraccarClient {
if (res == null){ if (res == null){
try { try {
TrackerClient trackerClient = new TrackerClient(); addDevice(device, tenantId);
trackerClient.addDevice(device, tenantId);
log.info("====================================");
log.info(device);
log.info(trackerClient);
log.info(tenantId);
log.info("====================================");
} catch (TraccarConfigurationException e) { } catch (TraccarConfigurationException e) {
String msg = "Error occurred while mapping with groupId"; String msg = "Error occurred while mapping with groupId";
log.error(msg, e); log.error(msg, e);
@ -314,17 +332,18 @@ public class TrackerClient implements TraccarClient {
* @throws TraccarConfigurationException Failed while dis-enroll a Traccar Device operation * @throws TraccarConfigurationException Failed while dis-enroll a Traccar Device operation
*/ */
public void disEndrollDevice(int deviceId, int tenantId) throws TraccarConfigurationException { public void disEndrollDevice(int deviceId, int tenantId) throws TraccarConfigurationException {
TrackerDeviceInfo res = null;
JSONObject obj = null;
try { try {
TrackerManagementDAOFactory.beginTransaction(); TrackerManagementDAOFactory.beginTransaction();
TrackerDeviceInfo res = trackerDAO.getTraccarDevice(deviceId, tenantId); res = trackerDAO.getTrackerDevice(deviceId, tenantId);
JSONObject obj = new JSONObject(res); if(res!=null){
trackerDAO.removeTraccarDevice(deviceId, tenantId); obj = new JSONObject(res);
if(obj!=null){
String context = defaultPort+"/api/devices/"+obj.getInt("traccarDeviceId"); trackerDAO.removeTrackerDevice(deviceId, tenantId);
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarDeviceId"), tenantId, endpoint, context, null, TrackerManagementDAOFactory.commitTransaction();
TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE); }
executor.execute(trackerExecutor); }
TrackerManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction(); TrackerManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred establishing the DB connection"; String msg = "Error occurred establishing the DB connection";
@ -336,6 +355,11 @@ public class TrackerClient implements TraccarClient {
} finally { } finally {
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
String context = defaultPort+"/api/devices/"+obj.getInt("traccarDeviceId");
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarDeviceId"), tenantId, endpoint, context, null,
TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE);
executor.execute(trackerExecutor);
} }
/** /**
@ -344,12 +368,14 @@ public class TrackerClient implements TraccarClient {
* @throws TraccarConfigurationException Failed while add Traccar Device the operation * @throws TraccarConfigurationException Failed while add Traccar Device the operation
*/ */
public void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws TraccarConfigurationException, TrackerAlreadyExistException { public void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws TraccarConfigurationException, TrackerAlreadyExistException {
TrackerGroupInfo res = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
TrackerGroupInfo res = trackerDAO.getTraccarGroup(groupId, tenantId); res = trackerDAO.getTrackerGroup(groupId, tenantId);
if(res!=null){ if (res!=null){
throw new TrackerAlreadyExistException("The group already exit"); String msg = "The group already exit";
log.error(msg);
throw new TrackerAlreadyExistException(msg);
} }
} catch (TrackerManagementDAOException e) { } catch (TrackerManagementDAOException e) {
String msg = "Error occurred while mapping with deviceId ."; String msg = "Error occurred while mapping with deviceId .";
@ -363,18 +389,20 @@ public class TrackerClient implements TraccarClient {
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
JSONObject payload = new JSONObject(); if (res==null){
payload.put("name", groupInfo.getName()); JSONObject payload = new JSONObject();
payload.put("attributes", new JSONObject()); payload.put("name", groupInfo.getName());
payload.put("attributes", new JSONObject());
String context = defaultPort+"/api/groups"; String context = defaultPort+"/api/groups";
Runnable trackerExecutor = new TrackerExecutor(groupId, tenantId, endpoint, context, payload, Runnable trackerExecutor = new TrackerExecutor(groupId, tenantId, endpoint, context, payload,
TraccarHandlerConstants.Methods.POST, TraccarHandlerConstants.Types.GROUP); TraccarHandlerConstants.Methods.POST, TraccarHandlerConstants.Types.GROUP);
executor.execute(trackerExecutor); executor.execute(trackerExecutor);
}
} }
/** /**
* Add Traccar Device operation. * update Traccar Group operation.
* @param groupInfo with groupName * @param groupInfo with groupName
* @throws TraccarConfigurationException Failed while add Traccar Device the operation * @throws TraccarConfigurationException Failed while add Traccar Device the operation
*/ */
@ -382,21 +410,21 @@ public class TrackerClient implements TraccarClient {
TrackerGroupInfo res = null; TrackerGroupInfo res = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
res = trackerDAO.getTraccarGroup(groupId, tenantId); res = trackerDAO.getTrackerGroup(groupId, tenantId);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred establishing the DB connection ."; String msg = "Error occurred establishing the DB connection .";
log.error(msg, e); log.error(msg, e);
} catch (TrackerManagementDAOException e) { } catch (TrackerManagementDAOException e) {
String msg="Could not update the traccar group"; String msg="Could not find traccar group details";
log.error(msg, e); log.error(msg, e);
} finally{ } finally{
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
if (res == null){ if ((res==null) || (res.getTraccarGroupId()==0)){
//add a new traccar group
try { try {
TrackerClient trackerClient = new TrackerClient(); addGroup(groupInfo, groupId, tenantId);
trackerClient.addGroup(groupInfo, groupId, tenantId);
} catch (TraccarConfigurationException e) { } catch (TraccarConfigurationException e) {
String msg = "Error occurred while mapping with groupId"; String msg = "Error occurred while mapping with groupId";
log.error(msg, e); log.error(msg, e);
@ -406,6 +434,21 @@ public class TrackerClient implements TraccarClient {
log.error(msg, e); log.error(msg, e);
throw new TrackerAlreadyExistException(msg, e); throw new TrackerAlreadyExistException(msg, e);
} }
}else if (res!=null && (res.getTraccarGroupId()!=0 && res.getStatus()==0)){
//update the traccargroupId and status
try {
TrackerManagementDAOFactory.beginTransaction();
trackerDAO.updateTrackerGroupIdANDStatus(res.getTraccarGroupId(), groupId, tenantId, 1);
TrackerManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred establishing the DB connection .";
log.error(msg, e);
} catch (TrackerManagementDAOException e) {
String msg="Could not add the traccar group";
log.error(msg, e);
} finally{
TrackerManagementDAOFactory.closeConnection();
}
}else{ }else{
JSONObject obj = new JSONObject(res); JSONObject obj = new JSONObject(res);
JSONObject payload = new JSONObject(); JSONObject payload = new JSONObject();
@ -426,17 +469,18 @@ public class TrackerClient implements TraccarClient {
* @throws TraccarConfigurationException Failed while add Traccar Device the operation * @throws TraccarConfigurationException Failed while add Traccar Device the operation
*/ */
public void deleteGroup(int groupId, int tenantId) throws TraccarConfigurationException { public void deleteGroup(int groupId, int tenantId) throws TraccarConfigurationException {
TrackerGroupInfo res = null;
JSONObject obj = null;
try { try {
TrackerManagementDAOFactory.beginTransaction(); TrackerManagementDAOFactory.beginTransaction();
TrackerGroupInfo res = trackerDAO.getTraccarGroup(groupId, tenantId); res = trackerDAO.getTrackerGroup(groupId, tenantId);
JSONObject obj = new JSONObject(res); if(res!=null){
trackerDAO.removeTraccarGroup(obj.getInt("id")); obj = new JSONObject(res);
if(obj!=null){
String context = defaultPort+"/api/groups/"+obj.getInt("traccarGroupId"); trackerDAO.removeTrackerGroup(obj.getInt("id"));
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarGroupId"), tenantId, endpoint, context, TrackerManagementDAOFactory.commitTransaction();
null, TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.GROUP); }
executor.execute(trackerExecutor); }
TrackerManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
TrackerManagementDAOFactory.rollbackTransaction(); TrackerManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred establishing the DB connection"; String msg = "Error occurred establishing the DB connection";
@ -448,6 +492,13 @@ public class TrackerClient implements TraccarClient {
} finally { } finally {
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
if(obj!=null){
String context = defaultPort+"/api/groups/"+obj.getInt("traccarGroupId");
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarGroupId"), tenantId, endpoint, context,
null, TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.GROUP);
executor.execute(trackerExecutor);
}
} }
private TraccarGateway getTraccarGateway(){ private TraccarGateway getTraccarGateway(){

@ -24,9 +24,9 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.Device; 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.device.details.DeviceLocation;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
import org.wso2.carbon.device.mgt.common.group.mgt.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.TrackerAlreadyExistException;
import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService;
import org.wso2.carbon.device.mgt.core.traccar.api.service.addons.TrackerClient; import org.wso2.carbon.device.mgt.core.traccar.api.service.addons.TraccarClient;
import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; 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.TraccarGroups;
import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition;
@ -34,12 +34,12 @@ import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarConfiguratio
import java.util.Date; import java.util.Date;
public class TraccarAPIClientServiceImpl implements DeviceAPIClientService { public class DeviceAPIClientServiceImpl implements DeviceAPIClientService {
private static final Log log = LogFactory.getLog(TraccarAPIClientServiceImpl.class); private static final Log log = LogFactory.getLog(DeviceAPIClientServiceImpl.class);
public void addDevice(Device device, int tenantId) { public void addDevice(Device device, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
String lastUpdatedTime = String.valueOf((new Date().getTime())); String lastUpdatedTime = String.valueOf((new Date().getTime()));
TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(), TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(),
"online", "false", lastUpdatedTime, "", "", "", "", "online", "false", lastUpdatedTime, "", "", "", "",
@ -56,7 +56,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void updateDevice(Device device, int tenantId) { public void updateDevice(Device device, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
String lastUpdatedTime = String.valueOf((new Date().getTime())); String lastUpdatedTime = String.valueOf((new Date().getTime()));
TraccarDevice traccarDeviceInfo = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(), TraccarDevice traccarDeviceInfo = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(),
"online", "false", lastUpdatedTime, "", "", "", "", "online", "false", lastUpdatedTime, "", "", "", "",
@ -73,7 +73,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) { public void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
TraccarPosition traccarPosition = new TraccarPosition(device.getDeviceIdentifier(), TraccarPosition traccarPosition = new TraccarPosition(device.getDeviceIdentifier(),
deviceLocation.getUpdatedTime().getTime(), deviceLocation.getUpdatedTime().getTime(),
deviceLocation.getLatitude(), deviceLocation.getLongitude(), deviceLocation.getLatitude(), deviceLocation.getLongitude(),
@ -95,7 +95,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void disEndrollDevice(int deviceId, int tenantId) { public void disEndrollDevice(int deviceId, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
try { try {
client.disEndrollDevice(deviceId, tenantId); client.disEndrollDevice(deviceId, tenantId);
} catch (TraccarConfigurationException e) { } catch (TraccarConfigurationException e) {
@ -105,7 +105,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void addGroup(DeviceGroup group, int groupId, int tenantId) { public void addGroup(DeviceGroup group, int groupId, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
TraccarGroups traccarGroups = new TraccarGroups(group.getName()); TraccarGroups traccarGroups = new TraccarGroups(group.getName());
try { try {
client.addGroup(traccarGroups, groupId, tenantId); client.addGroup(traccarGroups, groupId, tenantId);
@ -119,7 +119,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void updateGroup(DeviceGroup group, int groupId, int tenantId) { public void updateGroup(DeviceGroup group, int groupId, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
TraccarGroups traccarGroups = new TraccarGroups(group.getName()); TraccarGroups traccarGroups = new TraccarGroups(group.getName());
try { try {
client.updateGroup(traccarGroups, groupId, tenantId); client.updateGroup(traccarGroups, groupId, tenantId);
@ -133,7 +133,7 @@ public class TraccarAPIClientServiceImpl implements DeviceAPIClientService {
} }
public void deleteGroup(int groupId, int tenantId) { public void deleteGroup(int groupId, int tenantId) {
TrackerClient client = new TrackerClient(); TraccarClient client = new TraccarClient();
try { try {
client.deleteGroup(groupId, tenantId); client.deleteGroup(groupId, tenantId);
} catch (TraccarConfigurationException e) { } catch (TraccarConfigurationException e) {
Loading…
Cancel
Save