List of usage examples for javax.xml.datatype XMLGregorianCalendar equals
@Override public boolean equals(Object obj)
From source file:com.evolveum.midpoint.model.impl.lens.projector.ObjectTemplateProcessor.java
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;/* www . j a v a 2 s. c o m*/ } 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, 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, 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); } } }
From source file:com.evolveum.midpoint.model.impl.lens.projector.focus.ObjectTemplateProcessor.java
/** * Process focus template: application of object template where focus is both source and target. *//*from www .j a va2 s.co m*/ public <F extends FocusType> void processTemplate(LensContext<F> context, ObjectTemplateMappingEvaluationPhaseType phase, XMLGregorianCalendar now, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ObjectAlreadyExistsException, SecurityViolationException, ConfigurationException, CommunicationException { LensFocusContext<F> focusContext = context.getFocusContext(); if (focusContext.isDelete()) { LOGGER.trace("Skipping processing of object template: focus delete"); return; } ObjectTemplateType objectTemplate = context.getFocusTemplate(); String objectTemplateDesc = "(no template)"; if (objectTemplate != null) { objectTemplateDesc = objectTemplate.toString(); } int iteration = focusContext.getIteration(); String iterationToken = focusContext.getIterationToken(); ObjectDeltaObject<F> focusOdo = focusContext.getObjectDeltaObject(); PrismObjectDefinition<F> focusDefinition = getObjectDefinition(focusContext.getObjectTypeClass()); LOGGER.trace("Applying object template {} to {}, iteration {} ({}), phase {}", objectTemplate, focusContext.getObjectNew(), iteration, iterationToken, phase); Map<ItemPath, ObjectTemplateItemDefinitionType> itemDefinitionsMap = collectItemDefinitionsFromTemplate( objectTemplate, objectTemplateDesc, task, result); focusContext.setItemDefinitionsMap(itemDefinitionsMap); List<FocalMappingSpec> mappings = new ArrayList<>(); collectMappingsFromTemplate(context, mappings, objectTemplate, objectTemplateDesc, task, result); collectAutoassignMappings(context, mappings, task, result); Map<ItemPath, DeltaSetTriple<? extends ItemValueWithOrigin<?, ?>>> outputTripleMap = new HashMap<>(); XMLGregorianCalendar nextRecomputeTime = collectTripleFromMappings(context, mappings, phase, focusOdo, focusOdo.getNewObject(), outputTripleMap, iteration, iterationToken, now, task, result); if (LOGGER.isTraceEnabled()) { LOGGER.trace("outputTripleMap before item delta computation:\n{}", DebugUtil.debugDumpMapMultiLine(outputTripleMap)); } String contextDesc = "object template " + objectTemplateDesc + " 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); } } }
From source file:com.evolveum.midpoint.model.impl.lens.projector.MappingEvaluationHelper.java
/** * strongMappingWasUsed: Returns true here if the value was (at least partly) determined by a strong mapping. * Used to know whether (when doing reconciliation) this value should be forcibly put onto the resource, even * if it was not changed (i.e. if it's only in the zero set). *///from w ww. j a v a 2 s . c om // public <V extends PrismValue, F extends FocusType, O extends ObjectType> void evaluateMappingSetProjection( // Collection<MappingType> mappingTypes, String mappingDesc, // XMLGregorianCalendar now, MappingInitializer<V> initializer, MappingOutputProcessor<V> processor, // Item<V> aPrioriValue, ItemDelta<V> aPrioriDelta, PrismObject<? extends ObjectType> aPrioriObject, // Boolean evaluateCurrent, MutableBoolean strongMappingWasUsed, // LensContext<F> context, LensElementContext<O> targetContext, // Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException { public <V extends PrismValue, T extends ObjectType, F extends FocusType> void evaluateMappingSetProjection( MappingEvaluatorHelperParams<V, T, F> params, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException { 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>> mappings = new ArrayList<Mapping<V>>(mappingTypes.size()); for (MappingType mappingType : mappingTypes) { Mapping<V> mapping = mappingFactory.createMapping(mappingType, mappingDesc); if (!mapping.isApplicableToChannel(params.getContext().getChannel())) { continue; } mapping.setNow(params.getNow()); if (defaultTargetItemPath != null && targetObjectDefinition != null) { ItemDefinition defaultTargetItemDef = targetObjectDefinition .findItemDefinition(defaultTargetItemPath); mapping.setDefaultTargetDefinition(defaultTargetItemDef); mapping.setDefaultTargetPath(defaultTargetItemPath); } else { mapping.setDefaultTargetDefinition(params.getTargetItemDefinition()); mapping.setDefaultTargetPath(defaultTargetItemPath); } mapping.setTargetContext(targetObjectDefinition); // Initialize mapping (using Inversion of Control) params.getInitializer().initialize(mapping); Boolean timeConstraintValid = mapping.evaluateTimeConstraintValid(result); if (params.getEvaluateCurrent() != null) { if (params.getEvaluateCurrent() && !timeConstraintValid) { continue; } if (!params.getEvaluateCurrent() && timeConstraintValid) { continue; } } mappings.add(mapping); } for (Mapping<V> 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<PrismValue> aPrioriItemDelta = params.getAPrioriTargetDelta() .findItemDelta(mappingOutputPath); if (mapping.getStrength() != MappingStrengthType.STRONG) { if (aPrioriItemDelta != null && !aPrioriItemDelta.isEmpty()) { continue; } } } LensUtil.evaluateMapping(mapping, params.getContext(), task, result); PrismValueDeltaSetTriple<V> mappingOutputTriple = mapping.getOutputTriple(); 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); } PrismValueDeltaSetTriple<V> outputTriple = mappingOutputStruct.getOutputTriple(); if (outputTriple == null) { mappingOutputStruct.setOutputTriple(mappingOutputTriple); } else { outputTriple.merge(mappingOutputTriple); } } } // Second pass, evaluate only weak mappings for (Mapping<V> mapping : mappings) { 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(); Item<?> aPrioriTargetItem = null; PrismObject<T> aPrioriTargetObject = params.getAPrioriTargetObject(); if (aPrioriTargetObject != null && mappingOutputPath != null) { aPrioriTargetItem = aPrioriTargetObject.findItem(mappingOutputPath); } if ((aPrioriTargetItem == null || aPrioriTargetItem.isEmpty()) && outputTriple == null) { if (mapping.getStrength() != MappingStrengthType.WEAK) { continue; } LensUtil.evaluateMapping(mapping, params.getContext(), task, result); PrismValueDeltaSetTriple<V> mappingOutputTriple = mapping.getOutputTriple(); if (mappingOutputTriple != null) { 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(); if (processor != null) { processor.process(mappingOutputPath, outputTriple); } else { 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> targetItemDelta = targetItemDefinition.createEmptyDelta(mappingOutputPath); Item<V> aPrioriTargetItem = null; PrismObject<T> aPrioriTargetObject = params.getAPrioriTargetObject(); if (aPrioriTargetObject != null) { aPrioriTargetItem = (Item<V>) 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 (params.hasFullTargetObject() && mappingOutputStruct.isStrongMappingWasUsed()) { valuesToReplace = outputTriple.getNonNegativeValues(); } else { valuesToReplace = outputTriple.getPlusSet(); } if (valuesToReplace != null && !valuesToReplace.isEmpty()) { // if what we want to set is the same as is already in the shadow, we skip that // (we insist on having full shadow, to be sure we work with current data) if (params.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)); } } if (targetItemDelta.isEmpty()) { continue; } LOGGER.trace("{} adding new delta for {}: {}", new Object[] { mappingDesc, targetContext, targetItemDelta }); targetContext.swallowToSecondaryDelta(targetItemDelta); } } // Figure out recompute time for (Mapping<V> 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); } } }