use of com.evolveum.midpoint.cases.api.temporary.VariablesProvider 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;
}
Aggregations