Search in sources :

Example 1 with ObjectTemplateMappingType

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

the class TestParseObjectTemplate method assertObjectTemplateInternals.

// checks raw values of mappings
// should be called only on reparsed values in order to catch some raw-data-related serialization issues (MID-2196)
private void assertObjectTemplateInternals(PrismObject<ObjectTemplateType> object, QName elementName) throws SchemaException {
    int assignmentValuesFound = 0;
    for (ObjectTemplateMappingType mappingType : object.asObjectable().getMapping()) {
        if (mappingType.getExpression() != null) {
            if (mappingType.getTarget() != null && mappingType.getTarget().getPath() != null && new ItemPath(UserType.F_ASSIGNMENT).equivalent(mappingType.getTarget().getPath().getItemPath())) {
                ItemDefinition assignmentDef = PrismTestUtil.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class).findItemDefinition(UserType.F_ASSIGNMENT);
                for (JAXBElement evaluator : mappingType.getExpression().getExpressionEvaluator()) {
                    if (evaluator.getValue() instanceof RawType) {
                        RawType rawType = (RawType) evaluator.getValue();
                        Item assignment = rawType.getParsedItem(assignmentDef);
                        System.out.println("assignment:\n" + assignment.debugDump());
                        assignmentValuesFound++;
                    }
                }
            }
        }
    }
    assertEquals("wrong # of assignment values found in mapping", 2, assignmentValuesFound);
}
Also used : ObjectTemplateMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType) JAXBElement(javax.xml.bind.JAXBElement) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 2 with ObjectTemplateMappingType

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

the class ObjectTemplateProcessor method getUpdatedFocusOdo.

private <F extends FocusType> ObjectDeltaObject<F> getUpdatedFocusOdo(LensContext<F> context, ObjectDeltaObject<F> focusOdo, Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap, ObjectTemplateMappingType mappingType, String contextDesc) throws ExpressionEvaluationException, PolicyViolationException, SchemaException {
    ObjectDeltaObject<F> focusOdoCloned = null;
    for (VariableBindingDefinitionType source : mappingType.getSource()) {
        if (source.getPath() == null) {
            continue;
        }
        ItemPath path = stripFocusVariableSegment(source.getPath().getItemPath());
        if (path.startsWithVariable()) {
            continue;
        }
        DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>> triple = DeltaSetTriple.find(outputTripleMap, path);
        if (triple == null) {
            continue;
        }
        if (focusOdoCloned == null) {
            LOGGER.trace("Cloning and updating focusOdo because of chained mappings; chained source path: {}", path);
            focusOdoCloned = focusOdo.clone();
        } else {
            LOGGER.trace("Updating focusOdo because of chained mappings; chained source path: {}", path);
        }
        Class<F> focusClass = context.getFocusContext().getObjectTypeClass();
        ItemDefinition<?> itemDefinition = getObjectDefinition(focusClass).findItemDefinition(path);
        // TODO not much sure about the parameters
        ItemDelta itemDelta = LensUtil.consolidateTripleToDelta(path, (DeltaSetTriple) triple, itemDefinition, getAprioriItemDelta(focusOdo.getObjectDelta(), path), focusOdo.getNewObject(), null, null, true, true, false, " updating chained source (" + path + ") in " + contextDesc, true);
        LOGGER.trace("Updating focus ODO with delta:\n{}", itemDelta.debugDumpLazily());
        focusOdoCloned.update(itemDelta);
    }
    return focusOdoCloned != null ? focusOdoCloned : focusOdo;
}
Also used : VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with ObjectTemplateMappingType

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

the class ObjectTemplateProcessor method collectTripleFromMappings.

