Search in sources :

Example 1 with MappingBuilder

use of com.evolveum.midpoint.model.common.mapping.MappingBuilder 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

MappingBuilder (com.evolveum.midpoint.model.common.mapping.MappingBuilder)1 MappingImpl (com.evolveum.midpoint.model.common.mapping.MappingImpl)1 ModelBeans (com.evolveum.midpoint.model.impl.ModelBeans)1 InboundMappingInContext (com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.InboundMappingInContext)1 com.evolveum.midpoint.prism (com.evolveum.midpoint.prism)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 PathKeyedMap (com.evolveum.midpoint.prism.path.PathKeyedMap)1 ExpressionUtil (com.evolveum.midpoint.repo.common.expression.ExpressionUtil)1 Source (com.evolveum.midpoint.repo.common.expression.Source)1 VariableProducer (com.evolveum.midpoint.repo.common.expression.VariableProducer)1 ExpressionConstants (com.evolveum.midpoint.schema.constants.ExpressionConstants)1 TypedValue (com.evolveum.midpoint.schema.expression.TypedValue)1 DebugUtil (com.evolveum.midpoint.util.DebugUtil)1 MiscUtil (com.evolveum.midpoint.util.MiscUtil)1 MiscUtil.argCheck (com.evolveum.midpoint.util.MiscUtil.argCheck)1 com.evolveum.midpoint.util.exception (com.evolveum.midpoint.util.exception)1 Trace (com.evolveum.midpoint.util.logging.Trace)1 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)1 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)1