Traccar testing

merge-requests/926/head
shamalka 2 years ago
parent 47dfe0b7b8
commit 739090b42d

@ -99,6 +99,17 @@ public interface DeviceDetailsDAO {
*/
DeviceLocation getDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will return the device location exist or not
* @param deviceId - id of the device.
* @param enrollmentId - enrolment id of the device.
* @return - if device location exist
* @throws DeviceDetailsMgtDAOException
*/
boolean hasLocations(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException;
/**
* This method will delete the device location from the database.
* @param deviceId

@ -378,6 +378,35 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO {
}
}
@Override
public boolean hasLocations(int deviceId, int enrollmentId) throws
DeviceDetailsMgtDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
boolean hasLocation = false;
try {
conn = this.getConnection();
String sql = "SELECT DEVICE_ID FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ? " +
"LIMIT 1";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId);
stmt.setInt(2, enrollmentId);
rs = stmt.executeQuery();
if (rs.next()) {
hasLocation = true;
}
return hasLocation;
} catch (SQLException e) {
throw new DeviceDetailsMgtDAOException("Error occurred while fetching the location of the registered devices.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
}
@Override
public void deleteDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException {

@ -367,6 +367,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
} else {
log.info("Update location on IOTS");
deviceDetailsDAO.updateDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationInfo(device, deviceLocation,
@ -390,8 +391,10 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
//Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
try {
log.info("--- Location Pushing to Traccar starts ---");
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId());
log.info("--- Location Pushing to Traccar end ---");
} catch (ExecutionException e) {
log.error("ExecutionException : " + e);
//throw new RuntimeException(e);
@ -435,17 +438,44 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceLocation mostRecentDeviceLocation = deviceLocations.get(deviceLocations.size() - 1);
mostRecentDeviceLocation.setDeviceId(device.getId());
DeviceManagementDAOFactory.beginTransaction();
DeviceLocation previousLocation = deviceDetailsDAO.getDeviceLocation(device.getId(),
boolean previousLocation = deviceDetailsDAO.hasLocations(device.getId(),
device.getEnrolmentInfo().getId());
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
} else {
if (previousLocation) {
deviceDetailsDAO.updateDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationsInfo(device, deviceLocations,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
for (DeviceLocation deviceLocation: deviceLocations) {
//Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
try {
log.info("--- Location Pushing to Traccar starts ---");
DeviceManagementDataHolder.getInstance().getDeviceAPIClientService()
.updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId());
log.info("--- Location Pushing to Traccar end ---");
} catch (ExecutionException e) {
log.error("ExecutionException : " + e);
//throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
} catch (InterruptedException e) {
log.error("InterruptedException : " + e);
//throw new RuntimeException(e);
//Exception was not thrown due to being conflicted with non-traccar features
}
} else {
if(!HttpReportingUtil.isLocationPublishing()) {
log.info("Location publishing is disabled");
}
if (!HttpReportingUtil.isTrackerEnabled()) {
log.info("Traccar is disabled");
}
}
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
throw new DeviceDetailsMgtException("Transactional error occurred while adding the device location " +

@ -3979,7 +3979,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
deviceLocation.setDistance(Double.parseDouble(distance));
deviceLocation.setSpeed(Float.parseFloat(speed));
deviceLocation.setBearing(Float.parseFloat(bearing));
// deviceInformationManager.addDeviceLocation(device, deviceLocation);
log.info("--- Location Pushing to Traccar starts ---");
deviceInformationManager.addDeviceLocation(device, deviceLocation);
log.info("--- Location Pushing to Traccar end ---");
} catch (DeviceDetailsMgtException e) {
//We are not failing the execution since this is not critical for the functionality. But logging as
// a warning for reference.

@ -130,7 +130,6 @@ public class TraccarClientImpl implements TraccarClient {
request = builder.url(serverUri + publisherUrlWithContext).addHeader(authorization, authorizeKey).build();
response = client.newCall(request).execute();
log.info("Live Location: " + response.body().string());
return response.body().string();
}
}
@ -482,8 +481,6 @@ public class TraccarClientImpl implements TraccarClient {
"&lon=" + deviceInfo.getLon() + "&bearing=" + deviceInfo.getBearing() +
"&speed=" + deviceInfo.getSpeed() + "&ignition=true";
log.info("Live Location: " + url);
executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET,
authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()),
Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[0] + ":" +

Loading…
Cancel
Save