Add EVENT_UPDATE operation code and refactor geo fence update

remotes/1720607823028358574/master
Pramila Niroshan 6 months ago
parent 43e70bcb6c
commit 60eac79c74

@ -89,6 +89,7 @@ public final class DeviceManagementConstants {
public static final String POLICY_OPERATION_CODE = PolicyOperation.POLICY_OPERATION_CODE; 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 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_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; public static final String EVENT_REVOKE_OPERATION_CODE = OperationMgtConstants.OperationCodes.EVENT_REVOKE;
} }

@ -84,6 +84,16 @@ public class EventOperationExecutor implements Runnable {
} //extend with another cases to handle other types of events } //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. * Build operation to create EVENT_CONFIG operation.
* @param operation Operation object to build * @param operation Operation object to build
@ -128,6 +138,18 @@ public class EventOperationExecutor implements Runnable {
* @param operation operation object to set the payload * @param operation operation object to set the payload
*/ */
private void createGeoFenceRevokeOperation(ProfileOperation operation) { 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; GeoFenceEventMeta geoFenceMeta = (GeoFenceEventMeta) eventMetaData;
EventRevokeOperation eventRevokeOperation = new EventRevokeOperation(); EventRevokeOperation eventRevokeOperation = new EventRevokeOperation();
eventRevokeOperation.setEventSource(eventSource); eventRevokeOperation.setEventSource(eventSource);
@ -188,6 +210,9 @@ public class EventOperationExecutor implements Runnable {
if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) { if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) {
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG); operation.setCode(OperationMgtConstants.OperationCodes.EVENT_CONFIG);
buildEventConfigOperation(operation); 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)){ } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)){
operation.setCode(OperationMgtConstants.OperationCodes.EVENT_REVOKE); operation.setCode(OperationMgtConstants.OperationCodes.EVENT_REVOKE);
buildEventRevokeOperation(operation); buildEventRevokeOperation(operation);

@ -106,6 +106,8 @@ public class GroupAssignmentEventOperationExecutor implements Runnable {
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) { if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)) {
buildEventConfigOperationObject(operation); buildEventConfigOperationObject(operation);
} else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_UPDATE)) {
buildEventUpdateOperation(operation);
} else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)) { } else if (operationCode.equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE)) {
buildEventRevokeOperation(operation); 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 * Build EVENT_CONFIG operation attaching event payload
* @param operation operation object to build * @param operation operation object to build
@ -217,6 +232,18 @@ public class GroupAssignmentEventOperationExecutor implements Runnable {
* @param operation operation object to attach payload * @param operation operation object to attach payload
*/ */
private void setGeoFenceRevokeOperationContent(ProfileOperation operation){ 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<EventRevokeOperation> revokeOperationList = new ArrayList<>(); List<EventRevokeOperation> revokeOperationList = new ArrayList<>();
for (GeofenceData geofenceData : this.geoFencesOfGroup) { for (GeofenceData geofenceData : this.geoFencesOfGroup) {
EventRevokeOperation eventRevokeOperation = new EventRevokeOperation(); EventRevokeOperation eventRevokeOperation = new EventRevokeOperation();

@ -1323,7 +1323,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData),
tenantId, geofenceData.getGroupIds()); tenantId, geofenceData.getGroupIds());
} catch (EventConfigurationException e) { } 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; + geofenceData.getFenceName() + " of the tenant " + tenantId;
log.error(msg, e); log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e); throw new GeoLocationBasedServiceException(msg, e);
@ -1650,11 +1650,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
log.debug("Update geofence event completed."); log.debug("Update geofence event completed.");
} }
try { try {
eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_REVOKE, eventConfigService.createEventOperationTask(OperationMgtConstants.OperationCodes.EVENT_UPDATE,
DeviceManagementConstants.EventServices.GEOFENCE, DeviceManagementConstants.EventServices.GEOFENCE,
new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds()); new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds());
} catch (EventConfigurationException e) { } 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; + geofenceData.getFenceName() + " of the tenant " + tenantId;
log.error(msg, e); log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e); throw new GeoLocationBasedServiceException(msg, e);

@ -198,6 +198,7 @@ public class OperationManagerImpl implements OperationManager {
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (initiatedBy == null && (isScheduledOperation if (initiatedBy == null && (isScheduledOperation
|| operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG) || operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_CONFIG)
|| operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_UPDATE)
|| operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE))) { || operation.getCode().equalsIgnoreCase(OperationMgtConstants.OperationCodes.EVENT_REVOKE))) {
operation.setInitiatedBy(SYSTEM); operation.setInitiatedBy(SYSTEM);
} else if (StringUtils.isEmpty(operation.getInitiatedBy())) { } else if (StringUtils.isEmpty(operation.getInitiatedBy())) {
@ -1445,6 +1446,7 @@ public class OperationManagerImpl implements OperationManager {
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.POLICY_OPERATION_CODE:
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_CONFIG_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_CONFIG_OPERATION_CODE:
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.EVENT_REVOKE_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.POLICY_REVOKE_OPERATION_CODE:
case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE: case DeviceManagementConstants.AuthorizationSkippedOperationCodes.MONITOR_OPERATION_CODE:
status = true; status = true;

@ -26,6 +26,7 @@ public class OperationMgtConstants {
public static final String POLICY_REVOKE = "POLICY_REVOKE"; public static final String POLICY_REVOKE = "POLICY_REVOKE";
public static final String EVENT_CONFIG = "EVENT_CONFIG"; public static final String EVENT_CONFIG = "EVENT_CONFIG";
public static final String EVENT_UPDATE = "EVENT_UPDATE";
public static final String EVENT_REVOKE = "EVENT_REVOKE"; public static final String EVENT_REVOKE = "EVENT_REVOKE";
} }
} }

Loading…
Cancel
Save