From 7be828a55607fd1874b519c301c1b8ac3ffe4860 Mon Sep 17 00:00:00 2001 From: waruni Date: Wed, 17 Jul 2024 11:52:35 +0530 Subject: [PATCH] Add EVENT REVOKE operation for groupIds to delete --- .../GeoLocationProviderServiceImpl.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index 9b380f14ee..f11914d5ea 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -1528,7 +1528,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic @Override public boolean updateGeofence(GeofenceData geofenceData, int fenceId) throws GeoLocationBasedServiceException, EventConfigurationException { + EventConfigurationProviderService eventConfigService; + eventConfigService = DeviceManagementDataHolder.getInstance().getEventConfigurationService(); int tenantId; + List groupIdsToDelete = new ArrayList<>(); + List groupIdsToAdd = new ArrayList<>(); try { tenantId = DeviceManagementDAOUtil.getTenantId(); } catch (DeviceManagementDAOException e) { @@ -1543,8 +1547,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic int updatedRowCount = geofenceDAO.updateGeofence(geofenceData, fenceId); savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId); geofenceData.setId(fenceId); - List groupIdsToDelete = new ArrayList<>(); - List groupIdsToAdd = new ArrayList<>(); for (Integer savedGroupId : savedGroupIds) { if (!geofenceData.getGroupIds().contains(savedGroupId)) { groupIdsToDelete.add(savedGroupId); @@ -1558,6 +1560,18 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId); geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd); 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) { GeoCacheManagerImpl.getInstance().updateGeoFenceInCache(geofenceData, fenceId, tenantId); }