public static <IV extends PrismValue,ID extends ItemDefinition> ItemDelta<IV,ID> createItemDelta(ItemDeltaType propMod, PrismContainerDefinition<?> pcDef) throws SchemaException { return createItemDelta(propMod, pcDef, false); }
public static <T extends Objectable> Collection<? extends ItemDelta> toModifications(Collection<ItemDeltaType> itemDeltaTypes, PrismObjectDefinition<T> objDef) throws SchemaException { Collection<ItemDelta> modifications = new ArrayList<>(); for (ItemDeltaType propMod : itemDeltaTypes) { ItemDelta itemDelta = createItemDelta(propMod, objDef); modifications.add(itemDelta); } return modifications; }
/** * Creates delta from PropertyModificationType (XML). The values inside the PropertyModificationType are converted to java. * That's the reason this method needs schema and objectType (to locate the appropriate definitions). */ public static <IV extends PrismValue,ID extends ItemDefinition> ItemDelta<IV,ID> createItemDelta(ItemDeltaType propMod, Class<? extends Containerable> objectType, PrismContext prismContext) throws SchemaException { Validate.notNull(prismContext, "No prismContext in DeltaConvertor.createItemDelta call"); PrismContainerDefinition<? extends Containerable> objectDefinition = prismContext.getSchemaRegistry(). findContainerDefinitionByCompileTimeClass(objectType); return createItemDelta(propMod, objectDefinition); }
private ObjectDelta<? extends ObjectType> requestToDelta(ModelContext<?> modelContext, ApprovalRequest<AssignmentModification> approvalRequest, String objectOid) throws SchemaException { List<ItemDelta> modifications = new ArrayList<>(); Class<? extends ObjectType> focusClass = primaryChangeAspectHelper.getFocusClass(modelContext); for (ItemDeltaType itemDeltaType : approvalRequest.getItemToApprove().getModifications()) { modifications.add(DeltaConvertor.createItemDelta(itemDeltaType, focusClass, prismContext)); } return ((LensContext) modelContext).getPrismContext().deltaFactory().object() .createModifyDelta(objectOid, modifications, focusClass ); } //endregion
@Test public void testItemDeltaReplaceEmptyString() throws Exception { System.out.println("===[ testItemDeltaReplaceEmptyString ]===="); // GIVEN PrismObjectDefinition<UserType> userDef = getUserDefinition(); PropertyDelta<String> deltaBefore = getPrismContext().deltaFactory().property().createReplaceEmptyDelta(userDef, UserType.F_COST_CENTER); // deltaBefore.setValueToReplace(new PrismPropertyValue<String>("")); // WHEN Collection<ItemDeltaType> itemDeltaTypes = DeltaConvertor.toItemDeltaTypes(deltaBefore); // THEN System.out.println("Serialized"); System.out.println(itemDeltaTypes); // WHEN ItemDelta<?,?> deltaAfter = DeltaConvertor.createItemDelta(itemDeltaTypes.iterator().next(), userDef); // THEN System.out.println("Parsed"); System.out.println(deltaAfter.debugDump()); assertEquals("Deltas do not match", deltaBefore, deltaAfter); }
@Test public void testItemDeltaReplaceNil() throws Exception { System.out.println("===[ testItemDeltaReplaceNil ]===="); // GIVEN PrismObjectDefinition<UserType> userDef = getUserDefinition(); PropertyDelta<String> deltaBefore = getPrismContext().deltaFactory().property().createReplaceEmptyDelta(userDef, UserType.F_COST_CENTER); // The delta remains empty // WHEN Collection<ItemDeltaType> itemDeltaTypes = DeltaConvertor.toItemDeltaTypes(deltaBefore); // THEN System.out.println("Serialized"); System.out.println(itemDeltaTypes); ItemDeltaType itemDeltaType = itemDeltaTypes.iterator().next(); String xml = PrismTestUtil.serializeAtomicValue(itemDeltaType, new QName("wherever","whatever")); System.out.println(xml); // WHEN ItemDelta<?,?> deltaAfter = DeltaConvertor.createItemDelta(itemDeltaType, userDef); // THEN System.out.println("Parsed"); System.out.println(deltaAfter.debugDump()); assertEquals("Deltas do not match", deltaBefore, deltaAfter); }
public static <T extends Objectable> ObjectDelta<T> createObjectDelta(ObjectModificationType objectModification, PrismObjectDefinition<T> objDef) throws SchemaException { ObjectDelta<T> objectDelta = objDef.getPrismContext().deltaFactory().object().create(objDef.getCompileTimeClass(), ChangeType.MODIFY); objectDelta.setOid(objectModification.getOid()); for (ItemDeltaType propMod : objectModification.getItemDelta()) { ItemDelta itemDelta = createItemDelta(propMod, objDef); objectDelta.addModification(itemDelta); } return objectDelta; }
@Test public void testItemDeltaReplace() throws Exception { System.out.println("===[ testItemDeltaReplace ]===="); // GIVEN PrismObjectDefinition<UserType> userDef = getUserDefinition(); PropertyDelta<String> deltaBefore = getPrismContext().deltaFactory().property().createReplaceEmptyDelta(userDef, UserType.F_COST_CENTER); deltaBefore.setRealValuesToReplace("foo"); // WHEN Collection<ItemDeltaType> itemDeltaTypes = DeltaConvertor.toItemDeltaTypes(deltaBefore); // THEN System.out.println("Serialized"); System.out.println(itemDeltaTypes); // WHEN ItemDelta<?,?> deltaAfter = DeltaConvertor.createItemDelta(itemDeltaTypes.iterator().next(), userDef); // THEN System.out.println("Parsed"); System.out.println(deltaAfter.debugDump()); assertEquals("Deltas do not match", deltaBefore, deltaAfter); assertNull(deltaAfter.getEstimatedOldValues()); }
@Test public void testItemDeltaReplaceOldValue() throws Exception { System.out.println("===[ testItemDeltaReplaceOldValue ]===="); // GIVEN PrismObjectDefinition<UserType> userDef = getUserDefinition(); PropertyDelta<String> deltaBefore = getPrismContext().deltaFactory().property().createReplaceEmptyDelta(userDef, UserType.F_COST_CENTER); deltaBefore.setRealValuesToReplace("foo"); deltaBefore.addEstimatedOldValue(getPrismContext().itemFactory().createPropertyValue("BAR")); // WHEN Collection<ItemDeltaType> itemDeltaTypes = DeltaConvertor.toItemDeltaTypes(deltaBefore); // THEN System.out.println("Serialized"); System.out.println(itemDeltaTypes); // WHEN ItemDelta<?,?> deltaAfter = DeltaConvertor.createItemDelta(itemDeltaTypes.iterator().next(), userDef); // THEN System.out.println("Parsed"); System.out.println(deltaAfter.debugDump()); assertEquals("Deltas do not match", deltaBefore, deltaAfter); PropertyDelta<String> propDeltaAfter = (PropertyDelta<String>)deltaAfter; PrismAsserts.assertValues("Wrong old value", propDeltaAfter.getEstimatedOldValues(), "BAR"); }
PropertyDelta<ProtectedStringType> passDelta = (PropertyDelta)DeltaConvertor.createItemDelta(propMod, shadow.getDefinition()); PropertyModificationOperation<ProtectedStringType> passwordModification = new PropertyModificationOperation(passDelta); changes.add(passwordModification);
objectDelta.setOid(objectDeltaType.getOid()); for (ItemDeltaType propMod : objectDeltaType.getItemDelta()) { ItemDelta itemDelta = createItemDelta(propMod, objDef, allowRawValues); if (itemDelta != null){ objectDelta.addModification(itemDelta);
.createItemDelta(itemDeltaType, TaskType.class, taskManager.getPrismContext()); LOGGER.trace("Applying ItemDelta to task extension; task = {}; itemDelta = {}", this, itemDelta.debugDump()); this.modifyExtension(itemDelta);