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..b7c27db5ae 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 @@ -1606,6 +1606,8 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic List createdEventIds; int tenantId; + List groupIdsToDelete = new ArrayList<>(); + List savedGroupIds; try { tenantId = DeviceManagementDAOUtil.getTenantId(); setEventSource(geofenceData.getEventConfig()); @@ -1616,6 +1618,15 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic throw new GeoLocationBasedServiceException(msg); } createdEventIds = eventConfigService.updateEventsOfDeviceGroup(geofenceData.getEventConfig(), removedEventIdList, groupIds); + EventManagementDAOFactory.openConnection(); + savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId); + geofenceData.setId(fenceId); + for (Integer savedGroupId : savedGroupIds) { + if (!geofenceData.getGroupIds().contains(savedGroupId)) { + groupIdsToDelete.add(savedGroupId); + } + } + EventManagementDAOFactory.commitTransaction(); } catch (EventConfigurationException e) { String msg = "Error occurred while updating event configuration data"; log.error(msg, e); @@ -1624,6 +1635,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic String msg = "Error occurred while retrieving tenant id while update geofence data"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + finally { + EventManagementDAOFactory.closeConnection(); } if (log.isDebugEnabled()) { @@ -1650,6 +1666,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.debug("Update geofence event completed."); } try { + if (!groupIdsToDelete.isEmpty()) { + eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_REVOKE, + DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), + tenantId, groupIdsToDelete); + } eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_UPDATE, DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds());