|
|
@ -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,
|
|
|
|
|
|
|
|
TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE);
|
|
|
|
|
|
|
|
executor.execute(trackerExecutor);
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
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,6 +389,7 @@ public class TrackerClient implements TraccarClient {
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res==null){
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
JSONObject payload = new JSONObject();
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
@ -372,9 +399,10 @@ public class TrackerClient implements TraccarClient {
|
|
|
|
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,
|
|
|
|
|
|
|
|
null, TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.GROUP);
|
|
|
|
|
|
|
|
executor.execute(trackerExecutor);
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
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(){
|