public static <IV extends PrismValue,ID extends ItemDefinition> void assertNoAdd(String message, ItemDelta<IV,ID> delta) { assertNoSet(message, "add", delta.getValuesToAdd()); }
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(); } } }
for (PrismValue prismValue : itemDelta.getValuesToAdd()) { body.append(" --- ADD: "); body.append(prismValue.debugDump(2));
if (dryRun) { wasPresent = wasPresent || emptyIfNull(itemDelta.getValuesToAdd()).contains(value) || emptyIfNull(itemDelta.getValuesToReplace()).contains(value); } else {
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); } } }
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); }
public static void checkWfProcessAuditRecords(Map<String, WorkflowResult> expectedResults, DummyAuditService dummyAuditService) { List<AuditEventRecord> records = dummyAuditService.getRecordsOfType(AuditEventType.WORKFLOW_PROCESS_INSTANCE); assertEquals("Unexpected number of workflow process instance audit records", expectedResults.size() * 2, records.size()); for (AuditEventRecord record : records) { if (record.getEventStage() != AuditEventStage.EXECUTION) { continue; } ObjectDelta<? extends ObjectType> delta = record.getDeltas().iterator().next().getObjectDelta(); if (!delta.getModifications().isEmpty()) { AssignmentType assignmentType = (AssignmentType) ((PrismContainerValue) delta.getModifications().iterator().next() .getValuesToAdd().iterator().next()).asContainerable(); String oid = assignmentType.getTargetRef().getOid(); assertNotNull("Unexpected role to approve: " + oid, expectedResults.containsKey(oid)); assertEquals("Unexpected result for " + oid + ": " + record.getResult(), expectedResults.get(oid), WorkflowResult.fromNiceWfAnswer(record.getResult())); } } }
} else if (objectDelta.isModify()) { 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; }
LOGGER.trace("Found password value add/modify delta"); Collection<PrismPropertyValue<ProtectedStringType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismPropertyValue<ProtectedStringType> value : values) { LOGGER.trace("Found password add/modify delta"); Collection<PrismContainerValue<PasswordType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismContainerValue<PasswordType> value : values) { LOGGER.trace("Found credentials add/modify delta"); Collection<PrismContainerValue<CredentialsType>> values = itemDelta.isAdd() ? itemDelta.getValuesToAdd() : itemDelta.getValuesToReplace(); for (PrismContainerValue<CredentialsType> value : values) {
@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", 2, taskModelContext.getFocusContext().getPrimaryDelta().getModifications().size()); Iterator<? extends ItemDelta> it = taskModelContext.getFocusContext().getPrimaryDelta().getModifications().iterator(); ItemDelta addRoleDelta = null, activationChange = null; while (it.hasNext()) { ItemDelta mod = it.next(); if (mod.isAdd()) { addRoleDelta = mod; } else if (mod.isReplace()) { activationChange = mod; } } assertNotNull("role add delta was not found", addRoleDelta); assertEquals("role add delta contains wrong number of values", 1, addRoleDelta.getValuesToAdd().size()); assertNotNull("activation change delta was not found", activationChange); }
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); } }
@Test public void testFactorAddDeltaForItemValues() throws Exception { final String TEST_NAME = "testFactorAddDeltaForItemValues"; displayTestTile(TEST_NAME); // GIVEN PrismObject<UserType> user = PrismTestUtil.parseObject(USER_BILL_FILE); String OID = "user-oid-1"; user.setOid(OID); ObjectDelta<UserType> addDelta = DeltaFactory.Object.createAddDelta(user); // WHEN ObjectDelta.FactorOutResultMulti<UserType> out = addDelta.factorOutValues(ItemPath.create(UserType.F_ASSIGNMENT), true); // THEN System.out.println("Delta before factorOut:\n" + addDelta.debugDump() + "\n"); System.out.println("Delta after factorOut:\n" + out.remainder.debugDump() + "\n"); System.out.println("Offspring deltas:\n" + DebugUtil.debugDump(out.offsprings) + "\n"); assertTrue("Remaining delta is not an ADD delta", out.remainder.isAdd()); assertEquals("Wrong # of remaining assignments", 0, out.remainder.getObjectToAdd().asObjectable().getAssignment().size()); assertEquals("Wrong # of offspring deltas", 3, out.offsprings.size()); assertDeltaOid(out.remainder, OID); for (ObjectDelta<UserType> offspring : out.offsprings) { assertEquals("Wrong # of modifications in offspring", 1, offspring.getModifications().size()); assertEquals("Wrong # of assignments to add", 1, offspring.getModifications().iterator().next().getValuesToAdd().size()); assertDeltaOid(offspring, OID); } }
@Test public void testFactorAddDeltaForItem() throws Exception { final String TEST_NAME = "testFactorAddDeltaForItem"; displayTestTile(TEST_NAME); // GIVEN PrismObject<UserType> user = PrismTestUtil.parseObject(USER_BILL_FILE); String OID = "user-oid-1"; user.setOid(OID); ObjectDelta<UserType> addDelta = DeltaFactory.Object.createAddDelta(user); // WHEN ObjectDelta.FactorOutResultSingle<UserType> out = addDelta.factorOut(singleton(ItemPath.create(UserType.F_ASSIGNMENT)), true); // THEN System.out.println("Delta before factorOut:\n" + addDelta.debugDump() + "\n"); System.out.println("Delta after factorOut:\n" + out.remainder.debugDump() + "\n"); System.out.println("Offspring delta:\n" + DebugUtil.debugDump(out.offspring) + "\n"); assertTrue("Remaining delta is not an ADD delta", out.remainder.isAdd()); assertEquals("Wrong # of remaining assignments", 0, out.remainder.getObjectToAdd().asObjectable().getAssignment().size()); assertNotNull("Missing offspring delta", out.offspring); assertEquals("Wrong # of modifications in offspring", 1, out.offspring.getModifications().size()); assertEquals("Wrong # of assignments to add", 3, out.offspring.getModifications().iterator().next().getValuesToAdd().size()); assertDeltaOid(out.remainder, OID); assertDeltaOid(out.offspring, OID); }
mergeValuesToReplace(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToReplace())); } else { if (deltaToMerge.getValuesToAdd() != null) { mergeValuesToAdd(PrismValueCollectionsUtil.cloneValues(deltaToMerge.getValuesToAdd()));
/** * 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); } } } } } }