Search in sources :

Example 81 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class ShadowManager method getNormalizedValue.

private <T> List<PrismPropertyValue<T>> getNormalizedValue(PrismProperty<T> attr, RefinedObjectClassDefinition rObjClassDef) throws SchemaException {
    RefinedAttributeDefinition<T> refinedAttributeDefinition = rObjClassDef.findAttributeDefinition(attr.getElementName());
    QName matchingRuleQName = refinedAttributeDefinition.getMatchingRuleQName();
    MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleQName, refinedAttributeDefinition.getTypeName());
    List<PrismPropertyValue<T>> normalized = new ArrayList<>();
    for (PrismPropertyValue<T> origPValue : attr.getValues()) {
        T normalizedValue = matchingRule.normalize(origPValue.getValue());
        PrismPropertyValue<T> normalizedPValue = origPValue.clone();
        normalizedPValue.setValue(normalizedValue);
        normalized.add(normalizedPValue);
    }
    return normalized;
}
Also used : QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 82 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class WfExpressionEvaluationHelper method evaluateExpression.

@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, ExpressionVariables variables, String contextDescription, Class<T> clazz, QName typeName, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    ExpressionFactory expressionFactory = getExpressionFactory();
    PrismContext prismContext = expressionFactory.getPrismContext();
    PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl<>(new QName(SchemaConstants.NS_C, "result"), typeName, prismContext);
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, contextDescription, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task, result);
    context.setAdditionalConvertor(additionalConvertor);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, context, task, result);
    return exprResultTriple.getZeroSet().stream().map(ppv -> (T) ppv.getRealValue()).collect(Collectors.toList());
}
Also used : SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) SpringApplicationContextHolder.getMiscDataUtil(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getMiscDataUtil) MiscDataUtil(com.evolveum.midpoint.wf.impl.util.MiscDataUtil) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DOMUtil(com.evolveum.midpoint.util.DOMUtil) QNameUtil(com.evolveum.midpoint.util.QNameUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) Expression(com.evolveum.midpoint.repo.common.expression.Expression) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) Task(com.evolveum.midpoint.task.api.Task) ApprovalUtils(com.evolveum.midpoint.wf.util.ApprovalUtils) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Component(org.springframework.stereotype.Component) List(java.util.List) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ApprovalLevelOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) NotNull(org.jetbrains.annotations.NotNull)

Example 83 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class GcpExpressionHelper method evaluateBooleanExpression.

private boolean evaluateBooleanExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String opContext, Task taskFromModel, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    PrismContext prismContext = expressionFactory.getPrismContext();
    QName resultName = new QName(SchemaConstants.NS_C, "result");
    PrismPropertyDefinition<Boolean> resultDef = new PrismPropertyDefinitionImpl(resultName, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, resultDef, opContext, taskFromModel, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, opContext, taskFromModel, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, taskFromModel, result);
    Collection<PrismPropertyValue<Boolean>> exprResult = exprResultTriple.getZeroSet();
    if (exprResult.size() == 0) {
        return false;
    } else if (exprResult.size() > 1) {
        throw new IllegalStateException("Expression should return exactly one boolean value; it returned " + exprResult.size() + " ones");
    }
    Boolean boolResult = exprResult.iterator().next().getValue();
    return boolResult != null ? boolResult : false;
}
Also used : PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 84 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class WorkItemProvider method createTaskQuery.

