From 60eac79c746c0e4ed9de54142dc20f7c74d682fd Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Wed, 15 May 2024 11:01:06 +0530 Subject: [PATCH] Add EVENT_UPDATE operation code and refactor geo fence update --- .../mgt/core/DeviceManagementConstants.java | 1 + .../event/config/EventOperationExecutor.java | 25 +++++++++++++++++ ...GroupAssignmentEventOperationExecutor.java | 27 +++++++++++++++++++ .../GeoLocationProviderServiceImpl.java | 6 ++--- .../operation/mgt/OperationManagerImpl.java | 2 ++ .../operation/mgt/OperationMgtConstants.java | 1 + 6 files changed, 59 insertions(+), 3 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/DeviceManagementConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java index 6fae7901d5a..9f6f24db082 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java @@ -89,6 +89,7 @@ public final class DeviceManagementConstants { public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE; public static final String POLICY_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.POLICY_REVOKE; public static final String EVENT_CONFIG_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_CONFIG; + public static final String EVENT_UPDATE_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_UPDATE; public static final String EVENT_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_REVOKE; } 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/event/config/EventOperationExecutor.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/EventOperationExecutor.java index 54a7efd9dc6..7151eaeef70 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/EventOperationExecutor.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/EventOperationExecutor.java @@ -84,6 +84,16 @@ public class EventOperationExecutor implements Runnable { } //extend with another cases to handle other types of events } + /** + * Build operation to create EVENT_UPDATE operation. + * @param operation Operation object to build + */ + private void buildEventUpdateOperation(ProfileOperation operation) { + if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) { + createGeoFenceUpdateOperation(operation); + } //extend with another cases to handle other types of events + } + /** * Build operation to create EVENT_CONFIG operation. * @param operation Operation object to build @@ -128,6 +138,18 @@ public class EventOperationExecutor implements Runnable { * @param operation operation object to set the payload */ private void createGeoFenceRevokeOperation(ProfileOperation operation) { + changeGeoFenceOperation(operation); + } + + /** + * Create EVENT_UPDATE operation object and attach payload to configure geo fence events + * @param operation operation object to set the payload + */ + private void createGeoFenceUpdateOperation(ProfileOperation operation) { + changeGeoFenceOperation(operation); + } + + private void changeGeoFenceOperation(ProfileOperation operation) { GeoFenceEventMeta geoFenceMeta = (GeoFenceEventMeta) eventMetaData; EventRevokeOperation eventRevokeOperation = new EventRevokeOperation(); eventRevokeOperation.setEventSource(eventSource); @@ -188,6 +210,9 @@ public class EventOperationExecutor implements Runnable { if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) { operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG); buildEventConfigOperation(operation); + } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_UPDATE)){ + operation.setCode(OperationMgtConstants.OperationCodes.EVENT_UPDATE); + buildEventUpdateOperation(operation); } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)){ operation.setCode(OperationMgtConstants.OperationCodes.EVENT_REVOKE); buildEventRevokeOperation(operation); 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/event/config/GroupAssignmentEventOperationExecutor.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/GroupAssignmentEventOperationExecutor.java index 48c77e555b6..37a80ef7e58 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/GroupAssignmentEventOperationExecutor.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/event/config/GroupAssignmentEventOperationExecutor.java @@ -106,6 +106,8 @@ public class GroupAssignmentEventOperationExecutor implements Runnable { operation.setType(Operation.Type.PROFILE); if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) { buildEventConfigOperationObject(operation); + } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_UPDATE)) { + buildEventUpdateOperation(operation); } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)) { buildEventRevokeOperation(operation); } @@ -162,6 +164,19 @@ public class GroupAssignmentEventOperationExecutor implements Runnable { } } + /** + * Build EVENT_UPDATE operation attaching event payload + * @param operation operation object to build + * @throws EventConfigurationException if not events found for the specific group + */ + private void buildEventUpdateOperation(ProfileOperation operation) throws EventConfigurationException { + for (String eventSource : this.eventSources) { + if (eventSource.equalsIgnoreCase(DeviceManagementConstants.EventServices.GEOFENCE)) { + setGeoFenceUpdateOperationContent(operation); + } //add other cases to handle other types of events + } + } + /** * Build EVENT_CONFIG operation attaching event payload * @param operation operation object to build @@ -217,6 +232,18 @@ public class GroupAssignmentEventOperationExecutor implements Runnable { * @param operation operation object to attach payload */ private void setGeoFenceRevokeOperationContent(ProfileOperation operation){ + changeGeoFenceOperation(operation); + } + + /** + * Set operation payload GeoFence for EVENT_UPDATE operation + * @param operation operation object to attach payload + */ + private void setGeoFenceUpdateOperationContent(ProfileOperation operation){ + changeGeoFenceOperation(operation); + } + + private void changeGeoFenceOperation(ProfileOperation operation) { List revokeOperationList = new ArrayList<>(); for (GeofenceData geofenceData : this.geoFencesOfGroup) { EventRevokeOperation eventRevokeOperation = new EventRevokeOperation(); 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 edac4eaa091..9b380f14eec 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 @@ -1323,7 +1323,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds()); } catch (EventConfigurationException e) { - String msg = "Failed while creating EVENT_REVOKE operation creation task entry while updating geo fence " + String msg = "Failed while creating EVENT_CONFIG operation creation task entry while updating geo fence " + geofenceData.getFenceName() + " of the tenant " + tenantId; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); @@ -1650,11 +1650,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.debug("Update geofence event completed."); } try { - eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_REVOKE, + eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_UPDATE, DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds()); } catch (EventConfigurationException e) { - String msg = "Failed while creating EVENT_REVOKE operation creation task entry while updating geo fence " + String msg = "Failed while creating EVENT_UPDATE operation creation task entry while updating geo fence " + geofenceData.getFenceName() + " of the tenant " + tenantId; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); 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/operation/mgt/OperationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java index 8cf4630f0a8..658dc64545a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -198,6 +198,7 @@ public class OperationManagerImpl implements OperationManager { String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (initiatedBy == null && (isScheduledOperation || operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG) + || operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_UPDATE) || operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE))) { operation.setInitiatedBy(SYSTEM); } else if (StringUtils.isEmpty(operation.getInitiatedBy())) { @@ -1445,6 +1446,7 @@ public class OperationManagerImpl implements OperationManager { case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_CONFIG_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_REVOKE_OPERATION_CODE: + case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_UPDATE_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_REVOKE_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE: status = true; 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/operation/mgt/OperationMgtConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationMgtConstants.java index 920da1526f4..f0bfa8a330f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationMgtConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationMgtConstants.java @@ -26,6 +26,7 @@ public class OperationMgtConstants { public static final String POLICY_REVOKE = "POLICY_REVOKE"; public static final String EVENT_CONFIG = "EVENT_CONFIG"; + public static final String EVENT_UPDATE = "EVENT_UPDATE"; public static final String EVENT_REVOKE = "EVENT_REVOKE"; } }