Search in sources :

Example 41 with ItemDelta

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;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 42 with ItemDelta

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;
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 43 with ItemDelta

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();
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 44 with ItemDelta

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 45 with ItemDelta

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();
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Aggregations

ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)185 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)87 Test (org.testng.annotations.Test)66 ArrayList (java.util.ArrayList)64 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)56 Task (com.evolveum.midpoint.task.api.Task)40 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)33 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)30 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)26 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)21 QName (javax.xml.namespace.QName)21 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)20 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)19 LookupTableType (com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType)15 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)15 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)14 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)14 PrismObject (com.evolveum.midpoint.prism.PrismObject)13 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)12