Search in sources :

Example 1 with ComputationResult

use of com.evolveum.midpoint.wf.impl.util.ComputationResult in project midpoint by Evolveum.

the class StageComputeHelper method computeStageApprovers.

// TODO method name
public ComputationResult computeStageApprovers(ApprovalStageDefinitionType stageDef, CaseType theCase, VariablesProvider variablesProvider, @NotNull ComputationMode computationMode, Task opTask, OperationResult opResult) throws SchemaException {
    ComputationResult rv = new ComputationResult();
    VariablesMap variablesMap = null;
    VariablesProvider enhancedVariablesProvider = () -> {
        VariablesMap variables = variablesProvider.get();
        variables.put(ExpressionConstants.VAR_STAGE_DEFINITION, stageDef, ApprovalStageDefinitionType.class);
        variables.put(ExpressionConstants.VAR_POLICY_RULES, ApprovalContextUtil.getRulesForStage(theCase.getApprovalContext(), stageDef.getNumber()), List.class);
        return variables;
    };
    if (stageDef.getAutomaticallyCompleted() != null) {
        try {
            variablesMap = enhancedVariablesProvider.get();
            String outcome = evaluateAutoCompleteExpression(stageDef, variablesMap, opTask, opResult);
            if (outcome != null) {
                rv.predeterminedOutcome = ApprovalUtils.approvalLevelOutcomeFromUri(outcome);
                rv.automatedCompletionReason = AUTO_COMPLETION_CONDITION;
            }
        } catch (Exception e) {
            // todo
            throw new SystemException("Couldn't evaluate auto-approval expression", e);
        }
    }
    rv.approverRefs = new HashSet<>();
    if (rv.predeterminedOutcome == null) {
        rv.approverRefs.addAll(CloneUtil.cloneCollectionMembers(stageDef.getApproverRef()));
        if (!stageDef.getApproverExpression().isEmpty()) {
            try {
                if (variablesMap == null) {
                    variablesMap = enhancedVariablesProvider.get();
                }
                rv.approverRefs.addAll(evaluationHelper.evaluateRefExpressions(stageDef.getApproverExpression(), variablesMap, "resolving approver expression", opTask, opResult));
            } catch (ExpressionEvaluationException | ObjectNotFoundException | SchemaException | RuntimeException | CommunicationException | ConfigurationException | SecurityViolationException e) {
                throw new SystemException("Couldn't evaluate approvers expressions", e);
            }
        }
        LOGGER.trace("Approvers at the stage {} (before potential group expansion) are: {}", stageDef, rv.approverRefs);
        if (stageDef.getGroupExpansion() == GroupExpansionType.ON_WORK_ITEM_CREATION) {
            if (shouldExpandGroup(computationMode, opResult)) {
                // see MID-4105
                rv.approverRefs = expandGroups(rv.approverRefs);
                LOGGER.trace("Approvers at the stage {} (after group expansion) are: {}", stageDef, rv.approverRefs);
            } else {
                LOGGER.trace("Groups will not be expanded; computation mode = {}", computationMode);
            }
        }
        if (rv.approverRefs.isEmpty()) {
            rv.noApproversFound = true;
            rv.predeterminedOutcome = defaultIfNull(stageDef.getOutcomeIfNoApprovers(), REJECT);
            rv.automatedCompletionReason = NO_ASSIGNEES_FOUND;
        }
    }
    return rv;
}
Also used : ComputationResult(com.evolveum.midpoint.wf.impl.util.ComputationResult) VariablesProvider(com.evolveum.midpoint.cases.api.temporary.VariablesProvider) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) List(java.util.List)

Example 2 with ComputationResult

use of com.evolveum.midpoint.wf.impl.util.ComputationResult in project midpoint by Evolveum.

the class ApprovalSchemaExecutionInformationHelper method createStageExecutionPreview.

private ApprovalStageExecutionPreviewType createStageExecutionPreview(CaseType aCase, String requestChannel, ApprovalStageDefinitionType stageDef, Task opTask, OperationResult result) {
    ApprovalStageExecutionPreviewType rv = new ApprovalStageExecutionPreviewType(prismContext);
    try {
        ComputationResult computationResult = computeHelper.computeStageApprovers(stageDef, aCase, () -> caseMiscHelper.getDefaultVariables(aCase, aCase.getApprovalContext(), requestChannel, result), ComputationMode.PREVIEW, opTask, result);
        rv.getExpectedApproverRef().addAll(computationResult.getApproverRefs());
        rv.setExpectedAutomatedOutcome(computationResult.getPredeterminedOutcome());
        rv.setExpectedAutomatedCompletionReason(computationResult.getAutomatedCompletionReason());
    } catch (Throwable t) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't compute stage execution preview", t);
        rv.setErrorMessage(MiscUtil.formatExceptionMessageWithCause(t));
        // at least something here
        rv.getExpectedApproverRef().addAll(CloneUtil.cloneCollectionMembers(stageDef.getApproverRef()));
    }
    return rv;
}
Also used : ComputationResult(com.evolveum.midpoint.wf.impl.util.ComputationResult)

Example 3 with ComputationResult

use of com.evolveum.midpoint.wf.impl.util.ComputationResult in project midpoint by Evolveum.

the class CaseStageOpening method process.

@NotNull
public StageOpeningResult process(OperationResult result) throws SchemaException {
    ComputationResult preStageComputationResult = beans.stageComputeHelper.computeStageApprovers(stageDef, currentCase, () -> beans.caseMiscHelper.getDefaultVariables(currentCase, approvalContext, task.getChannel(), result), ComputationMode.EXECUTION, task, result);
    logPreStageComputationResult(preStageComputationResult);
    if (preStageComputationResult.predeterminedOutcome == null) {
        createWorkItems(preStageComputationResult, result);
    }
    return new ApprovalStageOpeningResultImpl(preStageComputationResult.createStageClosingInformation(), newWorkItems, stageDef.getTimedActions());
}
Also used : ComputationResult(com.evolveum.midpoint.wf.impl.util.ComputationResult) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ComputationResult (com.evolveum.midpoint.wf.impl.util.ComputationResult)3 VariablesProvider (com.evolveum.midpoint.cases.api.temporary.VariablesProvider)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1 List (java.util.List)1 NotNull (org.jetbrains.annotations.NotNull)1