Search in sources :

Example 1 with ItemDeltaItem

use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method determineDeputyValidity.

private boolean determineDeputyValidity(PrismObject<UserType> potentialDeputy, List<ObjectReferenceType> assignees, @Nullable AbstractWorkItemType workItem, QName privilegeLimitationItemName, Task task, OperationResult result) {
    AssignmentEvaluator.Builder<UserType> builder = new AssignmentEvaluator.Builder<UserType>().referenceResolver(referenceResolver).focusOdo(new ObjectDeltaObject<>(potentialDeputy, null, potentialDeputy, potentialDeputy.getDefinition())).channel(null).modelBeans(modelBeans).objectResolver(objectResolver).systemObjectCache(systemObjectCache).relationRegistry(relationRegistry).prismContext(prismContext).mappingFactory(mappingFactory).mappingEvaluator(mappingEvaluator).contextLoader(contextLoader).activationComputer(activationComputer).now(clock.currentTimeXMLGregorianCalendar()).loginMode(true).lensContext(new LensContextPlaceholder<>(potentialDeputy));
    AssignmentEvaluator<UserType> assignmentEvaluator = builder.build();
    for (AssignmentType assignmentType : potentialDeputy.asObjectable().getAssignment()) {
        if (!DeputyUtils.isDelegationAssignment(assignmentType, relationRegistry)) {
            continue;
        }
        try {
            ItemDeltaItem<PrismContainerValue<AssignmentType>, PrismContainerDefinition<AssignmentType>> assignmentIdi = new ItemDeltaItem<>(LensUtil.createAssignmentSingleValueContainer(assignmentType));
            // TODO some special mode for verification of the validity - we don't need complete calculation here!
            EvaluatedAssignment<UserType> assignment = assignmentEvaluator.evaluate(assignmentIdi, PlusMinusZero.ZERO, false, potentialDeputy.asObjectable(), potentialDeputy.toString(), AssignmentOrigin.createInObject(), task, result);
            if (!assignment.isValid()) {
                continue;
            }
            for (EvaluatedAssignmentTarget target : assignment.getRoles().getNonNegativeValues()) {
                // MID-6403
                if (target.getTarget().getOid() != null && DeputyUtils.isDelegationPath(target.getAssignmentPath(), relationRegistry) && ObjectTypeUtil.containsOid(assignees, target.getTarget().getOid())) {
                    List<OtherPrivilegesLimitationType> limitations = DeputyUtils.extractLimitations(target.getAssignmentPath());
                    if (workItem != null && DeputyUtils.limitationsAllow(limitations, privilegeLimitationItemName, workItem) || workItem == null && SchemaDeputyUtil.limitationsAllow(limitations, privilegeLimitationItemName)) {
                        return true;
                    }
                }
            }
        } catch (CommonException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't verify 'deputy' relation between {} and {} for work item {}; assignment: {}", e, potentialDeputy, assignees, workItem, assignmentType);
        }
    }
    return false;
}
Also used : ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) EvaluatedAssignmentTarget(com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget)

Example 2 with ItemDeltaItem

use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.

the class LensUtil method getIterationTokenVariableValue.

public static Object getIterationTokenVariableValue(LensProjectionContext accCtx) {
    String iterationTokenOld = null;
    PrismObject<ShadowType> shadowCurrent = accCtx.getObjectCurrent();
    if (shadowCurrent != null) {
        iterationTokenOld = shadowCurrent.asObjectable().getIterationToken();
    }
    if (iterationTokenOld == null) {
        return accCtx.getIterationToken();
    }
    PrismPropertyDefinition<String> propDef = PrismContext.get().definitionFactory().createPropertyDefinition(ExpressionConstants.VAR_ITERATION_TOKEN_QNAME, DOMUtil.XSD_STRING);
    PrismProperty<String> propOld = propDef.instantiate();
    propOld.setRealValue(iterationTokenOld);
    PropertyDelta<String> propDelta = propDef.createEmptyDelta(ExpressionConstants.VAR_ITERATION_TOKEN_QNAME);
    propDelta.setRealValuesToReplace(accCtx.getIterationToken());
    PrismProperty<String> propNew = propDef.instantiate();
    propNew.setRealValue(accCtx.getIterationToken());
    ItemDeltaItem<PrismPropertyValue<String>, PrismPropertyDefinition<String>> idi = new ItemDeltaItem<>(propOld, propDelta, propNew, propDef);
    return idi;
}
Also used : ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 3 with ItemDeltaItem

use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.

the class TimeConstraintsEvaluation method parseTimeSource.

