Search in sources :

Example 76 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class MappingEvaluator method evaluateMappingSetProjection.

public <V extends PrismValue, D extends ItemDefinition, T extends ObjectType, F extends FocusType> void evaluateMappingSetProjection(MappingEvaluatorParams<V, D, T, F> params, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException {
    String mappingDesc = params.getMappingDesc();
    LensElementContext<T> targetContext = params.getTargetContext();
    PrismObjectDefinition<T> targetObjectDefinition = targetContext.getObjectDefinition();
    ItemPath defaultTargetItemPath = params.getDefaultTargetItemPath();
    Map<ItemPath, MappingOutputStruct<V>> outputTripleMap = new HashMap<>();
    XMLGregorianCalendar nextRecomputeTime = null;
    Collection<MappingType> mappingTypes = params.getMappingTypes();
    Collection<Mapping<V, D>> mappings = new ArrayList<>(mappingTypes.size());
    for (MappingType mappingType : mappingTypes) {
        Mapping.Builder<V, D> mappingBuilder = mappingFactory.createMappingBuilder(mappingType, mappingDesc);
        String mappingName = null;
        if (mappingType.getName() != null) {
            mappingName = mappingType.getName();
        }
        if (!mappingBuilder.isApplicableToChannel(params.getContext().getChannel())) {
            LOGGER.trace("Mapping {} not applicable to channel, skipping {}", mappingName, params.getContext().getChannel());
            continue;
        }
        mappingBuilder.now(params.getNow());
        if (defaultTargetItemPath != null && targetObjectDefinition != null) {
            D defaultTargetItemDef = targetObjectDefinition.findItemDefinition(defaultTargetItemPath);
            mappingBuilder.defaultTargetDefinition(defaultTargetItemDef);
            mappingBuilder.defaultTargetPath(defaultTargetItemPath);
        } else {
            mappingBuilder.defaultTargetDefinition(params.getTargetItemDefinition());
            mappingBuilder.defaultTargetPath(defaultTargetItemPath);
        }
        mappingBuilder.targetContext(targetObjectDefinition);
        if (params.getSourceContext() != null) {
            mappingBuilder.sourceContext(params.getSourceContext());
        }
        // Initialize mapping (using Inversion of Control)
        mappingBuilder = params.getInitializer().initialize(mappingBuilder);
        Mapping<V, D> mapping = mappingBuilder.build();
        Boolean timeConstraintValid = mapping.evaluateTimeConstraintValid(task, result);
        if (params.getEvaluateCurrent() != null) {
            if (params.getEvaluateCurrent() && !timeConstraintValid) {
                LOGGER.trace("Mapping {} is non-current, but evulating current mappings, skipping {}", mappingName, params.getContext().getChannel());
                continue;
            }
            if (!params.getEvaluateCurrent() && timeConstraintValid) {
                LOGGER.trace("Mapping {} is current, but evulating non-current mappings, skipping {}", mappingName, params.getContext().getChannel());
                continue;
            }
        }
        mappings.add(mapping);
    }
    boolean hasFullTargetObject = params.hasFullTargetObject();
    PrismObject<T> aPrioriTargetObject = params.getAPrioriTargetObject();
    LOGGER.trace("Going to process {} mappings for {}", mappings.size(), mappingDesc);
    for (Mapping<V, D> mapping : mappings) {
        if (mapping.getStrength() == MappingStrengthType.WEAK) {
            // Evaluate weak mappings in a second run.
            continue;
        }
        ItemPath mappingOutputPath = mapping.getOutputPath();
        if (params.isFixTarget() && mappingOutputPath != null && defaultTargetItemPath != null && !mappingOutputPath.equivalent(defaultTargetItemPath)) {
            throw new ExpressionEvaluationException("Target cannot be overridden in " + mappingDesc);
        }
        if (params.getAPrioriTargetDelta() != null && mappingOutputPath != null) {
            ItemDelta<?, ?> aPrioriItemDelta = params.getAPrioriTargetDelta().findItemDelta(mappingOutputPath);
            if (mapping.getStrength() != MappingStrengthType.STRONG) {
                if (aPrioriItemDelta != null && !aPrioriItemDelta.isEmpty()) {
                    continue;
                }
            }
        }
        evaluateMapping(mapping, params.getContext(), task, result);
        PrismValueDeltaSetTriple<V> mappingOutputTriple = mapping.getOutputTriple();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Output triple of mapping {}\n{}", mapping.getContextDescription(), mappingOutputTriple == null ? null : mappingOutputTriple.debugDump(1));
        }
        if (mappingOutputTriple != null) {
            MappingOutputStruct<V> mappingOutputStruct = outputTripleMap.get(mappingOutputPath);
            if (mappingOutputStruct == null) {
                mappingOutputStruct = new MappingOutputStruct<>();
                outputTripleMap.put(mappingOutputPath, mappingOutputStruct);
            }
            if (mapping.getStrength() == MappingStrengthType.STRONG) {
                mappingOutputStruct.setStrongMappingWasUsed(true);
            //                	if (!hasFullTargetObject && params.getTargetLoader() != null) {
            //    					if (!params.getTargetLoader().isLoaded()) {
            //    						aPrioriTargetObject = params.getTargetLoader().load(task, result);
            //    						LOGGER.trace("Loaded object because of strong mapping: {}", aPrioriTargetObject);
            //    						hasFullTargetObject = true;
            //    					}
            //    				}
            }
            PrismValueDeltaSetTriple<V> outputTriple = mappingOutputStruct.getOutputTriple();
            if (outputTriple == null) {
                mappingOutputStruct.setOutputTriple(mappingOutputTriple);
            } else {
                outputTriple.merge(mappingOutputTriple);
            }
        }
    }
    if (params.isEvaluateWeak()) {
        // Second pass, evaluate only weak mappings
        for (Mapping<V, D> mapping : mappings) {
            if (mapping.getStrength() != MappingStrengthType.WEAK) {
                continue;
            }
            ItemPath mappingOutputPath = mapping.getOutputPath();
            if (params.isFixTarget() && mappingOutputPath != null && defaultTargetItemPath != null && !mappingOutputPath.equivalent(defaultTargetItemPath)) {
                throw new ExpressionEvaluationException("Target cannot be overridden in " + mappingDesc);
            }
            MappingOutputStruct<V> mappingOutputStruct = outputTripleMap.get(mappingOutputPath);
            if (mappingOutputStruct == null) {
                mappingOutputStruct = new MappingOutputStruct<>();
                outputTripleMap.put(mappingOutputPath, mappingOutputStruct);
            }
            PrismValueDeltaSetTriple<V> outputTriple = mappingOutputStruct.getOutputTriple();
            if (outputTriple != null) {
                // MID-3847
                continue;
            }
            Item<V, D> aPrioriTargetItem = null;
            if (aPrioriTargetObject != null && mappingOutputPath != null) {
                aPrioriTargetItem = aPrioriTargetObject.findItem(mappingOutputPath);
            }
            if (hasNoValue(aPrioriTargetItem)) {
                mappingOutputStruct.setWeakMappingWasUsed(true);
                evaluateMapping(mapping, params.getContext(), task, result);
                PrismValueDeltaSetTriple<V> mappingOutputTriple = mapping.getOutputTriple();
                if (mappingOutputTriple != null) {
                    // This is all not right. See MID-3847
                    if (!hasFullTargetObject && params.getTargetLoader() != null) {
                        if (!params.getTargetLoader().isLoaded()) {
                            aPrioriTargetObject = params.getTargetLoader().load("weak mapping", task, result);
                            LOGGER.trace("Loaded object because of weak mapping: {}", aPrioriTargetObject);
                            hasFullTargetObject = true;
                        }
                    }
                    if (aPrioriTargetObject != null && mappingOutputPath != null) {
                        aPrioriTargetItem = aPrioriTargetObject.findItem(mappingOutputPath);
                    }
                    if (!hasNoValue(aPrioriTargetItem)) {
                        continue;
                    }
                    if (outputTriple == null) {
                        mappingOutputStruct.setOutputTriple(mappingOutputTriple);
                    } else {
                        outputTriple.merge(mappingOutputTriple);
                    }
                }
            }
        }
    }
    MappingOutputProcessor<V> processor = params.getProcessor();
    for (Entry<ItemPath, MappingOutputStruct<V>> outputTripleMapEntry : outputTripleMap.entrySet()) {
        ItemPath mappingOutputPath = outputTripleMapEntry.getKey();
        MappingOutputStruct<V> mappingOutputStruct = outputTripleMapEntry.getValue();
        PrismValueDeltaSetTriple<V> outputTriple = mappingOutputStruct.getOutputTriple();
        boolean defaultProcessing = true;
        if (processor != null) {
            LOGGER.trace("Executing processor to process mapping evaluation results: {}", processor);
            defaultProcessing = processor.process(mappingOutputPath, mappingOutputStruct);
        }
        if (defaultProcessing) {
            if (outputTriple == null) {
                LOGGER.trace("{} expression resulted in null triple for {}, skipping", mappingDesc, targetContext);
                continue;
            }
            ItemDefinition targetItemDefinition = null;
            if (mappingOutputPath != null) {
                targetItemDefinition = targetObjectDefinition.findItemDefinition(mappingOutputPath);
                if (targetItemDefinition == null) {
                    throw new SchemaException("No definition for item " + mappingOutputPath + " in " + targetObjectDefinition);
                }
            } else {
                targetItemDefinition = params.getTargetItemDefinition();
            }
            ItemDelta<V, D> targetItemDelta = targetItemDefinition.createEmptyDelta(mappingOutputPath);
            Item<V, D> aPrioriTargetItem = null;
            if (aPrioriTargetObject != null) {
                aPrioriTargetItem = aPrioriTargetObject.findItem(mappingOutputPath);
            }
            if (targetContext.isAdd()) {
                Collection<V> nonNegativeValues = outputTriple.getNonNegativeValues();
                if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
                    LOGGER.trace("{} resulted in null or empty value for {}, skipping", mappingDesc, targetContext);
                    continue;
                }
                targetItemDelta.setValuesToReplace(PrismValue.cloneCollection(nonNegativeValues));
            } else {
                // if we have fresh information (full shadow) AND the mapping used to derive the information was strong,
                // we will consider all values (zero & plus sets) -- otherwise, we take only the "plus" (i.e. changed) set
                // the first case is necessary, because in some situations (e.g. when mapping is changed)
                // the evaluator sees no differences w.r.t. real state, even if there is a difference
                // - and we must have a way to push new information onto the resource
                Collection<V> valuesToReplace;
                if (hasFullTargetObject && mappingOutputStruct.isStrongMappingWasUsed()) {
                    valuesToReplace = outputTriple.getNonNegativeValues();
                } else {
                    valuesToReplace = outputTriple.getPlusSet();
                }
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("{}: hasFullTargetObject={}, isStrongMappingWasUsed={}, valuesToReplace={}", new Object[] { mappingDesc, hasFullTargetObject, mappingOutputStruct.isStrongMappingWasUsed(), valuesToReplace });
                }
                if (valuesToReplace != null && !valuesToReplace.isEmpty()) {
                    if (hasFullTargetObject && targetContext.isFresh() && aPrioriTargetItem != null) {
                        Collection<V> valuesPresent = aPrioriTargetItem.getValues();
                        if (PrismValue.equalsRealValues(valuesPresent, valuesToReplace)) {
                            LOGGER.trace("{} resulted in existing values for {}, skipping creation of a delta", mappingDesc, targetContext);
                            continue;
                        }
                    }
                    targetItemDelta.setValuesToReplace(PrismValue.cloneCollection(valuesToReplace));
                } else if (outputTriple.hasMinusSet()) {
                    LOGGER.trace("{} resulted in null or empty value for {} and there is a minus set, resetting it (replace with empty)", mappingDesc, targetContext);
                    targetItemDelta.setValueToReplace();
                } else {
                    LOGGER.trace("{} resulted in null or empty value for {}, skipping", mappingDesc, targetContext);
                }
            }
            if (targetItemDelta.isEmpty()) {
                continue;
            }
            LOGGER.trace("{} adding new delta for {}: {}", mappingDesc, targetContext, targetItemDelta);
            targetContext.swallowToSecondaryDelta(targetItemDelta);
        }
    }
    for (Mapping<V, D> mapping : mappings) {
        XMLGregorianCalendar mappingNextRecomputeTime = mapping.getNextRecomputeTime();
        if (mappingNextRecomputeTime != null) {
            if (nextRecomputeTime == null || nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
                nextRecomputeTime = mappingNextRecomputeTime;
            }
        }
    }
    if (nextRecomputeTime != null) {
        boolean alreadyHasTrigger = false;
        if (params.getAPrioriTargetObject() != null) {
            for (TriggerType trigger : params.getAPrioriTargetObject().asObjectable().getTrigger()) {
                if (RecomputeTriggerHandler.HANDLER_URI.equals(trigger.getHandlerUri()) && nextRecomputeTime.equals(trigger.getTimestamp())) {
                    alreadyHasTrigger = true;
                    break;
                }
            }
        }
        if (!alreadyHasTrigger) {
            PrismContainerDefinition<TriggerType> triggerContDef = targetObjectDefinition.findContainerDefinition(ObjectType.F_TRIGGER);
            ContainerDelta<TriggerType> triggerDelta = triggerContDef.createEmptyDelta(new ItemPath(ObjectType.F_TRIGGER));
            PrismContainerValue<TriggerType> triggerCVal = triggerContDef.createValue();
            triggerDelta.addValueToAdd(triggerCVal);
            TriggerType triggerType = triggerCVal.asContainerable();
            triggerType.setTimestamp(nextRecomputeTime);
            triggerType.setHandlerUri(RecomputeTriggerHandler.HANDLER_URI);
            targetContext.swallowToSecondaryDelta(triggerDelta);
        }
    }
}
Also used : ResourceBidirectionalMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBidirectionalMappingType) MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 77 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class MappingEvaluator method createFocusMapping.

