use of com.evolveum.midpoint.schema.expression.VariablesMap 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;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class CorrelatorUtil method getVariablesMap.
public static VariablesMap getVariablesMap(ObjectType focus, ShadowType resourceObject, CorrelationContext correlationContext) {
VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(focus, resourceObject, correlationContext.getResource(), correlationContext.getSystemConfiguration());
variables.put(ExpressionConstants.VAR_CORRELATION_CONTEXT, correlationContext, CorrelationContext.class);
variables.put(ExpressionConstants.VAR_CORRELATOR_STATE, correlationContext.getCorrelatorState(), AbstractCorrelatorStateType.class);
return variables;
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class DashboardServiceImpl method generateNumberMessage.
private String generateNumberMessage(DashboardWidgetType widget, VariablesMap variables, DashboardWidget data) {
Map<DashboardWidgetDataFieldTypeType, String> numberMessagesParts = new HashMap<>();
widget.getPresentation().getDataField().forEach(dataField -> {
switch(dataField.getFieldType()) {
case VALUE:
Task task = taskManager.createTaskInstance("Search domain collection");
try {
String valueMessage = getStringExpressionMessage(variables, dataField.getExpression(), "Get value message", task, task.getResult());
if (valueMessage != null) {
numberMessagesParts.put(DashboardWidgetDataFieldTypeType.VALUE, valueMessage);
}
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
break;
case UNIT:
task = taskManager.createTaskInstance("Get unit");
String unit = getStringExpressionMessage(new VariablesMap(), dataField.getExpression(), "Unit", task, task.getResult());
numberMessagesParts.put(DashboardWidgetDataFieldTypeType.UNIT, unit);
break;
}
});
if (!numberMessagesParts.containsKey(DashboardWidgetDataFieldTypeType.VALUE)) {
LOGGER.error("Value message is not generate from widget " + widget.getIdentifier());
return null;
}
StringBuilder sb = new StringBuilder();
sb.append(numberMessagesParts.get(DashboardWidgetDataFieldTypeType.VALUE));
if (numberMessagesParts.containsKey(DashboardWidgetDataFieldTypeType.UNIT)) {
sb.append(" ").append(numberMessagesParts.get(DashboardWidgetDataFieldTypeType.UNIT));
}
try {
evaluateVariation(widget, variables, data);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
data.setNumberMessage(sb.toString());
return sb.toString();
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class DashboardServiceImpl method countAuditEvents.
public Integer countAuditEvents(CollectionRefSpecificationType collectionRef, ObjectCollectionType collection, Task task, OperationResult result) throws CommonException {
if (collectionRef == null || ((collectionRef.getCollectionRef() == null || collectionRef.getCollectionRef().getOid() == null) && collectionRef.getFilter() == null)) {
return null;
}
if (!DashboardUtils.isAuditCollection(collectionRef, modelService, task, result)) {
LOGGER.error("Unsupported type for audit object collection");
return null;
}
SearchFilterType filter;
if (collection != null) {
filter = collection.getFilter();
} else {
filter = collectionRef.getFilter();
}
ObjectFilter objectFilter = combineAuditFilter(collectionRef, filter, task, result);
ObjectQuery query;
if (objectFilter == null) {
query = prismContext.queryFor(AuditEventRecordType.class).build();
} else {
query = prismContext.queryFactory().createQuery();
ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(objectFilter, new VariablesMap(), MiscSchemaUtil.getExpressionProfile(), expressionFactory, prismContext, "collection filter", task, result);
query.setFilter(evaluatedFilter);
}
@NotNull Collection<SelectorOptions<GetOperationOptions>> option = combineAuditOption(collectionRef, collection, task, result);
return modelAuditService.countObjects(query, option, task, result);
}
use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.
the class ObjectMerger method evaluateValueExpression.
private <O extends ObjectType> Collection<PrismValue> evaluateValueExpression(PrismObject<O> objectLeft, PrismObject<O> objectRight, String side, PrismValue origValue, Expression<PrismValue, ItemDefinition> valueExpression, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
VariablesMap variables = new VariablesMap();
variables.put(ExpressionConstants.VAR_SIDE, side, String.class);
variables.put(ExpressionConstants.VAR_OBJECT_LEFT, objectLeft, String.class);
variables.put(ExpressionConstants.VAR_OBJECT_RIGHT, objectRight, String.class);
variables.put(ExpressionConstants.VAR_INPUT, origValue, origValue.getParent().getDefinition());
variables.put(ExpressionConstants.VAR_VALUE, origValue, origValue.getParent().getDefinition());
ExpressionEvaluationContext exprContext = new ExpressionEvaluationContext(null, variables, "for value " + origValue, task);
PrismValueDeltaSetTriple<PrismValue> triple = valueExpression.evaluate(exprContext, result);
if (triple == null) {
return null;
}
return triple.getNonNegativeValues();
}
Aggregations