private XMLGregorianCalendar parseTimeSource(VariableBindingDefinitionType source, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ItemPath path = m.parser.getSourcePath(source);
    Object sourceObject = ExpressionUtil.resolvePathGetValue(path, m.variables, false, m.getTypedSourceContext(), m.beans.objectResolver, m.beans.prismContext, "reference time definition in " + m.getMappingContextDescription(), m.getTask(), result);
    LOGGER.trace("parseTimeSource: path = {}, source object = {}", path, sourceObject);
    if (sourceObject == null) {
        return null;
    }
    PrismProperty<XMLGregorianCalendar> timeProperty;
    if (sourceObject instanceof ItemDeltaItem<?, ?>) {
        // noinspection unchecked
        timeProperty = (PrismProperty<XMLGregorianCalendar>) ((ItemDeltaItem<?, ?>) sourceObject).getItemNew();
    } else if (sourceObject instanceof Item<?, ?>) {
        // noinspection unchecked
        timeProperty = (PrismProperty<XMLGregorianCalendar>) sourceObject;
    } else {
        throw new IllegalStateException("Unknown resolve result " + sourceObject);
    }
    return timeProperty != null ? timeProperty.getRealValue() : null;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with ItemDeltaItem

use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.

the class ExpressionUtil method computeTargetValues.

public static <V extends PrismValue> Collection<V> computeTargetValues(VariableBindingDefinitionType target, TypedValue defaultTargetContext, VariablesMap variables, ObjectResolver objectResolver, String contextDesc, PrismContext prismContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (target == null) {
        // Is this correct? What about default targets?
        return null;
    }
    ItemPathType itemPathType = target.getPath();
    if (itemPathType == null) {
        // Is this correct? What about default targets?
        return null;
    }
    ItemPath path = itemPathType.getItemPath();
    Object object = resolvePathGetValue(path, variables, false, defaultTargetContext, objectResolver, prismContext, contextDesc, task, result);
    if (object == null) {
        return new ArrayList<>();
    } else if (object instanceof Item) {
        return ((Item) object).getValues();
    } else if (object instanceof PrismValue) {
        return (List<V>) Collections.singletonList((PrismValue) object);
    } else if (object instanceof ItemDeltaItem) {
        ItemDeltaItem<V, ?> idi = (ItemDeltaItem<V, ?>) object;
        PrismValueDeltaSetTriple<V> triple = idi.toDeltaSetTriple(prismContext);
        return triple != null ? triple.getNonNegativeValues() : new ArrayList<>();
    } else {
        throw new IllegalStateException("Unsupported target value(s): " + object.getClass() + " (" + object + ")");
    }
}
Also used : ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with ItemDeltaItem

use of com.evolveum.midpoint.prism.util.ItemDeltaItem in project midpoint by Evolveum.

the class PathExpressionEvaluation method getInitialResolveContextFromVariable.

private ResolutionContext getInitialResolveContextFromVariable() throws ExpressionEvaluationException {
    String variableName = ItemPath.toVariableName(pathToResolve.first()).getLocalPart();
    pathToResolve = pathToResolve.rest();
    TypedValue variableValueAndDefinition = evaluator.findInSourcesAndVariables(context, variableName);
    if (variableValueAndDefinition == null) {
        throw new ExpressionEvaluationException("No variable with name " + variableName + " in " + context.getContextDescription());
    }
    Object variableValue = variableValueAndDefinition.getValue();
    if (variableValue == null) {
        return null;
    } else if (variableValue instanceof Item || variableValue instanceof ItemDeltaItem<?, ?>) {
        return IdiResolutionContext.fromAnyObject(variableValue);
    } else if (variableValue instanceof PrismValue) {
        return new ValueResolutionContext((PrismValue) variableValue, context.getContextDescription());
    } else if (variableValueAndDefinition.getTypeClass().isAssignableFrom(variableValue.getClass())) {
        return ValueResolutionContext.fromRealValue(variableValue, context.getContextDescription(), evaluator.getPrismContext());
    } else {
        throw new ExpressionEvaluationException("Unexpected variable value " + variableValue + " (" + variableValue.getClass() + ")");
    }
}
Also used : ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) ItemDeltaItem(com.evolveum.midpoint.prism.util.ItemDeltaItem) TypedValue(com.evolveum.midpoint.schema.expression.TypedValue)

Aggregations

ItemDeltaItem (com.evolveum.midpoint.prism.util.ItemDeltaItem)15 ObjectDeltaObject (com.evolveum.midpoint.prism.util.ObjectDeltaObject)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)3 Source (com.evolveum.midpoint.repo.common.expression.Source)3 PrismContainerDefinition (com.evolveum.midpoint.prism.PrismContainerDefinition)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2 TypedValue (com.evolveum.midpoint.schema.expression.TypedValue)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 Task (com.evolveum.midpoint.task.api.Task)2 EvaluatedAssignment (com.evolveum.midpoint.model.api.context.EvaluatedAssignment)1 EvaluatedAssignmentTarget (com.evolveum.midpoint.model.api.context.EvaluatedAssignmentTarget)1 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)1 ObjectValuePolicyEvaluator (com.evolveum.midpoint.model.common.stringpolicy.ObjectValuePolicyEvaluator)1 ShadowValuePolicyOriginResolver (com.evolveum.midpoint.model.common.stringpolicy.ShadowValuePolicyOriginResolver)1 ValuePolicyProcessor (com.evolveum.midpoint.model.common.stringpolicy.ValuePolicyProcessor)1 ModelObjectResolver (com.evolveum.midpoint.model.impl.ModelObjectResolver)1 com.evolveum.midpoint.model.impl.lens (com.evolveum.midpoint.model.impl.lens)1 AssignmentEvaluator (com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator)1 ContextLoader (com.evolveum.midpoint.model.impl.lens.projector.ContextLoader)1