public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoReplace(String message, ItemDelta<IV,ID> delta) { assertNoSet(message, "replace", delta.getValuesToReplace()); }
if (delta.getValuesToReplace() != null) { for (String existingOid : existingOids) { boolean found = false; for (PrismReferenceValue newVal : (Collection<PrismReferenceValue>) delta.getValuesToReplace()) { if (existingOid.equals(newVal.getOid())) { found = true; break;
private Set<String> getParentOidsToAdd(Collection<? extends ItemDelta> modifications, PrismObject<? extends ObjectType> originalObject) { Set<String> oids = new HashSet<>(); Set<String> existingOids = getParentOidsFromObject(originalObject); for (ItemDelta delta : modifications) { if (delta.getValuesToAdd() != null) { for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToAdd()) { String oid = val.getOid(); if (!existingOids.contains(oid)) { // if it's already there, we don't want to add it oids.add(oid); } } } if (delta.getValuesToReplace() != null) { // at this point we can assume this is not mixed with DELETE or ADD deltas // we mark all 'new' values in REPLACE delta not present in existing object as being added oids = new HashSet<>(); // and we do this for the latest REPLACE ItemDelta for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToReplace()) { String oid = val.getOid(); if (!existingOids.contains(oid)) { // if it's already there, we don't want to add it oids.add(oid); } } } } return oids; }
@Override public List<PrismValue> getNewValuesFor(ItemPath itemPath) { if (isAdd()) { Item<PrismValue, ItemDefinition> item = objectToAdd.findItem(itemPath); return item != null ? item.getValues() : Collections.emptyList(); } else if (isDelete()) { return Collections.emptyList(); } else { ItemDelta itemDelta = ItemDeltaCollectionsUtil.findItemDelta(modifications, itemPath, ItemDelta.class, false); if (itemDelta != null) { if (itemDelta.getValuesToReplace() != null) { return (List<PrismValue>) itemDelta.getValuesToReplace(); } else if (itemDelta.getValuesToAdd() != null) { return (List<PrismValue>) itemDelta.getValuesToAdd(); } else { return Collections.emptyList(); } } else { return Collections.emptyList(); } } }
if (delta.getValuesToReplace() != null && !delta.getValuesToReplace().isEmpty()) { Iterator<PrismContainerValue<ShadowAssociationType>> valueIterator = delta.getValuesToReplace().iterator(); while (valueIterator.hasNext()) { PrismContainerValue<ShadowAssociationType> association = valueIterator.next(); delta.resetValuesToAdd(); if (delta.getValuesToAdd() == null && delta.getValuesToReplace() == null && delta.getValuesToDelete() == null) { deltaIterator.remove();
wasPresent = wasPresent || emptyIfNull(itemDelta.getValuesToAdd()).contains(value) || emptyIfNull(itemDelta.getValuesToReplace()).contains(value); } else { boolean removed1 = itemDelta.removeValueToAdd(value); if (itemDelta.getValuesToReplace() != null) { throw new UnsupportedOperationException("Couldn't subtract 'value to be deleted' from REPLACE itemDelta: " + itemDelta);
for (PrismValue prismValue : itemDelta.getValuesToReplace()) { body.append(" --- REPLACE: "); body.append(prismValue.debugDump(2));
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 } } }
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); } } }
if (itemDelta.getPath().equivalent(ShadowType.F_OBJECT_CHANGE)) { changes = itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace();
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); }
for (ItemDelta<?,?> delta : objectDelta.getModifications()) { applyVisitorToValues(delta.getValuesToAdd(), delta, visitor); applyVisitorToValues(delta.getValuesToReplace(), delta, visitor);
/** * 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; }
Collection<PrismPropertyValue<ProtectedStringType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismPropertyValue<ProtectedStringType> value : values) { passwords.add(value.getValue()); Collection<PrismContainerValue<PasswordType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismContainerValue<PasswordType> value : values) { if (value.asContainerable().getValue() != null) { Collection<PrismContainerValue<CredentialsType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismContainerValue<CredentialsType> value : values) { if (value.asContainerable().getPassword() != null && value.asContainerable().getPassword().getValue() != null) {
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); } }
@Override public void assertsAfterClockworkRun(Task rootTask, List<Task> wfSubtasks, OperationResult result) throws Exception { ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result); assertEquals("There is wrong number of modifications left in primary focus delta", 1, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size()); ItemDelta givenNameDelta = (ItemDelta) taskModelContext.getFocusContext().getPrimaryDelta().getModifications().iterator().next(); assertNotNull("givenName delta is incorrect (not a replace delta)", givenNameDelta.isReplace()); assertEquals("givenName delta is incorrect (wrong value)", "JACK", ((PrismPropertyValue<PolyString>) givenNameDelta.getValuesToReplace().iterator().next()).getValue().getOrig()); PrismObject<UserType> jack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result); assertNotAssignedRole(jack, ROLE_R2_OID); assertEquals("Wrong given name before change", "Jack", jack.asObjectable().getGivenName().getOrig()); }
return; if (deltaToMerge.getValuesToReplace() != null) { mergeValuesToReplace(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToReplace())); } else { if (deltaToMerge.getValuesToAdd() != null) {
/** * 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; }
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); }
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); } } } } } }