if (NotificationFunctionsImpl.isAmongHiddenPaths(itemDelta.getPath(), hiddenPaths)) { continue; body.append(":\n"); if (itemDelta.isAdd()) { for (PrismValue prismValue : itemDelta.getValuesToAdd()) { body.append(" --- ADD: "); body.append(prismValue.debugDump(2)); if (itemDelta.isDelete()) { for (PrismValue prismValue : itemDelta.getValuesToDelete()) { body.append(" --- DELETE: "); body.append(prismValue.debugDump(2)); if (itemDelta.isReplace()) { for (PrismValue prismValue : itemDelta.getValuesToReplace()) { body.append(" --- REPLACE: "); body.append(prismValue.debugDump(2));
/** * Deltas are equivalent if they have the same result when * applied to an object. I.e. meta-data and other "decorations" * such as old values are not considered in this comparison. */ public boolean equivalent(ItemDelta other) { if (elementName == null) { if (other.getElementName() != null) return false; } else if (!QNameUtil.match(elementName, elementName)) return false; if (parentPath == null) { if (other.getParentPath() != null) return false; } else if (!parentPath.equivalent(other.getParentPath())) return false; if (!equivalentSetRealValue(this.valuesToAdd, other.getValuesToAdd(), false)) return false; if (!equivalentSetRealValue(this.valuesToDelete, other.getValuesToDelete(), true)) return false; if (!equivalentSetRealValue(this.valuesToReplace, other.getValuesToReplace(), false)) return false; return true; }
@Override public String debugDump(int indent) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append(debugName()); sb.append("<").append(objectTypeClass.getSimpleName()).append(">("); sb.append(debugIdentifiers()).append(",").append(changeType); if (changeType == ChangeType.DELETE) { // Nothing to print for delete sb.append(")"); } else { sb.append("):\n"); if (objectToAdd == null) { if (changeType == ChangeType.ADD) { DebugUtil.indentDebugDump(sb, indent + 1); sb.append("null"); } } else { sb.append(objectToAdd.debugDump(indent + 1)); } Iterator<? extends ItemDelta> i = modifications.iterator(); while (i.hasNext()) { sb.append(i.next().debugDump(indent + 1)); if (i.hasNext()) { sb.append("\n"); } } } return sb.toString(); }
private void formatItemDeltaContent(StringBuilder sb, ItemDelta itemDelta, PrismObject objectOld, List<ItemPath> hiddenPaths, boolean showOperationalAttributes) { formatItemDeltaValues(sb, "ADD", itemDelta.getValuesToAdd(), false, itemDelta.getPath(), objectOld, hiddenPaths, showOperationalAttributes); formatItemDeltaValues(sb, "DELETE", itemDelta.getValuesToDelete(), true, itemDelta.getPath(), objectOld, hiddenPaths, showOperationalAttributes); formatItemDeltaValues(sb, "REPLACE", itemDelta.getValuesToReplace(), false, itemDelta.getPath(), objectOld, hiddenPaths, showOperationalAttributes); }
private String getItemDeltaLabel(ItemDelta itemDelta, PrismObjectDefinition objectDefinition) { return getItemPathLabel(itemDelta.getPath(), itemDelta.getDefinition(), objectDefinition); }
public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta, DeltaConversionOptions options) throws SchemaException { if (InternalsConfig.consistencyChecks) { delta.checkConsistence(); if (!delta.isEmpty() && delta.getPrismContext() == null) { throw new IllegalStateException("Non-empty ItemDelta with no prismContext cannot be converted to ItemDeltaType."); ItemPathType path = new ItemPathType(delta.getPath()); if (delta.getValuesToReplace() != null) { ItemDeltaType mod = new ItemDeltaType(); mod.setPath(path); mod.setModificationType(ModificationTypeType.REPLACE); try { addModValues(delta, mod, delta.getValuesToReplace(), options); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " while converting property " + delta.getElementName(), e); addOldValues(delta, mod, delta.getEstimatedOldValues(), options); mods.add(mod); if (delta.getValuesToAdd() != null) { ItemDeltaType mod = new ItemDeltaType(); mod.setPath(path); mod.setModificationType(ModificationTypeType.ADD); try { addModValues(delta, mod, delta.getValuesToAdd(), options); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " while converting property " + delta.getElementName(), e); addOldValues(delta, mod, delta.getEstimatedOldValues(), options);
public void applyAttributesDefinition(ProvisioningContext ctx, ObjectDelta<ShadowType> delta) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException { if (delta.isAdd()) { applyAttributesDefinition(ctx, delta.getObjectToAdd()); } else if (delta.isModify()) { for (ItemDelta<?, ?> itemDelta : delta.getModifications()) { if (SchemaConstants.PATH_ATTRIBUTES.equivalent(itemDelta.getParentPath())) { applyAttributeDefinition(ctx, delta, itemDelta); } else if (SchemaConstants.PATH_ATTRIBUTES.equivalent(itemDelta.getPath())) { if (itemDelta.isAdd()) { for (PrismValue value : itemDelta.getValuesToAdd()) { applyAttributeDefinition(ctx, value); } } if (itemDelta.isReplace()) { for (PrismValue value : itemDelta.getValuesToReplace()) { applyAttributeDefinition(ctx, value); } } } } } }
while (itemDeltaIterator.hasNext()) { ItemDelta<?, ?> itemDelta = itemDeltaIterator.next(); if (itemPath.equivalent(itemDelta.getPath())) { if (!fromMinusSet) { if (dryRun) { wasPresent = wasPresent || emptyIfNull(itemDelta.getValuesToAdd()).contains(value) || emptyIfNull(itemDelta.getValuesToReplace()).contains(value); } else { boolean removed1 = itemDelta.removeValueToAdd(value); boolean removed2 = itemDelta.removeValueToReplace(value); wasPresent = wasPresent || removed1 || removed2; if (itemDelta.getValuesToReplace() != null) { throw new UnsupportedOperationException("Couldn't subtract 'value to be deleted' from REPLACE itemDelta: " + itemDelta); wasPresent = wasPresent || emptyIfNull(itemDelta.getValuesToDelete()).contains(value); } else { wasPresent = wasPresent || itemDelta.removeValueToDelete(value); if (!dryRun && itemDelta.isInFactEmpty()) { itemDeltaIterator.remove();
Collection<ItemDelta> repoChanges = new ArrayList<>(); for (ItemDelta itemDelta : objectChange) { if (ShadowType.F_ATTRIBUTES.equivalent(itemDelta.getParentPath())) { QName attrName = itemDelta.getElementName(); if (objectClassDefinition.isSecondaryIdentifier(attrName)) { if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) { newName = ((PrismPropertyValue)itemDelta.getValuesToReplace().iterator().next()).getValue().toString(); } else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) { newName = ((PrismPropertyValue)itemDelta.getValuesToAdd().iterator().next()).getValue().toString(); continue; } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getParentPath())) { if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) { continue; } else if (ShadowType.F_ACTIVATION.equivalent(itemDelta.getPath())) { // should not occur, but for completeness... for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) { ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable()); ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable()); } else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) { addPasswordDelta(repoChanges, itemDelta, objectClassDefinition); continue;
Collection<V> replace = new ArrayList<>(); replace.add(LensUtil.cloneAndApplyMetadata(value, isAssignment, originMapping.getMappingType())); outputFocusItemDelta.setValuesToReplace(replace); outputFocusItemDelta.addValueToAdd(LensUtil.cloneAndApplyMetadata(value, isAssignment, originMapping.getMappingType())); if (!outputFocusItemDelta.isReplace()) { outputFocusItemDelta.addValueToDelete(value); if (diffDelta.isReplace()) { if (diffDelta.getValuesToReplace().isEmpty()) { diffDelta.resetValuesToReplace(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Removing empty replace part of the diff delta because mapping is tolerant:\n{}", diffDelta.debugDump()); LOGGER.trace( "Making sure that the replace part of the diff contains old values delta because mapping is tolerant:\n{}", diffDelta.debugDump()); if (!PrismValueCollectionsUtil.containsRealValue(diffDelta.getValuesToReplace(), shouldBeValue)) { diffDelta.addValueToReplace(shouldBeValue.clone()); diffDelta.resetValuesToDelete(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Removing delete part of the diff delta because mapping settings are tolerant={}, hasRange={}:\n{}", tolerant, hasRange, diffDelta.debugDump());
if (path.equivalent(modification.getPath())) { if (modification.isReplace()) { throw new UnsupportedOperationException("Cannot factor out values for replace item delta. Path = " + path + ", modification = " + modification); for (PrismValue prismValue : emptyIfNull(modification.getValuesToAdd())) { createNewDelta(rv, modification).addValueToAdd(prismValue.clone()); for (PrismValue prismValue : emptyIfNull(modification.getValuesToDelete())) { createNewDelta(rv, modification).addValueToDelete(prismValue.clone()); } else if (path.isSubPath(modification.getPath())) { ItemPath remainingPath = modification.getPath().remainder(path); Long id = remainingPath.firstToIdOrNull(); modificationsForId.put(id, modification);
if (aprioriItemDelta != null && !aprioriItemDelta.isEmpty()) { continue; mapping, aprioriItemDelta, mapping.isSourceless()); } else if (mapping.getStrength() == MappingStrengthType.WEAK) { if (itemNew != null && !itemNew.isEmpty() || itemDelta.addsAnyValue()) { continue; if (itemNew == null || !itemNew.contains(valueFromZeroSet, EquivalenceStrategy.REAL_VALUE)) { LOGGER.trace("Reconciliation will add value {} for item {}. Existing item: {}", valueFromZeroSet, itemPath, itemNew); itemDelta.addValuesToAdd(LensUtil.cloneAndApplyMetadata(valueFromZeroSet, isAssignment, mapping)); if (itemDelta.isDelete()) { LOGGER.trace("Non-tolerant item with values to DELETE => removing them"); itemDelta.resetValuesToDelete(); // these are useless now - we move everything to REPLACE if (itemDelta.isReplace()) { LOGGER.trace("Non-tolerant item with resulting REPLACE delta => doing nothing"); } else { for (ItemValueWithOrigin<?,?> zeroSetIvwo: zeroSet) { itemDelta.addValuesToAdd(LensUtil.cloneAndApplyMetadata(zeroSetIvwo.getItemValue(), isAssignment, zeroSetIvwo.getMapping())); itemDelta.addToReplaceDelta(); LOGGER.trace("Non-tolerant item with resulting ADD delta => converted ADD to REPLACE values: {}", itemDelta.getValuesToReplace()); if (itemDelta.isRedundant(targetObject)) { LOGGER.trace("Computed item delta is redundant => skipping it. Delta = \n{}", itemDelta.debugDump()); continue;
if (deltaToMerge.isEmpty()) { return; if (deltaToMerge.getValuesToReplace() != null) { mergeValuesToReplace(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToReplace())); } else { if (deltaToMerge.getValuesToAdd() != null) { mergeValuesToAdd(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToAdd())); if (deltaToMerge.getValuesToDelete() != null) { mergeValuesToDelete(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToDelete())); if (deltaToMerge.getEstimatedOldValues() != null) { mergeOldValues(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getEstimatedOldValues()));
assertNull(focusPrimaryDelta.getObjectToAdd()); for (ItemDelta itemMod : focusPrimaryDelta.getModifications()) { if (itemMod.getValuesToDelete() != null) { Item property = focusOld.findItem(itemMod.getPath()); assertNotNull("Deleted item " + itemMod.getParentPath() + "/" + itemMod.getElementName() + " not found in focus", property); for (Object valueToDelete : itemMod.getValuesToDelete()) { if (!property.contains((PrismValue) valueToDelete, EquivalenceStrategy.REAL_VALUE)) { display("Deleted value " + valueToDelete + " is not in focus item " + itemMod.getParentPath() + "/" + itemMod.getElementName()); display("Deleted value", valueToDelete); display("HASHCODE: " + valueToDelete.hashCode()); display("HASHCODE: " + value.hashCode()); fail("Deleted value " + valueToDelete + " is not in focus item " + itemMod.getParentPath() + "/" + itemMod.getElementName());
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition(); for (ItemDelta itemDelta : objectChange) { if (isAttributeDelta(itemDelta) || SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) { if (itemDelta instanceof PropertyDelta) { PropertyModificationOperation attributeModification = new PropertyModificationOperation( (PropertyDelta) itemDelta); RefinedAttributeDefinition<Object> attrDef = objectClassDefinition.findAttributeDefinition(itemDelta.getElementName()); if (attrDef != null) { attributeModification.setMatchingRuleQName(attrDef.getMatchingRuleQName()); if (itemDelta.getDefinition() == null) { itemDelta.setDefinition(attrDef); throw new UnsupportedOperationException("Not supported delta: " + itemDelta); } else if (SchemaConstants.PATH_ACTIVATION.equivalent(itemDelta.getParentPath())) { if (!activationProcessed) { Collection<Operation> activationOperations = determineActivationChange(ctx, shadow.asObjectable(), objectChange, result); } else if (ShadowType.F_ASSOCIATION.equivalent(itemDelta.getPath())) { if (itemDelta instanceof ContainerDelta) { entitlementConverter.collectEntitlementChange(ctx, (ContainerDelta<ShadowAssociationType>)itemDelta, operations); throw new UnsupportedOperationException("Not supported delta: " + itemDelta); } else if (ShadowType.F_AUXILIARY_OBJECT_CLASS.equivalent(itemDelta.getPath())) { if (itemDelta instanceof PropertyDelta) { PropertyModificationOperation attributeModification = new PropertyModificationOperation(
PrismIdentifierGenerator idGenerator) { if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) { processAnyExtensionDeltaValues(delta.getValuesToReplace(), object, objectOwnerType, assignmentExtension, assignmentExtensionType, (existing, fromDelta) -> { ItemDefinition def = delta.getDefinition(); Collection<RAnyValue> filtered = filterRAnyValues(existing, def, objectOwnerType, assignmentExtensionType); processAnyExtensionDeltaValues(delta.getValuesToDelete(), object, objectOwnerType, assignmentExtension, assignmentExtensionType, (existing, fromDelta) -> { Collection filtered = fromDelta.stream().map(i -> i.getRepository()).collect(Collectors.toList()); processAnyExtensionDeltaValues(delta.getValuesToAdd(), object, objectOwnerType, assignmentExtension, assignmentExtensionType, (existing, fromDelta) -> markNewOnesTransientAndAddToExisting(existing, (Collection) fromDelta, idGenerator));
public static void clearCacheForDelta(Collection<? extends ItemDelta> modifications) { if (modifications == null) { return; } for (ItemDelta itemDelta : modifications) { if (ObjectType.F_NAME.equivalent(itemDelta.getPath())) { clearCacheForValues(itemDelta.getValuesToAdd()); // these may present a conflict clearCacheForValues(itemDelta.getValuesToReplace()); // so do these } } }
@SuppressWarnings("unchecked") private <V extends PrismValue, D extends ItemDefinition> SceneDeltaItemImpl createSceneDeltaItemCommon(ItemDelta<V, D> itemDelta, SceneImpl owningScene) throws SchemaException { String simpleName = itemDelta.getElementName() != null ? itemDelta.getElementName().getLocalPart() : ""; NameImpl name = new NameImpl(simpleName); if (itemDelta.getDefinition() != null) { name.setDisplayName(itemDelta.getDefinition().getDisplayName()); } name.setId(simpleName); name.setNamesAreResourceKeys(true); SceneDeltaItemImpl si = new SceneDeltaItemImpl(name); si.setSourceDelta(itemDelta); D def = itemDelta.getDefinition(); if (def != null) { Item<V,D> item = def.instantiate(); if (itemDelta.getEstimatedOldValues() != null) { item.addAll(CloneUtil.cloneCollectionMembers(itemDelta.getEstimatedOldValues())); } si.setSourceItem(item); si.setOperational(def.isOperational()); } ItemPath remainder = itemDelta.getPath().remainder(owningScene.getSourceRelPath()); if (remainder.startsWithNullId()) { remainder = remainder.rest(); } si.setSourceRelPath(remainder); return si; }
private <T> void normalizeDelta(ItemDelta<PrismPropertyValue<T>,PrismPropertyDefinition<T>> delta, RefinedAttributeDefinition rAttrDef) throws SchemaException{ MatchingRule<T> matchingRule = matchingRuleRegistry.getMatchingRule(rAttrDef.getMatchingRuleQName(), rAttrDef.getTypeName()); if (matchingRule != null) { if (delta.getValuesToReplace() != null){ normalizeValues(delta.getValuesToReplace(), matchingRule); } if (delta.getValuesToAdd() != null){ normalizeValues(delta.getValuesToAdd(), matchingRule); } if (delta.getValuesToDelete() != null){ normalizeValues(delta.getValuesToDelete(), matchingRule); } } }