use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType 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);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType 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;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType in project midpoint by Evolveum.
the class ObjectTemplateProcessor method collectItemDefinitionsFromTemplate.
private Map<ItemPath, ObjectTemplateItemDefinitionType> collectItemDefinitionsFromTemplate(ObjectTemplateType objectTemplateType, String contextDesc, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
Map<ItemPath, ObjectTemplateItemDefinitionType> definitions = new HashMap<>();
// Process includes (TODO refactor as a generic method)
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();
Map<ItemPath, ObjectTemplateItemDefinitionType> includedDefinitions = collectItemDefinitionsFromTemplate(includeObjectType, "include " + includeObject + " in " + objectTemplateType + " in " + contextDesc, task, result);
if (includedDefinitions != null) {
ItemPathUtil.putAllToMap(definitions, includedDefinitions);
}
}
// Process own definitions
for (ObjectTemplateItemDefinitionType def : objectTemplateType.getItem()) {
if (def.getRef() == null) {
throw new IllegalStateException("Item definition with null ref in " + contextDesc);
}
// TODO check for incompatible overrides
ItemPathUtil.putToMap(definitions, def.getRef().getItemPath(), def);
}
return definitions;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType in project midpoint by Evolveum.
the class ItemLimitationsChecker method checkItemsLimitations.
/**
* @pre Focus context is recomputed.
*/
<O extends ObjectType> void checkItemsLimitations(LensFocusContext<O> focusContext) throws SchemaException {
PathKeyedMap<ObjectTemplateItemDefinitionType> itemDefinitionsMap = focusContext.getItemDefinitionsMap();
PrismObject<O> objectNew = focusContext.getObjectNew();
if (objectNew == null) {
// nothing to check on DELETE operation
return;
}
for (Map.Entry<ItemPath, ObjectTemplateItemDefinitionType> entry : itemDefinitionsMap.entrySet()) {
for (PropertyLimitationsType limitation : entry.getValue().getLimitations()) {
if (!limitation.getLayer().contains(LayerType.MODEL)) {
// or should we apply SCHEMA-layer limitations as well?
continue;
}
checkItemLimitations(objectNew, entry.getKey(), limitation);
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType 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;
}
Aggregations