Search in sources :

Example 21 with HookOperationMode

use of com.evolveum.midpoint.model.api.hooks.HookOperationMode in project midpoint by Evolveum.

the class WfHook method processModelInvocation.

private HookOperationMode processModelInvocation(@NotNull ModelContext<? extends ObjectType> modelContext, WfConfigurationType wfConfigurationType, @NotNull Task opTask, @NotNull OperationResult result) {
    try {
        modelContext.reportProgress(new ProgressInformation(WORKFLOWS, ENTERING));
        ModelInvocationContext<?> ctx = new ModelInvocationContext<>(modelContext, wfConfigurationType, prismContext, repositoryService, opTask);
        for (ChangeProcessor changeProcessor : wfConfiguration.getChangeProcessors()) {
            LOGGER.trace("Trying change processor: {}", changeProcessor.getClass().getName());
            try {
                HookOperationMode hookOperationMode = changeProcessor.processModelInvocation(ctx, result);
                if (hookOperationMode != null) {
                    return hookOperationMode;
                }
            } catch (Exception e) {
                LoggingUtils.logUnexpectedException(LOGGER, "Exception while running change processor {}: {}", e, changeProcessor.getClass().getName(), e.getMessage());
                result.recordFatalError("Exception while running change processor " + changeProcessor.getClass().getSimpleName() + ": " + e.getMessage(), e);
                return HookOperationMode.ERROR;
            }
        }
    } finally {
        if (result.isInProgress()) {
            // a bit of hack: IN_PROGRESS for workflows actually means "success"
            OperationResult r = result.clone();
            r.recordSuccess();
            modelContext.reportProgress(new ProgressInformation(WORKFLOWS, r));
        } else {
            modelContext.reportProgress(new ProgressInformation(WORKFLOWS, result));
        }
    }
    LOGGER.trace("No change processor caught this request, returning the FOREGROUND flag.");
    return HookOperationMode.FOREGROUND;
}
Also used : ChangeProcessor(com.evolveum.midpoint.wf.impl.processors.ChangeProcessor) ProgressInformation(com.evolveum.midpoint.model.api.ProgressInformation) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ModelInvocationContext(com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException)

Aggregations

HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)21 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)14 Task (com.evolveum.midpoint.task.api.Task)9 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 QName (javax.xml.namespace.QName)4 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)3 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)3 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)3 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)3 ChangeHook (com.evolveum.midpoint.model.api.hooks.ChangeHook)2 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)2 PrismContext (com.evolveum.midpoint.prism.PrismContext)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)2 ObjectTypes (com.evolveum.midpoint.schema.constants.ObjectTypes)2 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)2