private void dumpDeltaOut(ObjectTreeDeltas<?> deltasOut) { List<ObjectDelta<? extends ObjectType>> deltaOut = deltasOut != null ? deltasOut.getDeltaList() : new ArrayList<>(); LOGGER.trace("deltaOut has {} modifications:", deltaOut.size()); for (ObjectDelta<?> delta : deltaOut) { LOGGER.trace("{}", delta.debugDump()); } } //endregion
@Override public String debugDump(int indent) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append("ObjectTreeDeltas:\n"); DebugUtil.debugDumpWithLabel(sb, "Focus primary change", focusChange, indent + 1); sb.append("\n"); DebugUtil.debugDumpLabel(sb, "Projections primary changes", indent+1); for (Map.Entry<ResourceShadowDiscriminator, ObjectDelta<ShadowType>> entry : projectionChangeMap.entrySet()) { sb.append("\n"); DebugUtil.indentDebugDump(sb, indent+2); sb.append(entry.getKey()); sb.append(" =>\n"); sb.append(entry.getValue().debugDump(indent+3)); } return sb.toString(); }
@Override public String getPlaintextPasswordFromDelta(ObjectDelta delta) { try { return midpointFunctions.getPlaintextAccountPasswordFromDelta(delta); } catch (EncryptionException e) { LoggingUtils.logException(LOGGER, "Couldn't decrypt password from shadow delta: {}", e, delta.debugDump()); return null; } }
@Override public String debugDump(int indent) { StringBuilder sb = new StringBuilder(); DebugUtil.indentDebugDump(sb, indent); sb.append("ObjectDeltaObject():"); dumpObject(sb, oldObject, "old", indent +1); if (delta != null) { sb.append("\n"); DebugUtil.indentDebugDump(sb, indent + 1); sb.append("delta:"); if (delta == null) { sb.append(" null"); } else { sb.append("\n"); sb.append(delta.debugDump(indent + 2)); } } dumpObject(sb, newObject, "new", indent +1); return sb.toString(); }
protected void assertDeltasEqual(String message, ObjectDelta expectedDelta, ObjectDelta realDelta) { // removeOldValues(expectedDelta); // removeOldValues(realDelta); if (!expectedDelta.equivalent(realDelta)) { fail(message + "\nExpected:\n" + expectedDelta.debugDump() + "\nReal:\n" + realDelta.debugDump()); } }
public ObjectDelta<O> getAggregatedWaveDelta(int wave) throws SchemaException { ObjectDelta<O> result = null; for (int w = 0; w <= wave; w++) { ObjectDelta<O> delta = getWaveDelta(w); if (delta == null) { continue; } if (result == null) { result = delta.clone(); } else { result.merge(delta); } } LOGGER.trace("Aggregated wave delta for wave {} = {}", wave, result != null ? result.debugDump() : "(null)"); return result; }
private <T extends ObjectType, F extends FocusType> boolean alreadyExecuted(ObjectDelta<T> objectDelta, LensElementContext<T> objectContext) { if (objectContext == null) { return false; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Checking for already executed delta:\n{}\nIn deltas:\n{}", objectDelta.debugDump(), DebugUtil.debugDump(objectContext.getExecutedDeltas())); } return ObjectDeltaOperation.containsDelta(objectContext.getExecutedDeltas(), objectDelta); }
@Test public void testAddDelta() throws SchemaException, SAXException, IOException { System.out.println("===[ testAddDelta ]==="); // WHEN ObjectDelta<UserType> userDelta = DiffUtil.diff(null,new File(TEST_DIR, "user-jack-after.xml"), UserType.class, getPrismContext()); //THEN System.out.println("DELTA:"); System.out.println(userDelta.debugDump()); userDelta.checkConsistence(); assertEquals("Wrong delta OID", "deadbeef-c001-f00d-1111-222233330001", userDelta.getOid()); assertEquals("Wrong change type", ChangeType.ADD, userDelta.getChangeType()); // TODO }
@Test(enabled = false) public void testTaskExtensionDeleteDelta() throws Exception { System.out.println("===[ testTaskExtensionDeleteDelta ]===="); // GIVEN PrismObject oldTask = PrismTestUtil.parseObject( new File(TEST_DIR, "task-old.xml")); PrismObject newTask = PrismTestUtil.parseObject( new File(TEST_DIR, "task-new.xml")); ObjectDelta<TaskType> delta = oldTask.diff(newTask, EquivalenceStrategy.LITERAL_IGNORE_METADATA); System.out.println("Delta:"); System.out.println(delta.debugDump()); final QName CUSTOM_OBJECT = new QName("http://delta.example.com", "object"); PrismContext context = getPrismContext(); // WHEN ObjectDeltaType xmlDelta = toObjectDeltaType(delta); // THEN Map<String, Object> properties = new HashMap<>(); String result = PrismTestUtil.serializeJaxbElementToString(new JAXBElement<>(CUSTOM_OBJECT, Object.class, xmlDelta)); assertNotNull(result); }
/** * Computes delta to execute, given a list of already executes deltas. See * below. */ private <T extends ObjectType> ObjectDelta<T> computeDeltaToExecute(ObjectDelta<T> objectDelta, LensElementContext<T> objectContext) { if (objectContext == null) { return objectDelta; } if (LOGGER.isTraceEnabled()) { LOGGER.trace("Computing delta to execute from delta:\n{}\nGiven these executed deltas:\n{}", objectDelta.debugDump(1), LensObjectDeltaOperation.shorterDebugDump(objectContext.getExecutedDeltas(),1)); } List<LensObjectDeltaOperation<T>> executedDeltas = objectContext.getExecutedDeltas(); return computeDiffDelta(executedDeltas, objectDelta); }
@Test // MID-4689 public void testObjectDeltaFindItemDeltaModifyNonExistentPropertyInReplacedContainer() throws Exception { final String TEST_NAME="testObjectDeltaFindItemDeltaModifyNonExistentPropertyInReplacedContainer"; displayTestTitle(TEST_NAME); // GIVEN ObjectDelta<UserType> userDelta = createDeltaForFindItem(true); System.out.println("Object delta:\n"+userDelta.debugDump()); ItemPath itemDeltaPath = ItemPath.create(UserType.F_ACTIVATION, ActivationType.F_VALID_TO); // not present in the delta // WHEN ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath); // THEN System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump())); assertNull("Found delta even if it shouldn't", itemDelta); }
@Test public void testObjectDeltaFindItemDeltaModifyNonExistentPropertyInAddedContainer() throws Exception { final String TEST_NAME="testObjectDeltaFindItemDeltaModifyNonExistentPropertyInAddedContainer"; displayTestTitle(TEST_NAME); // GIVEN ObjectDelta<UserType> userDelta = createDeltaForFindItem(false); System.out.println("Object delta:\n"+userDelta.debugDump()); ItemPath itemDeltaPath = ItemPath.create(UserType.F_ACTIVATION, ActivationType.F_VALID_TO); // not present in the delta // WHEN ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath); // THEN System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump())); assertNull("Found delta even if it shouldn't", itemDelta); }
private void checkObject(String oid, PrismObject<UserType> expected, boolean loadPhoto, OperationResult result) throws ObjectNotFoundException, SchemaException { Collection<SelectorOptions<GetOperationOptions>> options; if (loadPhoto) { options = Collections.singletonList( SelectorOptions.create(prismContext.toUniformPath(UserType.F_JPEG_PHOTO), GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE))); } else { options = null; } PrismObject<UserType> real = repositoryService.getObject(UserType.class, oid, options, result); ObjectDelta<UserType> delta = expected.diff(real); System.out.println("Expected object = \n" + expected.debugDump()); System.out.println("Real object in repo = \n" + real.debugDump()); System.out.println("Difference = \n" + delta.debugDump()); if (!delta.isEmpty()) { fail("Objects are not equal.\n*** Expected:\n" + expected.debugDump() + "\n*** Got:\n" + real.debugDump() + "\n*** Delta:\n" + delta.debugDump()); } }
private void checkObject(String oid, PrismObject<OrgType> expected, boolean loadPhoto, OperationResult result) throws ObjectNotFoundException, SchemaException { Collection<SelectorOptions<GetOperationOptions>> options; if (loadPhoto) { options = Collections.singletonList( SelectorOptions.create(prismContext.toUniformPath(FocusType.F_JPEG_PHOTO), GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE))); } else { options = null; } PrismObject<OrgType> real = repositoryService.getObject(OrgType.class, oid, options, result); ObjectDelta<OrgType> delta = expected.diff(real); System.out.println("Expected object = \n" + expected.debugDump()); System.out.println("Real object in repo = \n" + real.debugDump()); System.out.println("Difference = \n" + delta.debugDump()); if (!delta.isEmpty()) { fail("Objects are not equal.\n*** Expected:\n" + expected.debugDump() + "\n*** Got:\n" + real.debugDump() + "\n*** Delta:\n" + delta.debugDump()); } }
@Test public void testRefWithObject() throws SchemaException, IOException, JAXBException { System.out.println("===[ testRefWithObject ]===="); ObjectModificationType objectChange = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "user-modify-add-account.xml"), ObjectModificationType.COMPLEX_TYPE); ObjectDelta<UserType> objectDelta = DeltaConvertor.createObjectDelta(objectChange, UserType.class, getPrismContext()); System.out.println("delta: " + objectDelta.debugDump()); assertNotNull("No object delta", objectDelta); objectDelta.checkConsistence(); assertEquals("Wrong OID", "c0c010c0-d34d-b33f-f00d-111111111111", objectDelta.getOid()); ReferenceDelta accoutRefDelta = objectDelta.findReferenceModification(UserType.F_LINK_REF); assertNotNull("No accountRef delta", accoutRefDelta); Collection<PrismReferenceValue> valuesToAdd = accoutRefDelta.getValuesToAdd(); assertEquals("Wrong number of values to add", 1, valuesToAdd.size()); PrismReferenceValue accountRefVal = valuesToAdd.iterator().next(); assertNotNull("No object in accountRef value", accountRefVal.getObject()); objectDelta.assertDefinitions(); }
@Test public void testResourceNsChangeLiteral() throws SchemaException, SAXException, IOException, JAXBException { System.out.println("===[ testResourceNsChangeLiteral ]==="); PrismObject<ResourceType> resourceBefore = PrismTestUtil.parseObject(RESOURCE_BEFORE_FILE); PrismObject<ResourceType> resourceAfter = PrismTestUtil.parseObject(RESOURCE_AFTER_NS_CHANGE_FILE); resourceBefore.checkConsistence(); resourceAfter.checkConsistence(); // WHEN ObjectDelta<ResourceType> resourceDelta = resourceBefore.diff(resourceAfter, EquivalenceStrategy.LITERAL_IGNORE_METADATA); // THEN System.out.println("DELTA:"); System.out.println(resourceDelta.debugDump()); resourceDelta.checkConsistence(); resourceDelta.assertDefinitions(true); resourceBefore.checkConsistence(); resourceAfter.checkConsistence(); assertFalse("The delta is empty", resourceDelta.isEmpty()); }
@Test public void testObjectDeltaFindItemDeltaModifyPropertyInAddedContainer() throws Exception { final String TEST_NAME="testObjectDeltaFindItemDeltaModifyPropertyInAddedContainer"; displayTestTitle(TEST_NAME); // GIVEN ObjectDelta<UserType> userDelta = createDeltaForFindItem(false); System.out.println("Object delta:\n"+userDelta.debugDump()); ItemPath itemDeltaPath = ItemPath.create(UserType.F_ACTIVATION, ActivationType.F_ENABLED); // WHEN ItemDelta<PrismValue, ItemDefinition> itemDelta = userDelta.findItemDelta(itemDeltaPath); // THEN System.out.println("Item delta:\n"+(itemDelta==null?"null":itemDelta.debugDump())); PrismAsserts.assertInstanceOf(PropertyDelta.class, itemDelta); assertEquals(itemDeltaPath, itemDelta.getPath()); PrismAsserts.assertPropertyValues("Wrong add values in "+itemDelta, ((PropertyDelta)itemDelta).getValuesToAdd(), Boolean.TRUE); }
private MidPointPrincipal save(MidPointPrincipal person, OperationResult result) throws ObjectNotFoundException, SchemaException, ObjectAlreadyExistsException { UserType oldUserType = getUserByOid(person.getOid(), result); PrismObject<UserType> oldUser = oldUserType.asPrismObject(); PrismObject<UserType> newUser = person.getUser().asPrismObject(); ObjectDelta<UserType> delta = oldUser.diff(newUser); if (LOGGER.isTraceEnabled()) { LOGGER.trace("Updating user {} with delta:\n{}", newUser, delta.debugDump()); } repositoryService.modifyObject(UserType.class, delta.getOid(), delta.getModifications(), new OperationResult(OPERATION_UPDATE_USER)); return person; }
@Test public void addUserWithAssignmentExtension() throws Exception { LOGGER.info("===[ addUserWithAssignmentExtension ]==="); File file = new File(FOLDER_BASIC, "user-assignment-extension.xml"); List<PrismObject<? extends Objectable>> elements = prismContext.parserFor(file).parseObjects(); OperationResult result = new OperationResult("ADD"); String oid = repositoryService.addObject((PrismObject) elements.get(0), null, result); PrismObject<UserType> fileUser = (PrismObject<UserType>) prismContext.parserFor(file).parseObjects().get(0); long id = 1; for (AssignmentType assignment : fileUser.asObjectable().getAssignment()) { assignment.setId(id); id++; } PrismObject<UserType> repoUser = repositoryService.getObject(UserType.class, oid, null, result); ObjectDelta<UserType> delta = fileUser.diff(repoUser); AssertJUnit.assertNotNull(delta); LOGGER.info("delta\n{}", delta.debugDump(3)); assertTrue(delta.isEmpty()); }
@Override protected void afterFirstClockworkRun(Task rootTask, List<Task> subtasks, List<WorkItemType> workItems, OperationResult result) throws Exception { if (immediate) { assertFalse("There is model context in the root task (it should not be there)", wfTaskUtil.hasModelContext(rootTask)); } else { ModelContext taskModelContext = wfTaskUtil.getModelContext(rootTask, result); ObjectDelta realDelta0 = taskModelContext.getFocusContext().getPrimaryDelta(); assertTrue("Delta0 is not empty: " + realDelta0.debugDump(), realDelta0.isEmpty()); assertWfContextAfterClockworkRun(rootTask, subtasks, workItems, result, objectOid, expectedTasks, expectedWorkItems); } }