Merge pull request 'Change location publishing logic' (#218) from shamalka1/device-mgt-core:location-fix into master

Reviewed-on: community/device-mgt-core#218
master
commit 913f6175af

@ -363,13 +363,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
DeviceLocation previousLocation = deviceDetailsDAO.getDeviceLocation(device.getId(), DeviceLocation previousLocation = deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId()); device.getEnrolmentInfo().getId());
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.updateDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationInfo(device, deviceLocation,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
if (DeviceManagerUtil.isPublishLocationResponseEnabled()) { if (DeviceManagerUtil.isPublishLocationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getEnrolmentInfo().getOwner(), device.getType()}; Object[] metaData = {device.getDeviceIdentifier(), device.getEnrolmentInfo().getOwner(), device.getType()};
Object[] payload = new Object[]{ Object[] payload = new Object[]{
@ -382,11 +375,17 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceLocation.getDistance() deviceLocation.getDistance()
}; };
} }
//Tracker update GPS Location //Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) { if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation); DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation);
} else { } else {
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.updateDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationInfo(device, deviceLocation,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
if(!HttpReportingUtil.isLocationPublishing()) { if(!HttpReportingUtil.isLocationPublishing()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Location publishing is disabled"); log.debug("Location publishing is disabled");
@ -453,19 +452,20 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
boolean previousLocation = deviceDetailsDAO.hasLocations(device.getId(), boolean previousLocation = deviceDetailsDAO.hasLocations(device.getId(),
device.getEnrolmentInfo().getId()); device.getEnrolmentInfo().getId());
if(!HttpReportingUtil.isTrackerEnabled()) {
if (previousLocation) { if (previousLocation) {
deviceDetailsDAO.updateDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId()); deviceDetailsDAO.updateDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
} else { } else {
deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId()); deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
} }
deviceDetailsDAO.addDeviceLocationsInfo(device, deviceLocations, deviceDetailsDAO.addDeviceLocationsInfo(device, deviceLocations,
CarbonContext.getThreadLocalCarbonContext().getTenantId()); CarbonContext.getThreadLocalCarbonContext().getTenantId());
}
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
for (DeviceLocation deviceLocation: deviceLocations) { for (DeviceLocation deviceLocation: deviceLocations) {
//Tracker update GPS Location //Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation); DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation);
}
} else { } else {
if(!HttpReportingUtil.isLocationPublishing()) { if(!HttpReportingUtil.isLocationPublishing()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -478,7 +478,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
} }
} }
} }
}
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {

Loading…
Cancel
Save