public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoDelete(String message, ItemDelta<IV,ID> delta) { assertNoSet(message, "delete", delta.getValuesToDelete()); }
static void applyVisitorToValues(Collection<? extends PrismValue> values, ItemDelta<?,?> delta, Visitor visitor) { Collection<? extends PrismValue> valuesToDelete = delta.getValuesToDelete(); if (valuesToDelete == null) { valuesToDelete = new ArrayList<>(0); // just to simplify the code below } if (values != null) { for (PrismValue pval : values) { boolean isToBeDeleted = valuesToDelete.contains(pval); pval.accept(visitor); if (!isToBeDeleted && valuesToDelete.contains(pval)) { // value becomes 'to be deleted' -> we remove it from toBeDeleted list delta.removeValueToDelete(pval); } } } }
/** * Limitations: * (1) For DELETE object delta, we don't know what values were in the object's item. * (2) For REPLACE item delta, we don't know what values were in the object's item (but these deltas are quite rare * for multivalued items; and eventually there will be normalized into ADD+DELETE form) * (3) For DELETE item delta for PrismContainers, content of items deleted might not be known * (only ID could be provided on PCVs). */ @SuppressWarnings("unused") // used from scripts public List<PrismValue> getDeletedValuesFor(ItemPath itemPath) { if (isAdd()) { return Collections.emptyList(); } else if (isDelete()) { return Collections.emptyList(); } else { ItemDelta itemDelta = ItemDeltaCollectionsUtil.findItemDelta(modifications, itemPath, ItemDelta.class, false); if (itemDelta != null) { if (itemDelta.getValuesToDelete() != null) { return (List<PrismValue>) itemDelta.getValuesToDelete(); } else { return Collections.emptyList(); } } else { return Collections.emptyList(); } } }
if (delta.getValuesToDelete() != null) { for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToDelete()) { String oid = val.getOid(); if (existingOids.contains(oid)) { // if it's not there, we do not want to delete it!
for (PrismValue prismValue : itemDelta.getValuesToDelete()) { body.append(" --- DELETE: "); body.append(prismValue.debugDump(2));
wasPresent = wasPresent || emptyIfNull(itemDelta.getValuesToDelete()).contains(value); } else { wasPresent = wasPresent || itemDelta.removeValueToDelete(value);
private <T> boolean isToBeDeleted(ItemDelta existingDelta, ValueMatcher valueMatcher, T value) { LOGGER.trace("Checking existence for DELETE of value {} in existing delta: {}", value, existingDelta); if (existingDelta == null) { return false; } if (existingDelta.getValuesToDelete() == null){ return false; } for (Object isInDeltaValue : existingDelta.getValuesToDelete()) { if (isInDeltaValue instanceof PrismPropertyValue){ PrismPropertyValue isInRealValue = (PrismPropertyValue) isInDeltaValue; if (matchValue(isInRealValue.getValue(), value, valueMatcher)) { LOGGER.trace("Skipping adding value {} to delta for DELETE because it's already there", value); return true; } } else if (isInDeltaValue instanceof PrismContainerValue) { PrismContainerValue isInRealValue = (PrismContainerValue) isInDeltaValue; if (matchValue(isInRealValue.asContainerable(), value, valueMatcher)){ LOGGER.trace("Skipping adding value {} to delta for DELETE because it's already there", value); return true; } } //TODO: reference delta??? } return false; }
processAnyExtensionDeltaValues(delta.getValuesToDelete(), object, objectOwnerType, assignmentExtension, assignmentExtensionType, (existing, fromDelta) -> { Collection filtered = fromDelta.stream().map(i -> i.getRepository()).collect(Collectors.toList());
delta.resetValuesToAdd(); if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) { deltaIterator.remove();
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); } } }
ItemDelta<PrismValue, ItemDefinition> targetItemDelta = delta.findItemDelta(path); if (targetItemDelta != null) { rv.removeAll(emptyIfNull(targetItemDelta.getValuesToDelete()));
delta.resetValuesToAdd(); if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) { deltaIterator.remove();
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); }
/** * Returns true if the other delta is a complete subset of this delta. * I.e. if all the statements of the other delta are already contained * in this delta. As a consequence it also returns true if the two * deltas are equal. */ public boolean contains(ItemDelta<V,D> other, EquivalenceStrategy strategy) { if (!this.getPath().equivalent(other.getPath())) { return false; } if (!PrismValueCollectionsUtil.containsAll(this.valuesToAdd, other.getValuesToAdd(), strategy)) { return false; } if (!PrismValueCollectionsUtil.containsAll(this.valuesToDelete, other.getValuesToDelete(), strategy)) { return false; } if (!PrismValueCollectionsUtil.containsAll(this.valuesToReplace, other.getValuesToReplace(), strategy)) { return false; } return true; }
private void handleOneToMany(Collection collection, ItemDelta delta, Attribute attribute, Object bean, PrismObject prismObject, PrismIdentifierGenerator idGenerator) { Class outputType = getRealOutputType(attribute); Item item = prismObject.findItem(delta.getPath()); // handle replace if (delta.isReplace()) { Collection<PrismEntityPair<?>> valuesToReplace = processDeltaValues(delta.getValuesToReplace(), outputType, delta, bean); replaceValues(collection, valuesToReplace, item, idGenerator); return; } // handle add if (delta.isAdd()) { Collection<PrismEntityPair<?>> valuesToAdd = processDeltaValues(delta.getValuesToAdd(), outputType, delta, bean); addValues(collection, valuesToAdd, idGenerator); } // handle delete if (delta.isDelete()) { Collection<PrismEntityPair<?>> valuesToDelete = processDeltaValues(delta.getValuesToDelete(), outputType, delta, bean); valuesToDelete.stream().forEach(pair -> { if (pair.getRepository() instanceof EntityState) { ((EntityState) pair.getRepository()).setTransient(false); } }); deleteValues(collection, valuesToDelete, item); } }
mergeValuesToAdd(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToAdd())); if (deltaToMerge.getValuesToDelete() != null) { mergeValuesToDelete(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToDelete()));
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());
private boolean containsItem(ItemDelta itemDelta, ItemPath itemPath) { ItemPath namesOnlyPathTested = itemPath.namedSegmentsOnly(); ItemPath namesOnlyPathInDelta = itemDelta.getPath().namedSegmentsOnly(); if (namesOnlyPathTested.isSubPathOrEquivalent(namesOnlyPathInDelta)) { return true; } // however, we can add/delete whole container (containing part of the path) // e.g. we can test for activation/administrativeStatus, and the delta is: // ADD activation VALUE (administrativeStatus=ENABLED) if (!namesOnlyPathInDelta.isSubPath(namesOnlyPathTested)) { return false; } // for ADD values we know // for REPLACE values we know - for values being added, but NOT for values being left behind // for DELETE we have a problem if we are deleting "by ID" - we just don't know if the value being deleted contains the path in question or not ItemPath remainder = namesOnlyPathTested.remainder(namesOnlyPathInDelta); return containsItemInValues(itemDelta.getValuesToAdd(), remainder) || containsItemInValues(itemDelta.getValuesToReplace(), remainder) || containsItemInValues(itemDelta.getValuesToDelete(), remainder); }
/** * 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; }
assertEquals("Wrong # of assignments to add in offspring 0", 1, out.offsprings.get(0).getModifications().iterator().next().getValuesToAdd().size()); assertEquals("Wrong # of modifications in offspring 1", 1, out.offsprings.get(1).getModifications().size()); assertEquals("Wrong # of assignments to delete in offspring 1", 1, out.offsprings.get(1).getModifications().iterator().next().getValuesToDelete().size()); assertEquals("Wrong # of modifications in offspring 2", 1, out.offsprings.get(2).getModifications().size()); assertEquals("Wrong # of assignments to delete in offspring 2", 1, out.offsprings.get(2).getModifications().iterator().next().getValuesToDelete().size());