|
|
@ -64,6 +64,8 @@ import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import java.util.stream.IntStream;
|
|
|
|
|
|
|
|
|
|
|
|
public class TraccarClientFactory {
|
|
|
|
public class TraccarClientFactory {
|
|
|
|
|
|
|
|
|
|
|
@ -82,6 +84,9 @@ public class TraccarClientFactory {
|
|
|
|
final String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
final String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
private final TrackerDAO trackerDAO;
|
|
|
|
private final TrackerDAO trackerDAO;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This is the private constructor method as this class is a singleton
|
|
|
|
|
|
|
|
*/
|
|
|
|
private TraccarClientFactory() {
|
|
|
|
private TraccarClientFactory() {
|
|
|
|
client = new OkHttpClient.Builder()
|
|
|
|
client = new OkHttpClient.Builder()
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)
|
|
|
|
.connectTimeout(30, TimeUnit.SECONDS)
|
|
|
@ -92,6 +97,11 @@ public class TraccarClientFactory {
|
|
|
|
this.trackerDAO = TrackerManagementDAOFactory.getTrackerDAO();
|
|
|
|
this.trackerDAO = TrackerManagementDAOFactory.getTrackerDAO();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This method is used to initiate a singleton instance of this class.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return TraccarClientFactory instance
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static TraccarClientFactory getInstance() {
|
|
|
|
public static TraccarClientFactory getInstance() {
|
|
|
|
if(INSTANCE == null) {
|
|
|
|
if(INSTANCE == null) {
|
|
|
|
INSTANCE = new TraccarClientFactory();
|
|
|
|
INSTANCE = new TraccarClientFactory();
|
|
|
@ -144,10 +154,9 @@ public class TraccarClientFactory {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String fetchAllUsers() throws ExecutionException, InterruptedException {
|
|
|
|
public String fetchAllUsers() throws ExecutionException, InterruptedException {
|
|
|
|
String method = TraccarHandlerConstants.Methods.GET;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/users";
|
|
|
|
String url = defaultPort + "/api/users";
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> result = executor.submit(new OkHttpClientThreadPool(url, null, method,
|
|
|
|
Future<String> result = executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
return result.get();
|
|
|
|
return result.get();
|
|
|
@ -191,7 +200,6 @@ public class TraccarClientFactory {
|
|
|
|
traccarUser.setEmail(userName);
|
|
|
|
traccarUser.setEmail(userName);
|
|
|
|
traccarUser.setPassword(DeviceAPIClientServiceImpl.generateRandomString(TraccarHandlerConstants.Types.DEFAULT_RANDOM));
|
|
|
|
traccarUser.setPassword(DeviceAPIClientServiceImpl.generateRandomString(TraccarHandlerConstants.Types.DEFAULT_RANDOM));
|
|
|
|
traccarUser.setDeviceLimit(-1);
|
|
|
|
traccarUser.setDeviceLimit(-1);
|
|
|
|
//traccarUser.setUserLimit(-1);
|
|
|
|
|
|
|
|
traccarUser.setExpirationTime(tomorrow.toString());
|
|
|
|
traccarUser.setExpirationTime(tomorrow.toString());
|
|
|
|
DeviceAPIClientServiceImpl.createUser(traccarUser);
|
|
|
|
DeviceAPIClientServiceImpl.createUser(traccarUser);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -217,7 +225,6 @@ public class TraccarClientFactory {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DeviceAPIClientServiceImpl.updateUser(traccarUser, obj.getInt("id"));
|
|
|
|
DeviceAPIClientServiceImpl.updateUser(traccarUser, obj.getInt("id"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = DeviceAPIClientServiceImpl.fetchUserInfo(userName);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
|
|
} catch (InterruptedException | ExecutionException e) {
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
@ -230,22 +237,20 @@ public class TraccarClientFactory {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException {
|
|
|
|
public String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException {
|
|
|
|
String method = TraccarHandlerConstants.Methods.POST;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/users";
|
|
|
|
String url = defaultPort + "/api/users";
|
|
|
|
JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser);
|
|
|
|
JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser);
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
return res.get();
|
|
|
|
return res.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String updateUser(TraccarUser traccarUser, int userId) throws ExecutionException, InterruptedException {
|
|
|
|
public String updateUser(TraccarUser traccarUser, int userId) throws ExecutionException, InterruptedException {
|
|
|
|
String method = TraccarHandlerConstants.Methods.PUT;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/users/" + userId;
|
|
|
|
String url = defaultPort + "/api/users/" + userId;
|
|
|
|
JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser);
|
|
|
|
JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser);
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
return res.get();
|
|
|
|
return res.get();
|
|
|
@ -257,10 +262,9 @@ public class TraccarClientFactory {
|
|
|
|
payload.put("userId", userId);
|
|
|
|
payload.put("userId", userId);
|
|
|
|
payload.put("deviceId", deviceId);
|
|
|
|
payload.put("deviceId", deviceId);
|
|
|
|
|
|
|
|
|
|
|
|
String method = TraccarHandlerConstants.Methods.POST;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/permissions";
|
|
|
|
String url = defaultPort + "/api/permissions";
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
String result = res.get();
|
|
|
|
String result = res.get();
|
|
|
@ -284,7 +288,9 @@ public class TraccarClientFactory {
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
log.error("Couldn't add the permission record: " + result);
|
|
|
|
String msg = "Couldn't add the permission record: " + result;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -294,10 +300,9 @@ public class TraccarClientFactory {
|
|
|
|
payload.put("userId", userId);
|
|
|
|
payload.put("userId", userId);
|
|
|
|
payload.put("deviceId", deviceId);
|
|
|
|
payload.put("deviceId", deviceId);
|
|
|
|
|
|
|
|
|
|
|
|
String method = TraccarHandlerConstants.Methods.DELETE;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/permissions";
|
|
|
|
String url = defaultPort + "/api/permissions";
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.DELETE,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
|
|
|
|
|
|
|
@ -319,6 +324,10 @@ public class TraccarClientFactory {
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Error occured while removing permission.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -328,7 +337,6 @@ public class TraccarClientFactory {
|
|
|
|
TrackerManagementDAOFactory.openConnection();
|
|
|
|
TrackerManagementDAOFactory.openConnection();
|
|
|
|
return trackerDAO.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList);
|
|
|
|
return trackerDAO.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList);
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while mapping with deviceId .";
|
|
|
|
String msg = "Error occurred while mapping with deviceId .";
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
@ -412,7 +420,7 @@ public class TraccarClientFactory {
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
String result = res.get();
|
|
|
|
String result = res.get();
|
|
|
|
log.info("---------result--------");
|
|
|
|
log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar.");
|
|
|
|
if (res.isDone() && result.charAt(0) == '{') {
|
|
|
|
if (res.isDone() && result.charAt(0) == '{') {
|
|
|
|
JSONObject obj = new JSONObject(result);
|
|
|
|
JSONObject obj = new JSONObject(result);
|
|
|
|
if (obj.has("id")) {
|
|
|
|
if (obj.has("id")) {
|
|
|
@ -508,36 +516,50 @@ public class TraccarClientFactory {
|
|
|
|
List<TrackerPermissionInfo> trackerPermissionInfo = null;
|
|
|
|
List<TrackerPermissionInfo> trackerPermissionInfo = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TrackerManagementDAOFactory.beginTransaction();
|
|
|
|
TrackerManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.openConnection();
|
|
|
|
trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId);
|
|
|
|
trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId);
|
|
|
|
log.info("deviceId - " + deviceId);
|
|
|
|
|
|
|
|
if (trackerDeviceInfo != null) {
|
|
|
|
if (trackerDeviceInfo != null) {
|
|
|
|
trackerDAO.removeTrackerDevice(deviceId, tenantId);
|
|
|
|
trackerDAO.removeTrackerDevice(deviceId, tenantId);
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
trackerPermissionInfo = trackerDAO.getUserIdofPermissionByDeviceId(trackerDeviceInfo.getTraccarDeviceId());
|
|
|
|
trackerPermissionInfo = trackerDAO.getUserIdofPermissionByDeviceId(trackerDeviceInfo.getTraccarDeviceId());
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Tracker device for device id " + deviceId + " not found";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
String msg = "Error occurred establishing the DB connection .";
|
|
|
|
String msg = "Error occurred establishing the DB connection";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
String msg = "Could not add new device location";
|
|
|
|
String msg = "Error occurred while mapping with deviceId";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
log.error(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.info("--------Disenrolling Device with device id " + deviceId + " from traccar client--------");
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred establishing the DB connection";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("Disenrolling Device with device id " + deviceId + " from traccar client");
|
|
|
|
//Delete from traccar
|
|
|
|
//Delete from traccar
|
|
|
|
if (trackerDeviceInfo != null) {
|
|
|
|
if (trackerDeviceInfo != null) {
|
|
|
|
String method = TraccarHandlerConstants.Methods.DELETE;
|
|
|
|
|
|
|
|
|
|
|
|
if (trackerPermissionInfo.size() > 0) {
|
|
|
|
String url = defaultPort + "/api/devices/" + trackerPermissionInfo.get(0).getTraccarDeviceId();
|
|
|
|
String url = defaultPort + "/api/devices/" + trackerPermissionInfo.get(0).getTraccarDeviceId();
|
|
|
|
|
|
|
|
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, null, method,
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.DELETE,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Tracker permission mapping info not found";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
|
|
|
|
}
|
|
|
|
//remove permissions
|
|
|
|
//remove permissions
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
removePermission(
|
|
|
|
removePermission(
|
|
|
@ -545,9 +567,14 @@ public class TraccarClientFactory {
|
|
|
|
trackerPermissionInfo.get(0).getTraccarDeviceId(),
|
|
|
|
trackerPermissionInfo.get(0).getTraccarDeviceId(),
|
|
|
|
TraccarHandlerConstants.Types.REMOVE_TYPE_MULTIPLE);
|
|
|
|
TraccarHandlerConstants.Types.REMOVE_TYPE_MULTIPLE);
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
log.error("ExecutionException : " + e);
|
|
|
|
String msg = "Error occured while removing tacker permissions ";
|
|
|
|
throw new ExecutionException(e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ExecutionException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Tracker device not found";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -584,36 +611,35 @@ public class TraccarClientFactory {
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
|
|
|
|
|
|
|
|
|
String method = TraccarHandlerConstants.Methods.POST;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/groups";
|
|
|
|
String url = defaultPort + "/api/groups";
|
|
|
|
|
|
|
|
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
String result = res.get();
|
|
|
|
String result = res.get();
|
|
|
|
log.info("---------result--------");
|
|
|
|
log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar.");
|
|
|
|
if (res.isDone() && result.charAt(0) == '{') {
|
|
|
|
if (res.isDone() && result.charAt(0) == '{') {
|
|
|
|
JSONObject obj = new JSONObject(result);
|
|
|
|
JSONObject obj = new JSONObject(result);
|
|
|
|
if (obj.has("id")) {
|
|
|
|
if (obj.has("id")) {
|
|
|
|
int traccarGroupId = obj.getInt("id");
|
|
|
|
int traccarGroupId = obj.getInt("id");
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
TrackerManagementDAOFactory.beginTransaction();
|
|
|
|
TrackerManagementDAOFactory.beginTransaction();
|
|
|
|
trackerDAO.addTrackerGroup(traccarGroupId, groupId, tenantId);
|
|
|
|
trackerDAO.addTrackerGroup(traccarGroupId, groupId, tenantId);
|
|
|
|
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
|
|
|
trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId);
|
|
|
|
if (trackerGroupInfo.getStatus() == 0) {
|
|
|
|
if (trackerGroupInfo.getStatus() == 0) {
|
|
|
|
trackerDAO.updateTrackerGroupIdANDStatus(trackerGroupInfo.getTraccarGroupId(), groupId, tenantId, 1);
|
|
|
|
trackerDAO.updateTrackerGroupIdANDStatus(trackerGroupInfo.getTraccarGroupId(), groupId, tenantId, 1);
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while mapping with deviceId. ";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException 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);
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (TrackerManagementDAOException e) {
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
String msg = "Error occurred while mapping with deviceId. ";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
TrackerManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -680,10 +706,9 @@ public class TraccarClientFactory {
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("name", groupInfo.getName());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
|
payload.put("attributes", new JSONObject());
|
|
|
|
|
|
|
|
|
|
|
|
String method = TraccarHandlerConstants.Methods.PUT;
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId");
|
|
|
|
String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId");
|
|
|
|
|
|
|
|
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, payload, method,
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -705,14 +730,20 @@ public class TraccarClientFactory {
|
|
|
|
obj = new JSONObject(res);
|
|
|
|
obj = new JSONObject(res);
|
|
|
|
if (obj != null) {
|
|
|
|
if (obj != null) {
|
|
|
|
trackerDAO.removeTrackerGroup(obj.getInt("id"));
|
|
|
|
trackerDAO.removeTrackerGroup(obj.getInt("id"));
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId");
|
|
|
|
String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId");
|
|
|
|
|
|
|
|
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.DELETE,
|
|
|
|
executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.DELETE,
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
serverUrl(HttpReportingUtil.trackerServer())));
|
|
|
|
|
|
|
|
TrackerManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Tracker group JSON object is null";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
String msg = "Tracker group not found";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new TrackerManagementDAOException(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
|
TrackerManagementDAOFactory.rollbackTransaction();
|
|
|
@ -732,10 +763,7 @@ public class TraccarClientFactory {
|
|
|
|
public String generateRandomString(int len) {
|
|
|
|
public String generateRandomString(int len) {
|
|
|
|
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
|
|
Random rnd = new Random();
|
|
|
|
Random rnd = new Random();
|
|
|
|
StringBuilder sb = new StringBuilder(len);
|
|
|
|
return IntStream.range(0, len).mapToObj(i -> String.valueOf(chars.charAt(rnd.nextInt(chars.length())))).collect(Collectors.joining());
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
|
|
|
|
sb.append(chars.charAt(rnd.nextInt(chars.length())));
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TraccarGateway getTraccarGateway() {
|
|
|
|
private TraccarGateway getTraccarGateway() {
|
|
|
@ -756,10 +784,10 @@ public class TraccarClientFactory {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String serverUrl(String serverUrl) {
|
|
|
|
public String serverUrl(String serverUrl) {
|
|
|
|
String newServerUri = endpoint;
|
|
|
|
|
|
|
|
if (serverUrl != null) {
|
|
|
|
if (serverUrl != null) {
|
|
|
|
newServerUri = serverUrl;
|
|
|
|
return serverUrl;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return endpoint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return newServerUri;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|