private <V extends PrismValue, D extends ItemDefinition, F extends FocusType, T extends FocusType> XMLGregorianCalendar collectTripleFromMappings(Collection<ObjectTemplateMappingType> mappings, ObjectTemplateMappingEvaluationPhaseType phase, LensContext<F> context, ObjectTemplateType objectTemplateType, 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 {
    XMLGregorianCalendar nextRecomputeTime = null;
    for (ObjectTemplateMappingType mappingType : mappings) {
        ObjectTemplateMappingEvaluationPhaseType mappingPhase = mappingType.getEvaluationPhase();
        if (mappingPhase == null) {
            mappingPhase = ObjectTemplateMappingEvaluationPhaseType.BEFORE_ASSIGNMENTS;
        }
        if (phase != null && mappingPhase != phase) {
            continue;
        }
        LOGGER.trace("Starting evaluation of mapping '{}' in {}", mappingType.getName(), contextDesc);
        // for mapping chaining
        ObjectDeltaObject<F> updatedFocusOdo = getUpdatedFocusOdo(context, focusOdo, outputTripleMap, mappingType, contextDesc);
        Mapping<V, D> mapping = mappingEvaluator.createFocusMapping(mappingFactory, context, mappingType, objectTemplateType, updatedFocusOdo, target, null, iteration, iterationToken, context.getSystemConfiguration(), now, contextDesc, task, result);
        if (mapping == null) {
            continue;
        }
        Boolean timeConstraintValid = mapping.evaluateTimeConstraintValid(task, result);
        if (timeConstraintValid != null && !timeConstraintValid) {
            // Delayed mapping. Just schedule recompute time
            XMLGregorianCalendar mappingNextRecomputeTime = mapping.getNextRecomputeTime();
            LOGGER.trace("Evaluation of mapping {} delayed to {}", mapping, mappingNextRecomputeTime);
            if (mappingNextRecomputeTime != null) {
                if (nextRecomputeTime == null || nextRecomputeTime.compare(mappingNextRecomputeTime) == DatatypeConstants.GREATER) {
                    nextRecomputeTime = mappingNextRecomputeTime;
                }
            }
            continue;
        }
        mappingEvaluator.evaluateMapping(mapping, context, task, result);
        ItemPath itemPath = mapping.getOutputPath();
        if (itemPath == null) {
            continue;
        }
        DeltaSetTriple<ItemValueWithOrigin<V, D>> outputTriple = ItemValueWithOrigin.createOutputTriple(mapping);
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Output triple for {}:\n{}", mapping, DebugUtil.debugDump(outputTriple));
        }
        if (outputTriple == null) {
            continue;
        }
        DeltaSetTriple<ItemValueWithOrigin<V, D>> mapTriple = (DeltaSetTriple<ItemValueWithOrigin<V, D>>) outputTripleMap.get(itemPath);
        if (mapTriple == null) {
            outputTripleMap.put(itemPath, outputTriple);
        } else {
            mapTriple.merge(outputTriple);
        }
    }
    return nextRecomputeTime;
}
Also used : DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ObjectTemplateMappingEvaluationPhaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingEvaluationPhaseType) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ObjectTemplateMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with ObjectTemplateMappingType

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

the class ObjectTemplateProcessor method collectMappings.

private List<ObjectTemplateMappingType> collectMappings(ObjectTemplateType objectTemplateType) {
    List<ObjectTemplateMappingType> mappings = new ArrayList<ObjectTemplateMappingType>();
    mappings.addAll(objectTemplateType.getMapping());
    for (ObjectTemplateItemDefinitionType templateItemDefType : objectTemplateType.getItem()) {
        for (ObjectTemplateMappingType mapping : templateItemDefType.getMapping()) {
            VariableBindingDefinitionType target = mapping.getTarget();
            if (target == null) {
                target = new VariableBindingDefinitionType();
                target.setPath(templateItemDefType.getRef());
                mapping.setTarget(target);
            } else if (target.getPath() == null) {
                target = target.clone();
                target.setPath(templateItemDefType.getRef());
                mapping.setTarget(target);
            }
            mappings.add(mapping);
        }
    }
    return mappings;
}
Also used : VariableBindingDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType) ObjectTemplateMappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType) ArrayList(java.util.ArrayList) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType)

Example 5 with ObjectTemplateMappingType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType 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

ObjectTemplateMappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 VariableBindingDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.VariableBindingDefinitionType)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)1 DeltaSetTriple (com.evolveum.midpoint.prism.delta.DeltaSetTriple)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectTemplateItemDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType)1 ObjectTemplateMappingEvaluationPhaseType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingEvaluationPhaseType)1 ObjectTemplateType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)1 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1 ArrayList (java.util.ArrayList)1 JAXBElement (javax.xml.bind.JAXBElement)1