use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class OrgClosureManager method getParentOidsToAdd.
// filters out those OIDs that are already present in originalObject (beware, it may be null)
private Set<String> getParentOidsToAdd(Collection<? extends ItemDelta> modifications, PrismObject<? extends ObjectType> originalObject) {
Set<String> oids = new HashSet<>();
Set<String> existingOids = getParentOidsFromObject(originalObject);
for (ItemDelta delta : modifications) {
if (delta.getValuesToAdd() != null) {
for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToAdd()) {
String oid = val.getOid();
if (!existingOids.contains(oid)) {
// if it's already there, we don't want to add it
oids.add(oid);
}
}
}
if (delta.getValuesToReplace() != null) {
// at this point we can assume this is not mixed with DELETE or ADD deltas
// we mark all 'new' values in REPLACE delta not present in existing object as being added
// and we do this for the latest REPLACE ItemDelta
oids = new HashSet<>();
for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToReplace()) {
String oid = val.getOid();
if (!existingOids.contains(oid)) {
// if it's already there, we don't want to add it
oids.add(oid);
}
}
}
}
return oids;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class OrgClosureManager method getParentOidsToDelete.
private Set<String> getParentOidsToDelete(Collection<? extends ItemDelta> modifications, PrismObject<? extends ObjectType> originalObject) {
Validate.notNull(originalObject);
Set<String> oids = new HashSet<>();
Set<String> existingOids = getParentOidsFromObject(originalObject);
for (ItemDelta delta : modifications) {
if (delta.getValuesToDelete() != null) {
for (PrismReferenceValue val : (Collection<PrismReferenceValue>) delta.getValuesToDelete()) {
String oid = val.getOid();
if (existingOids.contains(oid)) {
// if it's not there, we do not want to delete it!
oids.add(oid);
}
}
}
if (delta.getValuesToReplace() != null) {
// at this point we can assume this is not mixed with DELETE or ADD deltas
// we mark all existing values not present in the new set as being removed!
// and we do this for the latest REPLACE ItemDelta
oids = new HashSet<>();
for (String existingOid : existingOids) {
boolean found = false;
for (PrismReferenceValue newVal : (Collection<PrismReferenceValue>) delta.getValuesToReplace()) {
if (existingOid.equals(newVal.getOid())) {
found = true;
break;
}
}
if (!found) {
// if existing OID was not found in values to REPLACE, it should be deleted
oids.add(existingOid);
}
}
}
}
return oids;
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestOrgStruct method executeConflictPlusAndMinus.
protected void executeConflictPlusAndMinus(String TEST_NAME) throws Exception {
Task task = taskManager.createTaskInstance(TestOrgStruct.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ItemDelta<?, ?>> modifications = new ArrayList<>();
modifications.add((createAssignmentModification(ROLE_DEFENDER_OID, RoleType.COMPLEX_TYPE, null, null, null, true)));
modifications.add((createAssignmentModification(ORG_MINISTRY_OF_DEFENSE_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);
// 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_DEFENSE_OID);
assertAssignedOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
assertNotAssignedOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, null);
assertHasOrgs(userJack, ORG_MINISTRY_OF_DEFENSE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
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 test221JackAssignScummBarAndSaveElaine.
/**
* Assign jack to both functional and project orgstruct.
* Implemented to check org struct reconciliation in test223.
*/
@Test
public void test221JackAssignScummBarAndSaveElaine() throws Exception {
final String TEST_NAME = "test221JackAssignScummBarAndSaveElaine";
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_SCUMM_BAR_OID, OrgType.COMPLEX_TYPE, null, null, null, true));
modifications.add(createAssignmentModification(ORG_SAVE_ELAINE_OID, OrgType.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, ORG_SCUMM_BAR_OID, ORG_SAVE_ELAINE_OID);
assertHasOrgs(userJack, ORG_MINISTRY_OF_OFFENSE_OID, ORG_SCUMM_BAR_OID, ORG_SAVE_ELAINE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
// Postcondition
assertMonkeyIslandOrgSanity();
}
use of com.evolveum.midpoint.prism.delta.ItemDelta in project midpoint by Evolveum.
the class TestOrgStruct method test305JackConflictZeroAndMinus.
/**
* Conflict: removing the role assignment (that should remove org assignment), while keeping explicit org assignment present
*/
@Test
public void test305JackConflictZeroAndMinus() throws Exception {
final String TEST_NAME = "test305JackConflictZeroAndMinus";
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(ROLE_DEFENDER_OID, RoleType.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);
// WHEN
modelService.executeChanges(deltas, null, task, result);
// THEN
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User jack after", userJack);
assertUserOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, ORG_MINISTRY_OF_DEFENSE_OID);
assertAssignedOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, SchemaConstants.ORG_MANAGER);
assertHasOrg(userJack, ORG_MINISTRY_OF_DEFENSE_OID, null);
// Postcondition
assertMonkeyIslandOrgSanity();
}
Aggregations