Search in sources :

Example 1 with ObjectTemplateType

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

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

the class ObjectPolicyPanel method createObjectTemplateList.

protected IModel<List<ObjectTemplateConfigTypeReferenceDto>> createObjectTemplateList() {
    return new AbstractReadOnlyModel<List<ObjectTemplateConfigTypeReferenceDto>>() {

        @Override
        public List<ObjectTemplateConfigTypeReferenceDto> getObject() {
            List<PrismObject<ObjectTemplateType>> templateList = null;
            List<ObjectTemplateConfigTypeReferenceDto> list = new ArrayList<>();
            OperationResult result = new OperationResult(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
            Task task = getPageBase().createSimpleTask(OPERATION_LOAD_ALL_OBJECT_TEMPLATES);
            try {
                templateList = getPageBase().getModelService().searchObjects(ObjectTemplateType.class, new ObjectQuery(), null, task, result);
                result.recomputeStatus();
            } catch (Exception e) {
                result.recordFatalError("Could not get list of object templates", e);
                LoggingUtils.logUnexpectedException(LOGGER, "Could not get list of object templates", e);
            // TODO - show this error in GUI
            }
            if (templateList != null) {
                ObjectTemplateType template;
                for (PrismObject<ObjectTemplateType> obj : templateList) {
                    template = obj.asObjectable();
                    list.add(new ObjectTemplateConfigTypeReferenceDto(template.getOid(), WebComponentUtil.getName(template)));
                }
            }
            return list;
        }
    };
}
Also used : AbstractReadOnlyModel(org.apache.wicket.model.AbstractReadOnlyModel) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectTemplateConfigTypeReferenceDto(com.evolveum.midpoint.web.page.admin.configuration.dto.ObjectTemplateConfigTypeReferenceDto) Task(com.evolveum.midpoint.task.api.Task) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 3 with ObjectTemplateType

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

the class ObjectTemplateProcessor method processTemplate.

/**
	 * Process focus template: application of object template where focus is both source and target. 
	 */
public <F extends FocusType> void processTemplate(LensContext<F> context, ObjectTemplateMappingEvaluationPhaseType phase, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ObjectAlreadyExistsException {
    LensFocusContext<F> focusContext = context.getFocusContext();
    if (focusContext.isDelete()) {
        LOGGER.trace("Skipping processing of object template: focus delete");
        return;
    }
    ObjectTemplateType objectTemplate = context.getFocusTemplate();
    if (objectTemplate == null) {
        // No applicable template
        LOGGER.trace("Skipping processing of object template: no object template");
        return;
    }
    int iteration = focusContext.getIteration();
    String iterationToken = focusContext.getIterationToken();
    ObjectDeltaObject<F> focusOdo = focusContext.getObjectDeltaObject();
    PrismObjectDefinition<F> focusDefinition = getObjectDefinition(focusContext.getObjectTypeClass());
    LOGGER.trace("Applying {} to {}, iteration {} ({}), phase {}", objectTemplate, focusContext.getObjectNew(), iteration, iterationToken, phase);
    Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap = new HashMap<>();
    Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap = collectItemDefinitionsFromTemplate(objectTemplate, objectTemplate.toString(), task, result);
    XMLGregorianCalendar nextRecomputeTime = collectTripleFromTemplate(context, objectTemplate, phase, focusOdo, focusOdo.getNewObject(), outputTripleMap, iteration, iterationToken, now, objectTemplate.toString(), task, result);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("outputTripleMap before item delta computation:\n{}", DebugUtil.debugDumpMapMultiLine(outputTripleMap));
    }
    String contextDesc = "object template " + objectTemplate + " for focus " + focusOdo.getAnyObject();
    Collection<ItemDelta<?, ?>> itemDeltas = computeItemDeltas(outputTripleMap, itemDefinitionsMap, focusOdo.getObjectDelta(), focusOdo.getNewObject(), focusDefinition, contextDesc);
    focusContext.applyProjectionWaveSecondaryDeltas(itemDeltas);
    if (nextRecomputeTime != null) {
        boolean alreadyHasTrigger = false;
        PrismObject<F> objectCurrent = focusContext.getObjectCurrent();
        if (objectCurrent != null) {
            for (TriggerType trigger : objectCurrent.asObjectable().getTrigger()) {
                if (RecomputeTriggerHandler.HANDLER_URI.equals(trigger.getHandlerUri()) && nextRecomputeTime.equals(trigger.getTimestamp())) {
                    alreadyHasTrigger = true;
                    break;
                }
            }
        }
        if (!alreadyHasTrigger) {
            PrismObjectDefinition<F> objectDefinition = focusContext.getObjectDefinition();
            PrismContainerDefinition<TriggerType> triggerContDef = objectDefinition.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);
            focusContext.swallowToProjectionWaveSecondaryDelta(triggerDelta);
        }
    }
}
Also used : TriggerType(com.evolveum.midpoint.xml.ns._public.common.common_3.TriggerType) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) HashMap(java.util.HashMap) ObjectTemplateItemDefinitionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) ItemValueWithOrigin(com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 4 with ObjectTemplateType

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

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

Aggregations

ObjectTemplateType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)15 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)4 ObjectTemplateMappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateMappingType)4 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)3 ObjectPolicyConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectPolicyConfigurationType)3 ObjectTemplateItemDefinitionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType)3 ArrayList (java.util.ArrayList)3 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)3 ItemValueWithOrigin (com.evolveum.midpoint.model.impl.lens.ItemValueWithOrigin)2 PrismObject (com.evolveum.midpoint.prism.PrismObject)2 DeltaSetTriple (com.evolveum.midpoint.prism.delta.DeltaSetTriple)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 Task (com.evolveum.midpoint.task.api.Task)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 HashMap (java.util.HashMap)2 MainObjectListPanel (com.evolveum.midpoint.gui.api.component.MainObjectListPanel)1 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)1 PrismContext (com.evolveum.midpoint.prism.PrismContext)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1