Search in sources :

Example 6 with VariablesMap

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;
}
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 7 with VariablesMap

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;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 8 with VariablesMap

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 9 with VariablesMap

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);
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with VariablesMap

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();
}
Also used : ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Aggregations

VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)166 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)30 Test (org.testng.annotations.Test)28 Task (com.evolveum.midpoint.task.api.Task)23 NotNull (org.jetbrains.annotations.NotNull)23 QName (javax.xml.namespace.QName)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)12 Source (com.evolveum.midpoint.repo.common.expression.Source)12 AbstractModelCommonTest (com.evolveum.midpoint.model.common.AbstractModelCommonTest)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)10 Trace (com.evolveum.midpoint.util.logging.Trace)10 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)10 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)8 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7