Search in sources :

Example 1 with ModelInvocationContext

use of com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext in project midpoint by Evolveum.

the class ApprovalSchemaExecutionInformationHelper method getApprovalSchemaPreview.

List<ApprovalSchemaExecutionInformationType> getApprovalSchemaPreview(ModelContext<?> modelContext, Task opTask, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    WfConfigurationType wfConfiguration = configurationHelper.getWorkflowConfiguration(modelContext, result);
    ModelInvocationContext<?> ctx = new ModelInvocationContext<>(modelContext, wfConfiguration, prismContext, repositoryService, opTask);
    List<PcpStartInstruction> taskInstructions = primaryChangeProcessor.previewModelInvocation(ctx, result);
    List<ApprovalSchemaExecutionInformationType> rv = new ArrayList<>();
    for (PcpStartInstruction taskInstruction : taskInstructions) {
        OperationResult childResult = result.createMinorSubresult(ApprovalSchemaExecutionInformationHelper.class + ".getApprovalSchemaPreview");
        try {
            CaseType aCase = taskInstruction.getCase();
            rv.add(getApprovalSchemaExecutionInformation(aCase, true, opTask, childResult));
            childResult.computeStatus();
        } catch (Throwable t) {
            childResult.recordFatalError("Couldn't preview approval schema for " + taskInstruction, t);
        }
    }
    return rv;
}
Also used : ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PcpStartInstruction(com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction) ModelInvocationContext(com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext)

Example 2 with ModelInvocationContext

use of com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext 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

OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ModelInvocationContext (com.evolveum.midpoint.wf.impl.processors.ModelInvocationContext)2 ProgressInformation (com.evolveum.midpoint.model.api.ProgressInformation)1 HookOperationMode (com.evolveum.midpoint.model.api.hooks.HookOperationMode)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 ChangeProcessor (com.evolveum.midpoint.wf.impl.processors.ChangeProcessor)1 PcpStartInstruction (com.evolveum.midpoint.wf.impl.processors.primary.PcpStartInstruction)1 ArrayList (java.util.ArrayList)1