/** * Converts this delta to PropertyModificationType (XML). */ public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta) throws SchemaException { return toItemDeltaTypes(delta, null); }
private void addToDeltas(Map<Long, List<ItemDeltaType>> deltasById, Long id, ItemDelta delta) throws SchemaException { List<ItemDeltaType> deltas = deltasById.get(id); if (deltas == null) { deltas = new ArrayList<>(); deltasById.put(id, deltas); } Collection<ItemDeltaType> itemDeltaTypes = DeltaConvertor.toItemDeltaTypes(delta); deltas.addAll(itemDeltaTypes); }
private void storeExtensionDeltas(List<ItemDeltaType> result, Collection<ItemDelta<?, ?>> extensionDeltas) { for (ItemDelta itemDelta : extensionDeltas) { Collection<ItemDeltaType> deltaTypes; try { deltaTypes = DeltaConvertor.toItemDeltaTypes(itemDelta); } catch (SchemaException e) { throw new SystemException("Unexpected SchemaException when converting extension ItemDelta to ItemDeltaType", e); } result.addAll(deltaTypes); } }
/** * Converts this delta to ObjectModificationType (XML). */ public static <T extends Objectable> ObjectModificationType toObjectModificationType(ObjectDelta<T> delta) throws SchemaException { if (delta.getChangeType() != ChangeType.MODIFY) { throw new IllegalStateException("Cannot produce ObjectModificationType from delta of type " + delta.getChangeType()); } ObjectModificationType modType = new ObjectModificationType(); modType.setOid(delta.getOid()); List<ItemDeltaType> propModTypes = modType.getItemDelta(); for (ItemDelta<?,?> propDelta : delta.getModifications()) { Collection<ItemDeltaType> propPropModTypes; try { propPropModTypes = toItemDeltaTypes(propDelta); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " in " + delta.toString(), e); } propModTypes.addAll(propPropModTypes); } return modType; }
@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); }
@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"); }
Collection<ItemDeltaType> propPropModTypes; try { propPropModTypes = toItemDeltaTypes(propDelta, options); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " in " + objectDelta.toString(), e);