use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestOrgStruct method test300JackUnassignAllOrgs.
@Test
public void test300JackUnassignAllOrgs() throws Exception {
final String TEST_NAME = "test300JackUnassignAllOrgs";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
// WHEN
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE, SchemaConstants.ORG_MANAGER, null, null, false)));
modifications.add((createAssignmentModification(ORG_SCUMM_BAR_OID, OrgType.COMPLEX_TYPE, null, null, null, false)));
modifications.add((createAssignmentModification(ORG_SAVE_ELAINE_OID, OrgType.COMPLEX_TYPE, null, null, null, false)));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
modelService.executeChanges(deltas, null, task, result);
// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertAssignedNoOrg(userJack);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, null);
// Postcondition
assertMonkeyIslandOrgSanity();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestOrgStruct method test210JackAssignMinistryOfOffenseMember.
// besides Offense org assignment, we create also Defender role assignment (which indirectly creates Defense org assignment)
@Test
public void test210JackAssignMinistryOfOffenseMember() throws Exception {
final String TEST_NAME = "test210JackAssignMinistryOfOffenseMember";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add(createAssignmentModification(ORG_MINISTRY_OF_OFFENSE_OID, OrgType.COMPLEX_TYPE, null, null, null, true));
modifications.add(createAssignmentModification(ROLE_DEFENDER_OID, RoleType.COMPLEX_TYPE, null, null, null, true));
ObjectDelta<UserType> userDelta = ObjectDelta.createModifyDelta(USER_JACK_OID, modifications, UserType.class, prismContext);
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertAssignedOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID);
assertHasOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
// Postcondition
assertMonkeyIslandOrgSanity();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ModifyAssignmentAspect method getApprovalRequests.
private List<ApprovalRequest<AssignmentModification>> getApprovalRequests(ModelContext<?> modelContext, WfConfigurationType wfConfigurationType, ObjectDelta<? extends ObjectType> change, Task taskFromModel, OperationResult result) throws SchemaException {
if (change.getChangeType() != ChangeType.MODIFY) {
return null;
}
PrismObject<F> focusOld = (PrismObject<F>) modelContext.getFocusContext().getObjectOld();
F focusTypeOld = focusOld.asObjectable();
PcpAspectConfigurationType config = primaryChangeAspectHelper.getPcpAspectConfigurationType(wfConfigurationType, this);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Relevant assignments in focus modify delta: ");
}
List<ApprovalRequest<AssignmentModification>> approvalRequestList = new ArrayList<>();
final ItemPath ASSIGNMENT_PATH = new ItemPath(UserType.F_ASSIGNMENT);
PrismContainer<AssignmentType> assignmentsOld = focusOld.findContainer(ASSIGNMENT_PATH);
// deltas sorted by assignment to which they are related
Map<Long, List<ItemDeltaType>> deltasById = new HashMap<>();
Iterator<? extends ItemDelta> deltaIterator = change.getModifications().iterator();
while (deltaIterator.hasNext()) {
ItemDelta delta = deltaIterator.next();
if (!ASSIGNMENT_PATH.isSubPath(delta.getPath())) {
continue;
}
// id may be null
Long id = getAssignmentIdFromDeltaPath(assignmentsOld, delta.getPath());
AssignmentType assignmentType = getAssignmentToBeModified(assignmentsOld, id);
if (isAssignmentRelevant(assignmentType)) {
T target = getAssignmentApprovalTarget(assignmentType, result);
boolean approvalRequired = shouldAssignmentBeApproved(config, target);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(" - target: {} (approval required = {})", target, approvalRequired);
}
if (approvalRequired) {
addToDeltas(deltasById, assignmentType.getId(), delta);
deltaIterator.remove();
}
}
}
if (!deltasById.isEmpty()) {
for (Map.Entry<Long, List<ItemDeltaType>> entry : deltasById.entrySet()) {
Long id = entry.getKey();
AssignmentType assignmentType = getAssignmentToBeModified(assignmentsOld, id);
AssignmentType aCopy = cloneAndCanonicalizeAssignment(assignmentType);
T target = getAssignmentApprovalTarget(assignmentType, result);
ApprovalRequest approvalRequest = createApprovalRequestForModification(config, aCopy, target, entry.getValue(), createRelationResolver(target, result), createReferenceResolver(modelContext, taskFromModel, result));
approvalRequestList.add(approvalRequest);
}
}
return approvalRequestList;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ModifyTest method test120ModifyAccountMetadata.
/**
* Modify account metadata. Make sure that no unrelated item has changed.
*/
// MID-3484
@Test(enabled = false)
public void test120ModifyAccountMetadata() throws Exception {
final String TEST_NAME = "test120ModifyAccountMetadata";
TestUtil.displayTestTile(TEST_NAME);
// GIVEN
OperationResult parentResult = new OperationResult(TEST_NAME);
PrismObject<ShadowType> shadowBefore = prismContext.parseObject(ACCOUNT_FILE);
MetadataType metaData = new MetadataType();
metaData.setCreateChannel("channel");
metaData.setCreateTimestamp(XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis()));
shadowBefore.asObjectable().setMetadata(metaData);
// The parsed shadow has attributes that have xsi:type specification. Add another one that has
// fully dynamic definition
QName attrBazQName = new QName(MidPointConstants.NS_RI, "baz");
PrismContainer<Containerable> attributesContainerBefore = shadowBefore.findContainer(ShadowType.F_ATTRIBUTES);
PrismProperty<String> attrBazBefore = new PrismProperty<>(new QName(MidPointConstants.NS_RI, "baz"), prismContext);
PrismPropertyDefinitionImpl<String> attrBazDefBefore = new PrismPropertyDefinitionImpl<>(attrBazQName, DOMUtil.XSD_STRING, prismContext);
attrBazDefBefore.setMaxOccurs(-1);
attrBazBefore.setDefinition(attrBazDefBefore);
attrBazBefore.addRealValue("BaZ1");
attrBazBefore.addRealValue("BaZ2");
attrBazBefore.addRealValue("BaZ3");
attributesContainerBefore.add(attrBazBefore);
System.out.println("\nAcc shadow");
System.out.println(shadowBefore.debugDump());
String oid = repositoryService.addObject(shadowBefore, null, parentResult);
// WHEN
TestUtil.displayWhen(TEST_NAME);
PrismObject<ShadowType> repoShadow = repositoryService.getObject(ShadowType.class, oid, null, parentResult);
// THEN
TestUtil.displayThen(TEST_NAME);
System.out.println("\nRepo shadow");
System.out.println(repoShadow.debugDump());
ObjectDelta<ShadowType> d = repoShadow.diff(shadowBefore);
System.out.println("\nDelta");
System.out.println(d.debugDump());
assertTrue("Delta after add is not empty", d.isEmpty());
PrismObjectDefinition<ShadowType> accountDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class);
Collection<ItemDelta> modifications = new ArrayList<ItemDelta>();
PropertyDelta pdelta = PropertyDelta.createModificationReplaceProperty((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_CHANNEL)), accountDefinition, "channel");
modifications.add(pdelta);
XMLGregorianCalendar modifyTimestampBefore = XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
pdelta = PropertyDelta.createModificationReplaceProperty((new ItemPath(ObjectType.F_METADATA, MetadataType.F_MODIFY_TIMESTAMP)), accountDefinition, modifyTimestampBefore);
modifications.add(pdelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
repositoryService.modifyObject(ShadowType.class, oid, modifications, getModifyOptions(), parentResult);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<ShadowType> afterModify = repositoryService.getObject(ShadowType.class, oid, null, parentResult);
System.out.println("\nAfter modify 1");
System.out.println(afterModify.debugDump());
MetadataType metadataAfter = afterModify.asObjectable().getMetadata();
assertEquals("Wrong modifyTimestamp", modifyTimestampBefore, metadataAfter.getModifyTimestamp());
PrismAsserts.assertEqualsPolyString("Wrong shadow name", "1234", afterModify.asObjectable().getName());
assertAttribute(afterModify, new QName(SchemaConstants.NS_ICF_SCHEMA, "uid"), "8daaeeae-f0c7-41c9-b258-2a3351aa8876");
assertAttribute(afterModify, "foo", "FOO");
assertAttribute(afterModify, "bar", "Bar1", "Bar2");
assertAttribute(afterModify, "baz", "BaZ1", "BaZ2", "BaZ3");
// GIVEN
XMLGregorianCalendar timestamp = XmlTypeConverter.createXMLGregorianCalendar(System.currentTimeMillis());
List<PropertyDelta<?>> syncSituationDeltas = SynchronizationUtils.createSynchronizationSituationDescriptionDelta(repoShadow, SynchronizationSituationType.LINKED, timestamp, null, false);
PropertyDelta<SynchronizationSituationType> syncSituationDelta = SynchronizationUtils.createSynchronizationSituationDelta(repoShadow, SynchronizationSituationType.LINKED);
syncSituationDeltas.add(syncSituationDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
repositoryService.modifyObject(ShadowType.class, oid, syncSituationDeltas, getModifyOptions(), parentResult);
// AssertJUnit.assertNull(afterModify.asObjectable().getObjectChange());
// THEN
TestUtil.displayThen(TEST_NAME);
afterModify = repositoryService.getObject(ShadowType.class, oid, null, parentResult);
System.out.println("\nAfter modify 2");
System.out.println(afterModify.debugDump());
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class ModifyTest method test150ModifyRoleAddInducements.
@Test
public void test150ModifyRoleAddInducements() throws Exception {
final String TEST_NAME = "test150ModifyRoleAddInducements";
TestUtil.displayTestTile(TEST_NAME);
OperationResult result = new OperationResult(TEST_NAME);
File roleFile = new File(TEST_DIR, "role-modify.xml");
//add first user
PrismObject<RoleType> role = prismContext.parseObject(roleFile);
String oid = repositoryService.addObject(role, null, result);
//modify second user name to "existingName"
ObjectModificationType modification = PrismTestUtil.parseAtomicValue(new File(TEST_DIR, "role-modify-change.xml"), ObjectModificationType.COMPLEX_TYPE);
modification.setOid(oid);
Collection<? extends ItemDelta> deltas = DeltaConvertor.toModifications(modification, RoleType.class, prismContext);
repositoryService.modifyObject(RoleType.class, oid, deltas, getModifyOptions(), result);
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
role = repositoryService.getObject(RoleType.class, oid, null, result);
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
PrismContainer container = role.findContainer(RoleType.F_INDUCEMENT);
assertEquals(2, container.size());
AssertJUnit.assertNotNull(container.getValue(2L));
AssertJUnit.assertNotNull(container.getValue(3L));
// modify role once more to check version progress
String version = role.getVersion();
repositoryService.modifyObject(RoleType.class, oid, new ArrayList<ItemDelta>(), getModifyOptions(), result);
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
role = repositoryService.getObject(RoleType.class, oid, null, result);
result.recomputeStatus();
AssertJUnit.assertTrue(result.isSuccess());
if (RepoModifyOptions.isExecuteIfNoChanges(getModifyOptions())) {
SqlRepoTestUtil.assertVersionProgress(version, role.getVersion());
} else {
assertEquals("Version has changed", version, role.getVersion());
}
}
Aggregations