// primitive 'query interpreter'
// returns null if no results should be returned
private TaskQuery createTaskQuery(ObjectQuery query, boolean includeVariables, Collection<SelectorOptions<GetOperationOptions>> options, OperationResult result) throws SchemaException {
    FilterComponents components = factorOutQuery(query, F_ASSIGNEE_REF, F_CANDIDATE_REF, F_EXTERNAL_ID);
    List<ObjectFilter> remainingClauses = components.getRemainderClauses();
    if (!remainingClauses.isEmpty()) {
        throw new SchemaException("Unsupported clause(s) in search filter: " + remainingClauses);
    }
    final ItemPath WORK_ITEM_ID_PATH = new ItemPath(F_EXTERNAL_ID);
    final ItemPath ASSIGNEE_PATH = new ItemPath(F_ASSIGNEE_REF);
    final ItemPath CANDIDATE_PATH = new ItemPath(F_CANDIDATE_REF);
    final ItemPath CREATED_PATH = new ItemPath(WorkItemType.F_CREATE_TIMESTAMP);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> workItemIdFilter = components.getKnownComponent(WORK_ITEM_ID_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> assigneeFilter = components.getKnownComponent(ASSIGNEE_PATH);
    final Map.Entry<ItemPath, Collection<? extends PrismValue>> candidateRolesFilter = components.getKnownComponent(CANDIDATE_PATH);
    TaskQuery taskQuery = activitiEngine.getTaskService().createTaskQuery();
    if (workItemIdFilter != null) {
        Collection<? extends PrismValue> filterValues = workItemIdFilter.getValue();
        if (filterValues.size() > 1) {
            throw new IllegalArgumentException("In a query there must be exactly one value for workItemId: " + filterValues);
        }
        taskQuery = taskQuery.taskId(((PrismPropertyValue<String>) filterValues.iterator().next()).getValue());
    }
    if (assigneeFilter != null) {
        taskQuery = addAssigneesToQuery(taskQuery, assigneeFilter);
    }
    if (candidateRolesFilter != null) {
        // TODO what about candidate users? (currently these are not supported)
        List<String> candidateGroups = MiscDataUtil.prismRefsToStrings((Collection<PrismReferenceValue>) candidateRolesFilter.getValue());
        if (!candidateGroups.isEmpty()) {
            taskQuery = taskQuery.taskCandidateGroupIn(candidateGroups);
        } else {
            // no groups -> no result
            return null;
        }
    }
    if (query != null && query.getPaging() != null) {
        ObjectPaging paging = query.getPaging();
        if (paging.getOrderingInstructions().size() > 1) {
            throw new UnsupportedOperationException("Ordering by more than one property is not supported: " + paging.getOrderingInstructions());
        } else if (paging.getOrderingInstructions().size() == 1) {
            ItemPath orderBy = paging.getOrderBy();
            if (CREATED_PATH.equivalent(orderBy)) {
                taskQuery = taskQuery.orderByTaskCreateTime();
            } else {
                throw new UnsupportedOperationException("Ordering by " + orderBy + " is not currently supported");
            }
            switch(paging.getDirection()) {
                case DESCENDING:
                    taskQuery = taskQuery.desc();
                    break;
                case ASCENDING:
                default:
                    taskQuery = taskQuery.asc();
                    break;
            }
        }
    }
    if (includeVariables) {
        return taskQuery.includeTaskLocalVariables().includeProcessVariables();
    } else {
        return taskQuery;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) FilterComponents(com.evolveum.midpoint.schema.util.ObjectQueryUtil.FilterComponents) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectPaging(com.evolveum.midpoint.prism.query.ObjectPaging) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) TaskQuery(org.activiti.engine.task.TaskQuery) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 85 with PrismPropertyValue

use of com.evolveum.midpoint.prism.PrismPropertyValue in project midpoint by Evolveum.

the class EntitlementConverter method createQuery.

// precondition: valueAttr has exactly one value
private <TV, TA> ObjectQuery createQuery(RefinedAssociationDefinition assocDefType, RefinedAttributeDefinition<TA> assocAttrDef, ResourceAttribute<TV> valueAttr) throws SchemaException {
    MatchingRule<TA> matchingRule = matchingRuleRegistry.getMatchingRule(assocDefType.getResourceObjectAssociationType().getMatchingRule(), assocAttrDef.getTypeName());
    PrismPropertyValue<TA> converted = PrismUtil.convertPropertyValue(valueAttr.getValue(0), valueAttr.getDefinition(), assocAttrDef);
    TA normalizedRealValue = matchingRule.normalize(converted.getValue());
    PrismPropertyValue<TA> normalized = new PrismPropertyValue<TA>(normalizedRealValue);
    LOGGER.trace("Converted entitlement filter value: {} ({}) def={}", normalized, normalized.getValue().getClass(), assocAttrDef);
    ObjectQuery query = QueryBuilder.queryFor(ShadowType.class, prismContext).item(new ItemPath(ShadowType.F_ATTRIBUTES, assocAttrDef.getName()), assocAttrDef).eq(normalized).build();
    query.setAllowPartialResults(true);
    return query;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)176 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)93 Test (org.testng.annotations.Test)83 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)81 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)81 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)60 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)43 QName (javax.xml.namespace.QName)35 PrismObject (com.evolveum.midpoint.prism.PrismObject)29 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)19 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ArrayList (java.util.ArrayList)16 Task (com.evolveum.midpoint.task.api.Task)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)11 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)9 PrismProperty (com.evolveum.midpoint.prism.PrismProperty)8 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 File (java.io.File)8