public static <T extends Objectable> ObjectDelta<T> createObjectDelta(ObjectDeltaType objectDeltaType, PrismContext prismContext) throws SchemaException { return createObjectDelta(objectDeltaType, prismContext, false); }
public static <T extends Objectable> Collection<? extends ItemDelta> toModifications(ObjectModificationType objectModification, PrismObjectDefinition<T> objDef) throws SchemaException { return toModifications(objectModification.getItemDelta(), objDef); }
public static ObjectDeltaType toObjectDeltaType(ObjectDelta<? extends ObjectType> objectDelta) throws SchemaException { return toObjectDeltaType(objectDelta, null); }
private void roundTrip(ObjectDelta delta) throws Exception { ObjectDeltaType deltaType = DeltaConvertor.toObjectDeltaType(delta); System.out.println("Serialized to bean"); System.out.println(deltaType); String xml = getPrismContext().xmlSerializer().serializeRealValue(deltaType, new QName("aDelta")); System.out.println("Serialized to XML"); System.out.println(xml); ObjectDeltaType deltaTypeParsed = getPrismContext().parserFor(xml).parseRealValue(); System.out.println("Parsed from XML to bean"); System.out.println(deltaTypeParsed); ObjectDelta deltaParsed = DeltaConvertor.createObjectDelta(deltaTypeParsed, getPrismContext()); System.out.println("Parsed from XML to bean to delta"); System.out.println(deltaParsed); assertTrue("Deltas (native) do not match", delta.equivalent(deltaParsed)); // note: comparing beans is problematic because e.g. item paths are not equal ({common-3}name vs {c=common-3}c:name) } }
@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); }
public static <IV extends PrismValue,ID extends ItemDefinition> ItemDelta<IV,ID> createItemDelta(ItemDeltaType propMod, PrismContainerDefinition<?> pcDef) throws SchemaException { return createItemDelta(propMod, pcDef, false); }
/** * Converts this delta to PropertyModificationType (XML). */ public static Collection<ItemDeltaType> toItemDeltaTypes(ItemDelta delta) throws SchemaException { return toItemDeltaTypes(delta, null); }
public static ObjectDeltaType toObjectDeltaType(ObjectDelta<? extends ObjectType> objectDelta, DeltaConversionOptions options) throws SchemaException { Validate.notNull(objectDelta.getPrismContext(), "ObjectDelta without prismContext cannot be converted to ObjectDeltaType"); ObjectDeltaType objectDeltaType = new ObjectDeltaType(); objectDeltaType.setChangeType(convertChangeType(objectDelta.getChangeType())); Class<? extends Objectable> type = objectDelta.getObjectTypeClass(); PrismObjectDefinition<? extends Objectable> objDef = objectDelta.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type); Collection<ItemDeltaType> propPropModTypes; try { propPropModTypes = toItemDeltaTypes(propDelta, options); } catch (SchemaException e) { throw new SchemaException(e.getMessage() + " in " + objectDelta.toString(), e);
public static ObjectDeltaOperationType toObjectDeltaOperationType(ObjectDeltaOperation objectDeltaOperation) throws SchemaException { return toObjectDeltaOperationType(objectDeltaOperation, null); }
@Override public ObjectDeltaOperationListType executeChanges(ObjectDeltaListType deltaList, ModelExecuteOptionsType optionsType) throws FaultMessage { notNullArgument(deltaList, "Object delta list must not be null."); Task task = createTaskInstance(EXECUTE_CHANGES); auditLogin(task); OperationResult operationResult = task.getResult(); try { Collection<ObjectDelta> deltas = DeltaConvertor.createObjectDeltas(deltaList, prismContext); for (ObjectDelta delta : deltas) { prismContext.adopt(delta); } ModelExecuteOptions options = ModelExecuteOptions.fromModelExecutionOptionsType(optionsType); Collection<ObjectDeltaOperation<? extends ObjectType>> objectDeltaOperations = modelService.executeChanges((Collection) deltas, options, task, operationResult); // brutally eliminating type-safety compiler barking ObjectDeltaOperationListType retval = new ObjectDeltaOperationListType(); for (ObjectDeltaOperation objectDeltaOperation : objectDeltaOperations) { ObjectDeltaOperationType objectDeltaOperationType = DeltaConvertor.toObjectDeltaOperationType(objectDeltaOperation, null); retval.getDeltaOperation().add(objectDeltaOperationType); } return retval; } catch (Exception ex) { LoggingUtils.logException(LOGGER, "# MODEL executeChanges() failed", ex); throwFault(ex, operationResult); // notreached return null; } finally { auditLogout(task); } }
ObjectDeltaType objectDeltaType = toObjectDeltaType(objectDelta); ObjectDelta<Objectable> objectDeltaRoundtrip = DeltaConvertor.createObjectDelta(objectDeltaType, getPrismContext());
@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> 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; }
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); }
public static ObjectDeltaOperationType toObjectDeltaOperationType(ObjectDeltaOperation objectDeltaOperation, DeltaConversionOptions options) throws SchemaException { ObjectDeltaOperationType rv = new ObjectDeltaOperationType(); toObjectDeltaOperationType(objectDeltaOperation, rv, options); return rv; }
public static Collection<ObjectDelta> createObjectDeltas(ObjectDeltaListType deltaList, PrismContext prismContext) throws SchemaException { List<ObjectDelta> retval = new ArrayList<>(); for (ObjectDeltaType deltaType : deltaList.getDelta()) { retval.add(createObjectDelta(deltaType, prismContext)); } return retval; } }
private Collection<ItemDelta<?, ?>> parseDeltas(List<ItemDeltaType> deltas) { try { //noinspection unchecked return (Collection<ItemDelta<?, ?>>) DeltaConvertor.toModifications(deltas, taskDefinition); } catch (SchemaException e) { throw new SystemException("Couldn't parse task item deltas: " + e.getMessage(), e); } }
public ObjectDeltaWavesType toObjectDeltaWavesType() throws SchemaException { ObjectDeltaWavesType objectDeltaWavesType = new ObjectDeltaWavesType(); for (int i = 0; i < waves.size(); i++) { ObjectDelta wave = waves.get(i); if (wave != null) { ObjectDeltaWaveType objectDeltaWaveType = new ObjectDeltaWaveType(); objectDeltaWaveType.setNumber(i); objectDeltaWaveType.setDelta(DeltaConvertor.toObjectDeltaType(wave)); objectDeltaWavesType.getWave().add(objectDeltaWaveType); } } return objectDeltaWavesType; }
@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()); }
/** * 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); }