Search in sources :

Example 1 with PathKeyedMap

use of com.evolveum.midpoint.prism.path.PathKeyedMap in project midpoint by Evolveum.

the class ItemLimitationsChecker method checkItemsLimitations.

/**
 * @pre Focus context is recomputed.
 */
<O extends ObjectType> void checkItemsLimitations(LensFocusContext<O> focusContext) throws SchemaException {
    PathKeyedMap<ObjectTemplateItemDefinitionType> itemDefinitionsMap = focusContext.getItemDefinitionsMap();
    PrismObject<O> objectNew = focusContext.getObjectNew();
    if (objectNew == null) {
        // nothing to check on DELETE operation
        return;
    }
    for (Map.Entry<ItemPath, ObjectTemplateItemDefinitionType> entry : itemDefinitionsMap.entrySet()) {
        for (PropertyLimitationsType limitation : entry.getValue().getLimitations()) {
            if (!limitation.getLayer().contains(LayerType.MODEL)) {
                // or should we apply SCHEMA-layer limitations as well?
                continue;
            }
            checkItemLimitations(objectNew, entry.getKey(), limitation);
        }
    }
}
Also used : ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) Map(java.util.Map) PathKeyedMap(com.evolveum.midpoint.prism.path.PathKeyedMap) PropertyLimitationsType(com.evolveum.midpoint.xml.ns._public.common.common_3.PropertyLimitationsType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with PathKeyedMap

use of com.evolveum.midpoint.prism.path.PathKeyedMap in project midpoint by Evolveum.

the class AssignmentProcessor method evaluateFocusMappings.

private <AH extends AssignmentHolderType> void evaluateFocusMappings(LensContext<AH> context, XMLGregorianCalendar now, LensFocusContext<AH> focusContext, DeltaSetTriple<EvaluatedAssignmentImpl<AH>> evaluatedAssignmentTriple, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, PolicyViolationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, CommunicationException {
    OperationResult result = parentResult.subresult(OP_EVALUATE_FOCUS_MAPPINGS).setMinor().build();
    try {
        LOGGER.trace("Starting evaluation of assignment-held mappings");
        ObjectDeltaObject<AH> focusOdoRelative = focusContext.getObjectDeltaObjectRelative();
        List<AssignedFocusMappingEvaluationRequest> allRequests = new ArrayList<>();
        for (EvaluatedAssignmentImpl<AH> evaluatedAssignment : evaluatedAssignmentTriple.getAllValues()) {
            allRequests.addAll(evaluatedAssignment.getFocusMappingEvaluationRequests());
        }
        FocalMappingSetEvaluation.TripleCustomizer<?, ?> customizer = (triple, abstractRequest) -> {
            if (triple == null) {
                return null;
            }
            DeltaSetTriple<ItemValueWithOrigin<PrismValue, ItemDefinition<?>>> rv = prismContext.deltaFactory().createDeltaSetTriple();
            AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
            // noinspection unchecked
            EvaluatedAssignmentImpl<AH> evaluatedAssignment = (EvaluatedAssignmentImpl<AH>) request.getEvaluatedAssignment();
            PlusMinusZero relativeMode = request.getRelativeMode();
            Set<PlusMinusZero> presence = new HashSet<>();
            PlusMinusZero resultingMode = null;
            if (evaluatedAssignmentTriple.presentInPlusSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.PLUS, relativeMode);
                presence.add(PlusMinusZero.PLUS);
            }
            if (evaluatedAssignmentTriple.presentInMinusSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.MINUS, relativeMode);
                presence.add(PlusMinusZero.MINUS);
            }
            if (evaluatedAssignmentTriple.presentInZeroSet(evaluatedAssignment)) {
                resultingMode = PlusMinusZero.compute(PlusMinusZero.ZERO, relativeMode);
                presence.add(PlusMinusZero.ZERO);
            }
            LOGGER.trace("triple customizer: presence = {}, relativeMode = {}, resultingMode = {}", presence, relativeMode, resultingMode);
            if (presence.isEmpty()) {
                throw new IllegalStateException("Evaluated assignment is not present in any of plus/minus/zero sets " + "of the triple. Assignment = " + evaluatedAssignment + ", triple = " + triple);
            } else if (presence.size() > 1) {
                // TODO think about this
                throw new IllegalStateException("Evaluated assignment is present in more than one plus/minus/zero sets " + "of the triple: " + presence + ". Assignment = " + evaluatedAssignment + ", triple = " + triple);
            }
            if (resultingMode != null) {
                switch(resultingMode) {
                    case PLUS:
                        // MID-6403
                        rv.addAllToPlusSet(triple.getNonNegativeValues());
                        break;
                    case MINUS:
                        // MID-6403
                        rv.addAllToMinusSet(triple.getNonPositiveValues());
                        break;
                    case ZERO:
                        rv = triple;
                        break;
                }
            }
            return rv;
        };
        FocalMappingSetEvaluation.EvaluatedMappingConsumer mappingConsumer = (mapping, abstractRequest) -> {
            AssignedFocusMappingEvaluationRequest request = (AssignedFocusMappingEvaluationRequest) abstractRequest;
            request.getEvaluatedAssignment().addFocusMapping(mapping);
        };
        TargetObjectSpecification<AH> targetSpecification = new FixedTargetSpecification<>(focusOdoRelative.getNewObject(), true);
        MappingEvaluationEnvironment env = new MappingEvaluationEnvironment("focus mappings in assignments of " + focusContext.getHumanReadableName(), now, task);
        FocalMappingSetEvaluation<AH, AH> mappingSetEvaluation = new FocalMappingSetEvaluationBuilder<AH, AH>().context(context).evaluationRequests(allRequests).phase(null).focusOdo(focusOdoRelative).targetSpecification(targetSpecification).tripleCustomizer(customizer).mappingConsumer(mappingConsumer).iteration(focusContext.getIteration()).iterationToken(focusContext.getIterationToken()).beans(beans).env(env).result(result).build();
        mappingSetEvaluation.evaluateMappingsToTriples();
        PathKeyedMap<DeltaSetTriple<ItemValueWithOrigin<?, ?>>> focusOutputTripleMap = mappingSetEvaluation.getOutputTripleMap();
        logOutputTripleMap(focusOutputTripleMap);
        DeltaSetTripleMapConsolidation<AH> consolidation = new DeltaSetTripleMapConsolidation<>(focusOutputTripleMap, focusOdoRelative.getNewObject(), focusOdoRelative.getObjectDelta(), context::primaryFocusItemDeltaExists, null, null, focusContext.getObjectDefinition(), env, beans, context, result);
        consolidation.computeItemDeltas();
        Collection<ItemDelta<?, ?>> focusDeltas = consolidation.getItemDeltas();
        LOGGER.trace("Computed focus deltas: {}", focusDeltas);
        focusContext.swallowToSecondaryDelta(focusDeltas);
        focusContext.recompute();
    } catch (Throwable t) {
        result.recordFatalError(t.getMessage(), t);
        throw t;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) OperationResultStatus(com.evolveum.midpoint.schema.result.OperationResultStatus) BooleanUtils(org.apache.commons.lang.BooleanUtils) MappingFactory(com.evolveum.midpoint.model.common.mapping.MappingFactory) QNameUtil(com.evolveum.midpoint.util.QNameUtil) LensContext(com.evolveum.midpoint.model.impl.lens.LensContext) ProcessorExecution(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorExecution) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ActivationComputer(com.evolveum.midpoint.common.ActivationComputer) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) Objects(java.util.Objects) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ComplexConstructionConsumer(com.evolveum.midpoint.model.impl.lens.projector.ComplexConstructionConsumer) SystemObjectCache(com.evolveum.midpoint.model.common.SystemObjectCache) ProvisioningService(com.evolveum.midpoint.provisioning.api.ProvisioningService) Entry(java.util.Map.Entry) com.evolveum.midpoint.prism.delta(com.evolveum.midpoint.prism.delta) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) ProcessorMethod(com.evolveum.midpoint.model.impl.lens.projector.util.ProcessorMethod) FocusTypeUtil(com.evolveum.midpoint.schema.util.FocusTypeUtil) ContextLoader(com.evolveum.midpoint.model.impl.lens.projector.ContextLoader) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) java.util(java.util) com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ModelBeans(com.evolveum.midpoint.model.impl.ModelBeans) ObjectDeltaObject(com.evolveum.midpoint.prism.util.ObjectDeltaObject) EvaluatedConstructionPack(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedConstructionPack) SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Trace(com.evolveum.midpoint.util.logging.Trace) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ModelImplUtils(com.evolveum.midpoint.model.impl.util.ModelImplUtils) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectTypeUtil(com.evolveum.midpoint.schema.util.ObjectTypeUtil) SchemaDebugUtil(com.evolveum.midpoint.schema.util.SchemaDebugUtil) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) com.evolveum.midpoint.model.impl.lens.projector.mappings(com.evolveum.midpoint.model.impl.lens.projector.mappings) RelationRegistry(com.evolveum.midpoint.schema.RelationRegistry) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PathKeyedMap(com.evolveum.midpoint.prism.path.PathKeyedMap) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) EvaluatedAssignedResourceObjectConstructionImpl(com.evolveum.midpoint.model.impl.lens.construction.EvaluatedAssignedResourceObjectConstructionImpl) ProjectorProcessor(com.evolveum.midpoint.model.impl.lens.projector.ProjectorProcessor) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) DeltaSetTripleMapConsolidation(com.evolveum.midpoint.model.impl.lens.projector.focus.consolidation.DeltaSetTripleMapConsolidation) LensUtil(com.evolveum.midpoint.model.impl.lens.LensUtil) ConstructionProcessor(com.evolveum.midpoint.model.impl.lens.projector.ConstructionProcessor) AssignmentEvaluator(com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectResolver(com.evolveum.midpoint.repo.common.ObjectResolver) SynchronizationPolicyDecision(com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) ReferenceResolver(com.evolveum.midpoint.model.api.util.ReferenceResolver) Component(org.springframework.stereotype.Component) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ItemName(com.evolveum.midpoint.prism.path.ItemName) PolicyRuleProcessor(com.evolveum.midpoint.model.impl.lens.projector.policy.PolicyRuleProcessor) LensFocusContext(com.evolveum.midpoint.model.impl.lens.LensFocusContext) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MappingEvaluationEnvironment(com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment) EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl) DeltaSetTripleMapConsolidation(com.evolveum.midpoint.model.impl.lens.projector.focus.consolidation.DeltaSetTripleMapConsolidation)

