Merge pull request 'Fix: Send EVENT_REVOKE when a group is removed from a geofence' (#454) from waruni/device-mgt-core:geofence-revoke-fix into master

Reviewed-on: community/device-mgt-core#454
issue-10462/secure-pending-operation-6.2
Pahansith Gunathilake 2 months ago
commit 30f685cce8

@ -1528,7 +1528,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
@Override @Override
public boolean updateGeofence(GeofenceData geofenceData, int fenceId) public boolean updateGeofence(GeofenceData geofenceData, int fenceId)
throws GeoLocationBasedServiceException, EventConfigurationException { throws GeoLocationBasedServiceException, EventConfigurationException {
EventConfigurationProviderService eventConfigService;
eventConfigService = DeviceManagementDataHolder.getInstance().getEventConfigurationService();
int tenantId; int tenantId;
List<Integer> groupIdsToDelete = new ArrayList<>();
List<Integer> groupIdsToAdd = new ArrayList<>();
try { try {
tenantId = DeviceManagementDAOUtil.getTenantId(); tenantId = DeviceManagementDAOUtil.getTenantId();
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
@ -1543,8 +1547,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
int updatedRowCount = geofenceDAO.updateGeofence(geofenceData, fenceId); int updatedRowCount = geofenceDAO.updateGeofence(geofenceData, fenceId);
savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId); savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId);
geofenceData.setId(fenceId); geofenceData.setId(fenceId);
List<Integer> groupIdsToDelete = new ArrayList<>();
List<Integer> groupIdsToAdd = new ArrayList<>();
for (Integer savedGroupId : savedGroupIds) { for (Integer savedGroupId : savedGroupIds) {
if (!geofenceData.getGroupIds().contains(savedGroupId)) { if (!geofenceData.getGroupIds().contains(savedGroupId)) {
groupIdsToDelete.add(savedGroupId); groupIdsToDelete.add(savedGroupId);
@ -1558,6 +1560,18 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId); geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId);
geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd); geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd);
EventManagementDAOFactory.commitTransaction(); EventManagementDAOFactory.commitTransaction();
try {
if (!groupIdsToDelete.isEmpty()) {
eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_REVOKE,
DeviceManagementConstants.EventServices.GEOFENCE,
new GeoFenceEventMeta(geofenceData), tenantId, groupIdsToDelete);
}
} catch (EventConfigurationException e) {
String msg = "Failed while creating EVENT_REVOKE operation creation task entry while updating geo fence "
+ geofenceData.getFenceName() + " of the tenant " + tenantId;
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
}
if (updatedRowCount > 0) { if (updatedRowCount > 0) {
GeoCacheManagerImpl.getInstance().updateGeoFenceInCache(geofenceData, fenceId, tenantId); GeoCacheManagerImpl.getInstance().updateGeoFenceInCache(geofenceData, fenceId, tenantId);
} }

Loading…
Cancel
Save