public <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> Mapping<V, D> createFocusMapping(final MappingFactory mappingFactory, final LensContext<F> context, final MappingType mappingType, ObjectType originObject, ObjectDeltaObject<F> focusOdo, PrismObject<T> defaultTargetObject, AssignmentPathVariables assignmentPathVariables, Integer iteration, String iterationToken, PrismObject<SystemConfigurationType> configuration, XMLGregorianCalendar now, String contextDesc, final Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (!Mapping.isApplicableToChannel(mappingType, context.getChannel())) {
        LOGGER.trace("Mapping {} not applicable to channel {}, skipping.", mappingType, context.getChannel());
        return null;
    }
    StringPolicyResolver stringPolicyResolver = new StringPolicyResolver() {

        private ItemPath outputPath;

        private ItemDefinition outputDefinition;

        @Override
        public void setOutputPath(ItemPath outputPath) {
            this.outputPath = outputPath;
        }

        @Override
        public void setOutputDefinition(ItemDefinition outputDefinition) {
            this.outputDefinition = outputDefinition;
        }

        @Override
        public StringPolicyType resolve() {
            // TODO need to switch to ObjectValuePolicyEvaluator
            if (outputDefinition.getName().equals(PasswordType.F_VALUE)) {
                ValuePolicyType passwordPolicy = credentialsProcessor.determinePasswordPolicy(context.getFocusContext(), task, result);
                if (passwordPolicy == null) {
                    return null;
                }
                return passwordPolicy.getStringPolicy();
            }
            if (mappingType.getExpression() != null) {
                List<JAXBElement<?>> evaluators = mappingType.getExpression().getExpressionEvaluator();
                if (evaluators != null) {
                    for (JAXBElement jaxbEvaluator : evaluators) {
                        Object object = jaxbEvaluator.getValue();
                        if (object instanceof GenerateExpressionEvaluatorType && ((GenerateExpressionEvaluatorType) object).getValuePolicyRef() != null) {
                            ObjectReferenceType ref = ((GenerateExpressionEvaluatorType) object).getValuePolicyRef();
                            try {
                                ValuePolicyType valuePolicyType = mappingFactory.getObjectResolver().resolve(ref, ValuePolicyType.class, null, "resolving value policy for generate attribute " + outputDefinition.getName() + " value", task, new OperationResult("Resolving value policy"));
                                if (valuePolicyType != null) {
                                    return valuePolicyType.getStringPolicy();
                                }
                            } catch (CommonException ex) {
                                throw new SystemException(ex.getMessage(), ex);
                            }
                        }
                    }
                }
            }
            return null;
        }
    };
    ExpressionVariables variables = new ExpressionVariables();
    FOCUS_VARIABLE_NAMES.forEach(name -> variables.addVariableDefinition(name, focusOdo));
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, iteration);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken);
    variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, configuration);
    Collection<V> targetValues = computeTargetValues(mappingType.getTarget(), defaultTargetObject, variables, mappingFactory.getObjectResolver(), contextDesc, task, result);
    Mapping.Builder<V, D> mappingBuilder = mappingFactory.<V, D>createMappingBuilder(mappingType, contextDesc).sourceContext(focusOdo).targetContext(defaultTargetObject.getDefinition()).variables(variables).originalTargetValues(targetValues).originType(OriginType.USER_POLICY).originObject(originObject).stringPolicyResolver(stringPolicyResolver).rootNode(focusOdo).now(now);
    mappingBuilder = LensUtil.addAssignmentPathVariables(mappingBuilder, assignmentPathVariables);
    Mapping<V, D> mapping = mappingBuilder.build();
    ItemPath itemPath = mapping.getOutputPath();
    if (itemPath == null) {
        // no output element, i.e. this is a "validation mapping"
        return mapping;
    }
    if (defaultTargetObject != null) {
        Item<V, D> existingTargetItem = (Item<V, D>) defaultTargetObject.findItem(itemPath);
        if (existingTargetItem != null && !existingTargetItem.isEmpty() && mapping.getStrength() == MappingStrengthType.WEAK) {
            LOGGER.trace("Mapping {} is weak and target already has a value {}, skipping.", mapping, existingTargetItem);
            return null;
        }
    }
    return mapping;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ValuePolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValuePolicyType) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) StringPolicyResolver(com.evolveum.midpoint.repo.common.expression.StringPolicyResolver) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Mapping(com.evolveum.midpoint.model.common.mapping.Mapping) JAXBElement(javax.xml.bind.JAXBElement) Item(com.evolveum.midpoint.prism.Item) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PrismObject(com.evolveum.midpoint.prism.PrismObject) GenerateExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.GenerateExpressionEvaluatorType) CommonException(com.evolveum.midpoint.util.exception.CommonException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 78 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ObjectTemplateProcessor method computeItemDeltas.

<F extends FocusType, T extends FocusType> Collection<ItemDelta<?, ?>> computeItemDeltas(Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, @Nullable Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap, ObjectDelta<T> targetObjectAPrioriDelta, PrismObject<T> targetObject, PrismObjectDefinition<F> focusDefinition, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
    Collection<ItemDelta<?, ?>> itemDeltas = new ArrayList<>();
    LOGGER.trace("Computing deltas in {}, focusDelta:\n{}", contextDesc, targetObjectAPrioriDelta);
    boolean addUnchangedValues = false;
    if (targetObjectAPrioriDelta != null && targetObjectAPrioriDelta.isAdd()) {
        addUnchangedValues = true;
    }
    for (Entry<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> entry : outputTripleMap.entrySet()) {
        ItemPath itemPath = entry.getKey();
        DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>> outputTriple = entry.getValue();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Computed triple for {}:\n{}", itemPath, outputTriple.debugDump());
        }
        final ObjectTemplateItemDefinitionType templateItemDefinition;
        if (itemDefinitionsMap != null) {
            templateItemDefinition = ItemPathUtil.getFromMap(itemDefinitionsMap, itemPath);
        } else {
            templateItemDefinition = null;
        }
        boolean isNonTolerant = templateItemDefinition != null && Boolean.FALSE.equals(templateItemDefinition.isTolerant());
        ItemDelta aprioriItemDelta = getAprioriItemDelta(targetObjectAPrioriDelta, itemPath);
        // if non-tolerant, we want to gather ZERO & PLUS sets
        boolean filterExistingValues = !isNonTolerant;
        ItemDefinition itemDefinition = focusDefinition.findItemDefinition(itemPath);
        ItemDelta itemDelta = LensUtil.consolidateTripleToDelta(itemPath, (DeltaSetTriple) outputTriple, itemDefinition, aprioriItemDelta, targetObject, null, null, addUnchangedValues, filterExistingValues, false, contextDesc, true);
        // Do a quick version of reconciliation. There is not much to reconcile as both the source and the target
        // is focus. But there are few cases to handle, such as strong mappings, and sourceless normal mappings. 
        Collection<? extends ItemValueWithOrigin<?, ?>> zeroSet = outputTriple.getZeroSet();
        Item<PrismValue, ItemDefinition> itemNew = null;
        if (targetObject != null) {
            itemNew = targetObject.findItem(itemPath);
        }
        for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
            PrismValueDeltaSetTripleProducer<?, ?> mapping = zeroSetIvwo.getMapping();
            if ((mapping.getStrength() == null || mapping.getStrength() == MappingStrengthType.NORMAL)) {
                if (aprioriItemDelta != null && !aprioriItemDelta.isEmpty()) {
                    continue;
                }
                if (!mapping.isSourceless()) {
                    continue;
                }
                LOGGER.trace("Adding zero values from normal mapping {}, a-priori delta: {}, isSourceless: {}", mapping, aprioriItemDelta, mapping.isSourceless());
            } else if (mapping.getStrength() == MappingStrengthType.WEAK) {
                if ((itemNew != null && !itemNew.isEmpty()) || (itemDelta != null && itemDelta.addsAnyValue())) {
                    continue;
                }
                LOGGER.trace("Adding zero values from weak mapping {}, itemNew: {}, itemDelta: {}", mapping, itemNew, itemDelta);
            } else {
                LOGGER.trace("Adding zero values from strong mapping {}", mapping);
            }
            PrismValue valueFromZeroSet = zeroSetIvwo.getItemValue();
            if (itemNew == null || !itemNew.containsRealValue(valueFromZeroSet)) {
                LOGGER.trace("Reconciliation will add value {} for item {}. Existing item: {}", valueFromZeroSet, itemPath, itemNew);
                itemDelta.addValuesToAdd(valueFromZeroSet.clone());
            }
        }
        if (isNonTolerant) {
            if (itemDelta.isDelete()) {
                LOGGER.trace("Non-tolerant item with values to DELETE => removing them");
                // these are useless now - we move everything to REPLACE
                itemDelta.resetValuesToDelete();
            }
            if (itemDelta.isReplace()) {
                LOGGER.trace("Non-tolerant item with resulting REPLACE delta => doing nothing");
            } else {
                for (ItemValueWithOrigin<?, ?> zeroSetIvwo : zeroSet) {
                    itemDelta.addValuesToAdd(zeroSetIvwo.getItemValue().clone());
                }
                itemDelta.addToReplaceDelta();
                LOGGER.trace("Non-tolerant item with resulting ADD delta => converted ADD to REPLACE values: {}", itemDelta.getValuesToReplace());
            }
            // under a special option "createReplaceDelta", but for the time being, let's keep it here
            if (itemDelta instanceof PropertyDelta) {
                PropertyDelta propertyDelta = ((PropertyDelta) itemDelta);
                QName matchingRuleName = templateItemDefinition != null ? templateItemDefinition.getMatchingRule() : null;
                MatchingRule matchingRule = matchingRuleRegistry.getMatchingRule(matchingRuleName, null);
                if (propertyDelta.isRedundant(targetObject, matchingRule)) {
                    LOGGER.trace("Computed property delta is redundant => skipping it. Delta = \n{}", propertyDelta.debugDump());
                    continue;
                }
            } else {
                if (itemDelta.isRedundant(targetObject)) {
                    LOGGER.trace("Computed item delta is redundant => skipping it. Delta = \n{}", itemDelta.debugDump());
                    continue;
                }
            }
            PrismUtil.setDeltaOldValue(targetObject, itemDelta);
        }
        itemDelta.simplify();
        itemDelta.validate(contextDesc);
        itemDeltas.add(itemDelta);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Computed delta:\n{}", itemDelta.debugDump());
        }
    }
    return itemDeltas;
}
Also used : DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) PrismValue(com.evolveum.midpoint.prism.PrismValue) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) MatchingRule(com.evolveum.midpoint.prism.match.MatchingRule) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 79 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class FocusProcessor method processActivationLockout.