Example 3 with PathKeyedMap

use of com.evolveum.midpoint.prism.path.PathKeyedMap in project midpoint by Evolveum.

the class MappedItem method createMappings.

/**
 * Creates the respective mapping(s).
 */
void createMappings(@NotNull PathKeyedMap<List<InboundMappingInContext<?, ?>>> mappingsMap) throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
    boolean fromAbsoluteState = processingMode == ProcessingMode.ABSOLUTE_STATE || processingMode == ProcessingMode.ABSOLUTE_STATE_IF_KNOWN;
    if (fromAbsoluteState && !source.isAbsoluteStateAvailable()) {
        LOGGER.trace("Skipping inbound mapping(s) for {} as they should be processed from absolute state, but we don't" + " have one", itemDescription);
        return;
    }
    Item<V, D> currentProjectionItem = itemProvider.provide();
    if (postProcessor != null) {
        postProcessor.postProcess(itemAPrioriDelta, currentProjectionItem);
    }
    LOGGER.trace("Creating {} inbound mapping(s) for {} in {} ({}). Relevant values are:\n" + "- a priori item delta:\n{}\n" + "- current item:\n{}", mappingBeans.size(), itemDescription, source.getProjectionHumanReadableNameLazy(), fromAbsoluteState ? "absolute mode" : "relative mode", DebugUtil.debugDumpLazily(itemAPrioriDelta, 1), DebugUtil.debugDumpLazily(currentProjectionItem, 1));
    if (currentProjectionItem != null && currentProjectionItem.hasRaw()) {
        throw new SystemException("Property " + currentProjectionItem + " has raw parsing state," + " such property cannot be used in inbound expressions");
    }
    source.setValueMetadata(currentProjectionItem, itemAPrioriDelta);
    ResourceType resource = source.getResource();
    // Value for the $shadow ($projection, $account) variable.
    // TODO Why do we use "object new" here? (We should perhaps go with ODO, shouldn't we?)
    // Bear in mind that the value might not contain the full shadow (for example)
    PrismObject<ShadowType> shadowVariableValue = source.getResourceObjectNew();
    PrismObjectDefinition<ShadowType> shadowVariableDef = getShadowDefinition(shadowVariableValue);
    Source<V, D> defaultSource = new Source<>(currentProjectionItem, itemAPrioriDelta, null, ExpressionConstants.VAR_INPUT_QNAME, itemDefinition);
    defaultSource.recompute();
    for (MappingType mappingBean : mappingBeans) {
        String channel = source.getChannel();
        if (!MappingImpl.isApplicableToChannel(mappingBean, channel)) {
            LOGGER.trace("Mapping is not applicable to channel {}", channel);
            continue;
        }
        MappingBuilder<V, D> builder = beans.mappingFactory.<V, D>createMappingBuilder().mappingBean(mappingBean).mappingKind(MappingKindType.INBOUND).implicitSourcePath(implicitSourcePath).contextDescription("inbound expression for " + itemDescription + " in " + resource).defaultSource(defaultSource).targetContext(target.focusDefinition).addVariableDefinition(ExpressionConstants.VAR_USER, target.focus, target.focusDefinition).addVariableDefinition(ExpressionConstants.VAR_FOCUS, target.focus, target.focusDefinition).addAliasRegistration(ExpressionConstants.VAR_USER, ExpressionConstants.VAR_FOCUS).addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, shadowVariableValue, shadowVariableDef).addVariableDefinition(ExpressionConstants.VAR_SHADOW, shadowVariableValue, shadowVariableDef).addVariableDefinition(ExpressionConstants.VAR_PROJECTION, shadowVariableValue, shadowVariableDef).addAliasRegistration(ExpressionConstants.VAR_ACCOUNT, ExpressionConstants.VAR_PROJECTION).addAliasRegistration(ExpressionConstants.VAR_SHADOW, ExpressionConstants.VAR_PROJECTION).addVariableDefinition(ExpressionConstants.VAR_RESOURCE, resource, resource.asPrismObject().getDefinition()).addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration(), getSystemConfigurationDefinition()).addVariableDefinition(ExpressionConstants.VAR_OPERATION, context.getOperation(), String.class).variableResolver(variableProducer).valuePolicySupplier(context.createValuePolicySupplier()).originType(OriginType.INBOUND).originObject(resource).now(context.env.now);
        if (!target.isFocusBeingDeleted()) {
            assert target.focus != null;
            TypedValue<PrismObject<F>> targetContext = new TypedValue<>(target.focus);
            builder.originalTargetValues(ExpressionUtil.computeTargetValues(mappingBean.getTarget(), targetContext, builder.getVariables(), beans.mappingFactory.getObjectResolver(), "resolving target values", beans.prismContext, context.env.task, context.result));
        }
        MappingImpl<V, D> mapping = builder.build();
        if (checkWeakSkip(mapping)) {
            LOGGER.trace("Skipping because of mapping is weak and focus property has already a value");
            continue;
        }
        InboundMappingInContext<V, D> mappingStruct = source.createInboundMappingInContext(mapping);
        ItemPath targetFocusItemPath = mapping.getOutputPath();
        if (ItemPath.isEmpty(targetFocusItemPath)) {
            throw new ConfigurationException("Empty target path in " + mapping.getContextDescription());
        }
        checkTargetItemDefinitionKnown(targetFocusItemPath);
        mappingsMap.computeIfAbsent(targetFocusItemPath, k -> new ArrayList<>()).add(mappingStruct);
    }
}
Also used : com.evolveum.midpoint.xml.ns._public.common.common_3(com.evolveum.midpoint.xml.ns._public.common.common_3) ModelBeans(com.evolveum.midpoint.model.impl.ModelBeans) InboundMappingInContext(com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.InboundMappingInContext) Trace(com.evolveum.midpoint.util.logging.Trace) DebugUtil(com.evolveum.midpoint.util.DebugUtil) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) VariableProducer(com.evolveum.midpoint.repo.common.expression.VariableProducer) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ArrayList(java.util.ArrayList) MappingImpl(com.evolveum.midpoint.model.common.mapping.MappingImpl) PathKeyedMap(com.evolveum.midpoint.prism.path.PathKeyedMap) com.evolveum.midpoint.prism(com.evolveum.midpoint.prism) Collection(java.util.Collection) TypedValue(com.evolveum.midpoint.schema.expression.TypedValue) MiscUtil(com.evolveum.midpoint.util.MiscUtil) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Objects(java.util.Objects) List(java.util.List) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) MiscUtil.argCheck(com.evolveum.midpoint.util.MiscUtil.argCheck) Source(com.evolveum.midpoint.repo.common.expression.Source) MappingBuilder(com.evolveum.midpoint.model.common.mapping.MappingBuilder) NotNull(org.jetbrains.annotations.NotNull) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ArrayList(java.util.ArrayList) Source(com.evolveum.midpoint.repo.common.expression.Source) TypedValue(com.evolveum.midpoint.schema.expression.TypedValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 PathKeyedMap (com.evolveum.midpoint.prism.path.PathKeyedMap)3 ModelBeans (com.evolveum.midpoint.model.impl.ModelBeans)2 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)2 ActivationComputer (com.evolveum.midpoint.common.ActivationComputer)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)1 ReferenceResolver (com.evolveum.midpoint.model.api.util.ReferenceResolver)1 SystemObjectCache (com.evolveum.midpoint.model.common.SystemObjectCache)1 MappingBuilder (com.evolveum.midpoint.model.common.mapping.MappingBuilder)1 MappingEvaluationEnvironment (com.evolveum.midpoint.model.common.mapping.MappingEvaluationEnvironment)1 MappingFactory (com.evolveum.midpoint.model.common.mapping.MappingFactory)1 MappingImpl (com.evolveum.midpoint.model.common.mapping.MappingImpl)1 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)1 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)1 LensFocusContext (com.evolveum.midpoint.model.impl.lens.LensFocusContext)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 LensUtil (com.evolveum.midpoint.model.impl.lens.LensUtil)1 AssignmentEvaluator (com.evolveum.midpoint.model.impl.lens.assignments.AssignmentEvaluator)1 EvaluatedAssignmentImpl (com.evolveum.midpoint.model.impl.lens.assignments.EvaluatedAssignmentImpl)1