formatting issues fix + added new Traccar Device constructor #8

Merged
deenath merged 1 commits from traccar_consistency_issue into master 2 years ago

@ -476,25 +476,24 @@ public class TraccarClientFactory {
* Model, Contact, Category, fenceIds * Model, Contact, Category, fenceIds
* @throws TrackerManagementDAOException Failed while add Traccar Device the operation * @throws TrackerManagementDAOException Failed while add Traccar Device the operation
*/ */
public void modifyDevice(TraccarDevice traccarDevice,int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { public void modifyDevice(TraccarDevice traccarDevice, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException {
TrackerDeviceInfo trackerDeviceInfo = null; TrackerDeviceInfo trackerDeviceInfo = null;
try { try {
TrackerManagementDAOFactory.openConnection(); TrackerManagementDAOFactory.openConnection();
trackerDeviceInfo =trackerDAO.getTrackerDevice(traccarDevice.getId(),tenantId); trackerDeviceInfo = trackerDAO.getTrackerDevice(traccarDevice.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);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} } 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);
throw new TrackerManagementDAOException(msg, e); throw new TrackerManagementDAOException(msg, e);
} finally { } finally {
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
if(trackerDeviceInfo != null){ if (trackerDeviceInfo != null) {
log.info("Preparing to rename device ("+ traccarDevice.getId() +" to taccar server"); log.info("Preparing to rename device (" + traccarDevice.getId() + " to taccar server");
String url = defaultPort + "/api/devices/" + trackerDeviceInfo.getTraccarDeviceId(); String url = defaultPort + "/api/devices/" + trackerDeviceInfo.getTraccarDeviceId();
JSONObject payload = TraccarUtil.TraccarDevicePayload(traccarDevice, trackerDeviceInfo.getTraccarDeviceId()); JSONObject payload = TraccarUtil.TraccarDevicePayload(traccarDevice, trackerDeviceInfo.getTraccarDeviceId());
Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT, Future<String> res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT,
@ -503,14 +502,14 @@ public class TraccarClientFactory {
String result = res.get(); String result = res.get();
log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar."); log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar.");
if (res.isDone() && result.charAt(0) == '{') { if (res.isDone() && result.charAt(0) == '{') {
log.info("Succesfully renamed Traccar Device - " + traccarDevice.getId() + "in server" ); log.info("Succesfully renamed Traccar Device - " + traccarDevice.getId() + "in server");
}else{ } else {
log.info("Failed to rename Traccar Device" + traccarDevice.getId() + "in server" ); log.info("Failed to rename Traccar Device" + traccarDevice.getId() + "in server");
} }
}else { } else {
// forward to add device // forward to add device
try { try {
addDevice(traccarDevice,tenantId); addDevice(traccarDevice, tenantId);
} catch (TrackerAlreadyExistException e) { } catch (TrackerAlreadyExistException e) {
String msg = "The device already exist"; String msg = "The device already exist";
log.error(msg, e); log.error(msg, e);

@ -63,10 +63,10 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService {
} }
@Override @Override
public void modifyDevice(Device device,int tenantId) throws ExecutionException,InterruptedException{ public void modifyDevice(Device device, int tenantId) throws ExecutionException, InterruptedException {
TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(), null,null,null,null,null,null,null,null,null); TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getDeviceIdentifier(), device.getName());
try{ try {
client.modifyDevice(traccarDevice,tenantId); client.modifyDevice(traccarDevice, 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);

@ -55,6 +55,12 @@ public class TraccarDevice {
this.category =category; this.category =category;
} }
public TraccarDevice(int id, String deviceIdentifier, String deviceName) {
this.id = id;
this.deviceIdentifier = deviceIdentifier;
this.deviceName = deviceName;
}
public TraccarDevice(){ } public TraccarDevice(){ }
public int getId() { return id; } public int getId() { return id; }

@ -67,13 +67,11 @@ public class TraccarUtil {
return payload; return payload;
} }
public static JSONObject TraccarDevicePayload(TraccarDevice deviceInfo,int id){ public static JSONObject TraccarDevicePayload(TraccarDevice deviceInfo, int id) {
JSONObject payload = new JSONObject(); JSONObject payload = new JSONObject();
payload.put("id",id); payload.put("id", id);
payload.put("name",deviceInfo.getDeviceName()); payload.put("name", deviceInfo.getDeviceName());
payload.put("uniqueId",deviceInfo.getUniqueId()); payload.put("uniqueId", deviceInfo.getUniqueId());
// add other params if needed
// as long as its null it wintt be overitten
return payload; return payload;
} }
} }

Loading…
Cancel
Save