private <F extends FocusType> void processActivationLockout(LensFocusContext<UserType> focusContext, XMLGregorianCalendar now, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException {
    ObjectDelta<UserType> focusPrimaryDelta = focusContext.getPrimaryDelta();
    if (focusPrimaryDelta != null) {
        PropertyDelta<LockoutStatusType> lockoutStatusDelta = focusContext.getPrimaryDelta().findPropertyDelta(SchemaConstants.PATH_ACTIVATION_LOCKOUT_STATUS);
        if (lockoutStatusDelta != null) {
            if (lockoutStatusDelta.isAdd()) {
                for (PrismPropertyValue<LockoutStatusType> pval : lockoutStatusDelta.getValuesToAdd()) {
                    if (pval.getValue() == LockoutStatusType.LOCKED) {
                        throw new SchemaException("Lockout status cannot be changed to LOCKED value");
                    }
                }
            } else if (lockoutStatusDelta.isReplace()) {
                for (PrismPropertyValue<LockoutStatusType> pval : lockoutStatusDelta.getValuesToReplace()) {
                    if (pval.getValue() == LockoutStatusType.LOCKED) {
                        throw new SchemaException("Lockout status cannot be changed to LOCKED value");
                    }
                }
            }
        }
    }
    ActivationType activationNew = null;
    ActivationType activationCurrent = null;
    LockoutStatusType lockoutStatusNew = null;
    LockoutStatusType lockoutStatusCurrent = null;
    PrismObject<UserType> focusNew = focusContext.getObjectNew();
    if (focusNew != null) {
        activationNew = focusNew.asObjectable().getActivation();
        if (activationNew != null) {
            lockoutStatusNew = activationNew.getLockoutStatus();
        }
    }
    PrismObject<UserType> focusCurrent = focusContext.getObjectCurrent();
    if (focusCurrent != null) {
        activationCurrent = focusCurrent.asObjectable().getActivation();
        if (activationCurrent != null) {
            lockoutStatusCurrent = activationCurrent.getLockoutStatus();
        }
    }
    if (lockoutStatusNew == lockoutStatusCurrent) {
        // No change, (almost) no work
        LOGGER.trace("Skipping lockout processing because there was no change ({} -> {})", lockoutStatusCurrent, lockoutStatusNew);
        return;
    }
    LOGGER.trace("Lockout change {} -> {}", lockoutStatusCurrent, lockoutStatusNew);
    if (lockoutStatusNew == LockoutStatusType.NORMAL) {
        CredentialsType credentialsTypeNew = focusNew.asObjectable().getCredentials();
        if (credentialsTypeNew != null) {
            resetFailedLogins(focusContext, credentialsTypeNew.getPassword(), SchemaConstants.PATH_CREDENTIALS_PASSWORD_FAILED_LOGINS);
            resetFailedLogins(focusContext, credentialsTypeNew.getNonce(), SchemaConstants.PATH_CREDENTIALS_NONCE_FAILED_LOGINS);
            resetFailedLogins(focusContext, credentialsTypeNew.getSecurityQuestions(), SchemaConstants.PATH_CREDENTIALS_SECURITY_QUESTIONS_FAILED_LOGINS);
        }
        if (activationNew != null && activationNew.getLockoutExpirationTimestamp() != null) {
            PrismContainerDefinition<ActivationType> activationDefinition = getActivationDefinition();
            PrismPropertyDefinition<XMLGregorianCalendar> lockoutExpirationTimestampDef = activationDefinition.findPropertyDefinition(ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP);
            PropertyDelta<XMLGregorianCalendar> lockoutExpirationTimestampDelta = lockoutExpirationTimestampDef.createEmptyDelta(new ItemPath(UserType.F_ACTIVATION, ActivationType.F_LOCKOUT_EXPIRATION_TIMESTAMP));
            lockoutExpirationTimestampDelta.setValueToReplace();
            focusContext.swallowToProjectionWaveSecondaryDelta(lockoutExpirationTimestampDelta);
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NoFocusNameSchemaException(com.evolveum.midpoint.util.exception.NoFocusNameSchemaException) CredentialsType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ActivationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType) LockoutStatusType(com.evolveum.midpoint.xml.ns._public.common.common_3.LockoutStatusType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 80 with FocusType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType in project midpoint by Evolveum.

the class ObjectTemplateProcessor method collectTripleFromTemplate.

private <F extends FocusType, T extends FocusType> XMLGregorianCalendar collectTripleFromTemplate(LensContext<F> context, ObjectTemplateType objectTemplateType, ObjectTemplateMappingEvaluationPhaseType phase, ObjectDeltaObject<F> focusOdo, PrismObject<T> target, Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, int iteration, String iterationToken, XMLGregorianCalendar now, String contextDesc, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, PolicyViolationException {
    LOGGER.trace("Collecting triples from {}", objectTemplateType);
    XMLGregorianCalendar nextRecomputeTime = null;
    // Process includes
    for (ObjectReferenceType includeRef : objectTemplateType.getIncludeRef()) {
        PrismObject<ObjectTemplateType> includeObject = includeRef.asReferenceValue().getObject();
        if (includeObject == null) {
            ObjectTemplateType includeObjectType = modelObjectResolver.resolve(includeRef, ObjectTemplateType.class, null, "include reference in " + objectTemplateType + " in " + contextDesc, task, result);
            includeObject = includeObjectType.asPrismObject();
            // Store resolved object for future use (e.g. next waves).
            includeRef.asReferenceValue().setObject(includeObject);
        }
        LOGGER.trace("Including template {}", includeObject);
        ObjectTemplateType includeObjectType = includeObject.asObjectable();
        XMLGregorianCalendar includeNextRecomputeTime = collectTripleFromTemplate(context, includeObjectType, phase, focusOdo, target, outputTripleMap, iteration, iterationToken, now, "include " + includeObject + " in " + objectTemplateType + " in " + contextDesc, task, result);
        if (includeNextRecomputeTime != null) {
            if (nextRecomputeTime == null || nextRecomputeTime.compare(includeNextRecomputeTime) == DatatypeConstants.GREATER) {
                nextRecomputeTime = includeNextRecomputeTime;
            }
        }
    }
    // Process own mappings
    List<ObjectTemplateMappingType> mappings = collectMappings(objectTemplateType);
    List<ObjectTemplateMappingType> sortedMappings = sortMappingsByDependencies(mappings);
    XMLGregorianCalendar templateNextRecomputeTime = collectTripleFromMappings(sortedMappings, phase, context, objectTemplateType, focusOdo, target, outputTripleMap, iteration, iterationToken, now, contextDesc, task, result);
    if (templateNextRecomputeTime != null) {
        if (nextRecomputeTime == null || nextRecomputeTime.compare(templateNextRecomputeTime) == DatatypeConstants.GREATER) {
            nextRecomputeTime = templateNextRecomputeTime;
        }
    }
    return nextRecomputeTime;
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)27 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)25 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)23 FocusType (com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType)22 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)18 PrismObject (com.evolveum.midpoint.prism.PrismObject)16 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)15 ArrayList (java.util.ArrayList)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)10 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)9 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)8 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)8 QName (javax.xml.namespace.QName)8 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)7 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)7 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)7 ActivationStatusType (com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType)7