Merge pull request 'formatting issues fix + added new Traccar Device constructor' (#8) from traccar_consistency_issue into master

Reviewed-on: deenath/device-mgt-core#8
pull/21/head
Deenath Geeganage 2 years ago
commit 74a09c2f1a

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

@ -63,10 +63,10 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService {
}
@Override
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);
try{
client.modifyDevice(traccarDevice,tenantId);
public void modifyDevice(Device device, int tenantId) throws ExecutionException, InterruptedException {
TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getDeviceIdentifier(), device.getName());
try {
client.modifyDevice(traccarDevice, tenantId);
} catch (TrackerManagementDAOException e) {
String msg = "Error occurred while mapping with deviceId";
log.error(msg, e);

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

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

Loading…
Cancel
Save