Search in sources :

Example 46 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.

the class TestMultiResource method test300AddAndAssignRelative.

@Test
public void test300AddAndAssignRelative() throws Exception {
    final String TEST_NAME = "test300AddAndAssignRelative";
    TestUtil.displayTestTile(TEST_NAME);
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.RELATIVE);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    // Add default dummy account to jack without assigning it.
    // In relative mode this account should shay untouched while we play with assignments and
    // unsassignements of other accounts
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMY_FILE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_JACK_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationAdd(UserType.F_LINK_REF, getUserDefinition(), accountRefVal);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(userDelta);
    modelService.executeChanges(deltas, null, task, result);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    PrismObject<UserType> userJack = getUser(USER_JACK_OID);
    display("User after default dummy account add", userJack);
    assertUserJack(userJack);
    assertAccount(userJack, RESOURCE_DUMMY_OID);
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    assignAccount(USER_JACK_OID, RESOURCE_DUMMY_BLUE_OID, null, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    userJack = getUser(USER_JACK_OID);
    display("User after red dummy assignment", userJack);
    assertUserJack(userJack);
    assertAccount(userJack, RESOURCE_DUMMY_OID);
    assertAccount(userJack, RESOURCE_DUMMY_BLUE_OID);
    assertLinks(userJack, 2);
    String accountOid = getLinkRefOid(userJack, RESOURCE_DUMMY_BLUE_OID);
    // Check shadow
    PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
    assertAccountShadowRepo(accountShadow, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyBlueType);
    // Check account
    PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
    assertAccountShadowModel(accountModel, accountOid, ACCOUNT_JACK_DUMMY_USERNAME, resourceDummyBlueType);
    assertDefaultDummyAccount(ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
    assertDummyAccount(RESOURCE_DUMMY_BLUE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) Collection(java.util.Collection) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractPasswordTest(com.evolveum.midpoint.model.intest.password.AbstractPasswordTest)

Example 47 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.

the class TestPreviewChanges method test200ModifyUserGuybrushDeleteAccount.

@Test
public void test200ModifyUserGuybrushDeleteAccount() throws Exception {
    final String TEST_NAME = "test200ModifyUserGuybrushDeleteAccount";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestPreviewChanges.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    assumeAssignmentPolicy(AssignmentPolicyEnforcementType.NONE);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_GUYBRUSH_DUMMY_FILE);
    ObjectDelta<UserType> userDelta = ObjectDelta.createEmptyModifyDelta(UserType.class, USER_GUYBRUSH_OID, prismContext);
    PrismReferenceValue accountRefVal = new PrismReferenceValue();
    accountRefVal.setObject(account);
    ReferenceDelta accountDelta = ReferenceDelta.createModificationDelete(UserType.F_LINK_REF, getUserDefinition(), account);
    userDelta.addModification(accountDelta);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
    display("Input deltas: ", deltas);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    ModelContext<UserType> modelContext = modelInteractionService.previewChanges(deltas, new ModelExecuteOptions(), task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    display("Preview context", modelContext);
    assertNotNull("Null model context", modelContext);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
    assertNotNull("Null model focus context", focusContext);
    assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
    assertSideEffectiveDeltasOnly("focus secondary delta", focusContext.getSecondaryDelta());
    Collection<? extends ModelProjectionContext> projectionContexts = modelContext.getProjectionContexts();
    assertNotNull("Null model projection context list", projectionContexts);
    assertEquals("Unexpected number of projection contexts", 1, projectionContexts.size());
    ModelProjectionContext accContext = projectionContexts.iterator().next();
    assertNotNull("Null model projection context", accContext);
    assertEquals("Wrong policy decision", SynchronizationPolicyDecision.DELETE, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertEquals(ChangeType.DELETE, accountPrimaryDelta.getChangeType());
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 48 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.

the class OrgClosureManager method filterParentRefDeltas.

private List<ReferenceDelta> filterParentRefDeltas(Collection<? extends ItemDelta> modifications) {
    boolean containsAdd = false, containsDelete = false, containsReplace = false;
    List<ReferenceDelta> deltas = new ArrayList<>();
    if (modifications == null) {
        return deltas;
    }
    for (ItemDelta delta : modifications) {
        if (!QNameUtil.match(ObjectType.F_PARENT_ORG_REF, delta.getElementName())) {
            // TODO is this OK?
            continue;
        }
        if (delta.isAdd()) {
            containsAdd = true;
        }
        if (delta.isDelete()) {
            containsDelete = true;
        }
        if (delta.isReplace()) {
            if (containsReplace) {
                throw new IllegalStateException("Unsupported combination of parentOrgRef operations: more REPLACE ItemDeltas");
            }
            containsReplace = true;
        }
        deltas.add((ReferenceDelta) delta);
    }
    if (containsReplace && (containsAdd || containsDelete)) {
        throw new IllegalStateException("Unsupported combination of parentOrgRef operations: REPLACE with either ADD or DELETE");
    }
    return deltas;
}
Also used : ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Example 49 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.

the class ModifyTest method test032ModifyTaskObjectRef.

@Test
public void test032ModifyTaskObjectRef() throws Exception {
    final String TEST_NAME = "test032ModifyTaskObjectRef";
    TestUtil.displayTestTile(TEST_NAME);
    OperationResult result = new OperationResult(TEST_NAME);
    File taskFile = new File(TEST_DIR, "task.xml");
    System.out.println("ADD");
    PrismObject<TaskType> task = prismContext.parseObject(taskFile);
    repositoryService.addObject(task, null, result);
    final String taskOid = "00000000-0000-0000-0000-123450000001";
    AssertJUnit.assertNotNull(taskOid);
    System.out.println("GET");
    PrismObject<TaskType> getTask = null;
    getTask = repositoryService.getObject(TaskType.class, taskOid, null, result);
    String lastVersion = getTask.getVersion();
    AssertJUnit.assertTrue(task.equivalent(getTask));
    TaskType taskType = null;
    taskType = getTask.asObjectable();
    AssertJUnit.assertNull(taskType.getObjectRef());
    Collection modifications = new ArrayList();
    PrismObjectDefinition objectDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(TaskType.class);
    PrismReferenceDefinition def = objectDef.findReferenceDefinition(TaskType.F_OBJECT_REF);
    System.out.println("MODIFY");
    ObjectReferenceType objectRef = null;
    ReferenceDelta delta = new ReferenceDelta(def, prismContext);
    delta.addValueToAdd(new PrismReferenceValue("1", ResourceType.COMPLEX_TYPE));
    modifications.add(delta);
    repositoryService.modifyObject(TaskType.class, taskOid, modifications, getModifyOptions(), result);
    System.out.println("GET");
    getTask = repositoryService.getObject(TaskType.class, taskOid, null, result);
    taskType = getTask.asObjectable();
    AssertJUnit.assertNotNull(taskType.getObjectRef());
    objectRef = taskType.getObjectRef();
    assertEquals("1", objectRef.getOid());
    SqlRepoTestUtil.assertVersionProgress(lastVersion, getTask.getVersion());
    lastVersion = getTask.getVersion();
    checkReference(taskOid);
    System.out.println("MODIFY");
    modifications.clear();
    delta = new ReferenceDelta(def, prismContext);
    delta.addValueToDelete(new PrismReferenceValue("1", ResourceType.COMPLEX_TYPE));
    delta.addValueToAdd(new PrismReferenceValue("2", ResourceType.COMPLEX_TYPE));
    modifications.add(delta);
    repositoryService.modifyObject(TaskType.class, taskOid, modifications, getModifyOptions(), result);
    checkReference(taskOid);
    getTask = repositoryService.getObject(TaskType.class, taskOid, null, result);
    taskType = getTask.asObjectable();
    AssertJUnit.assertNotNull(taskType.getObjectRef());
    objectRef = taskType.getObjectRef();
    assertEquals("2", objectRef.getOid());
    LOGGER.info(PrismTestUtil.serializeObjectToString(taskType.asPrismObject()));
    SqlRepoTestUtil.assertVersionProgress(lastVersion, getTask.getVersion());
    lastVersion = getTask.getVersion();
    modifications.clear();
    delta = new ReferenceDelta(def, prismContext);
    delta.addValueToDelete(new PrismReferenceValue("2", ResourceType.COMPLEX_TYPE));
    delta.addValueToAdd(new PrismReferenceValue("1", ResourceType.COMPLEX_TYPE));
    modifications.add(delta);
    repositoryService.modifyObject(TaskType.class, taskOid, modifications, getModifyOptions(), result);
    checkReference(taskOid);
    getTask = repositoryService.getObject(TaskType.class, taskOid, null, result);
    taskType = getTask.asObjectable();
    AssertJUnit.assertNotNull(taskType.getObjectRef());
    objectRef = taskType.getObjectRef();
    assertEquals("1", objectRef.getOid());
    SqlRepoTestUtil.assertVersionProgress(lastVersion, getTask.getVersion());
    lastVersion = getTask.getVersion();
}
Also used : ArrayList(java.util.ArrayList) Collection(java.util.Collection) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) File(java.io.File) Test(org.testng.annotations.Test)

Example 50 with ReferenceDelta

use of com.evolveum.midpoint.prism.delta.ReferenceDelta in project midpoint by Evolveum.

the class ModifyUser method test100ModifyUserApproverMetadata.

@Test
public void test100ModifyUserApproverMetadata() throws Exception {
    PrismObjectDefinition userDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
    ReferenceDelta delta1 = ReferenceDelta.createModificationAdd(new ItemPath(UserType.F_METADATA, MetadataType.F_CREATE_APPROVER_REF), userDefinition, new PrismReferenceValue("target-oid-1", UserType.COMPLEX_TYPE));
    ReferenceDelta delta2 = ReferenceDelta.createModificationAdd(new ItemPath(UserType.F_METADATA, MetadataType.F_MODIFY_APPROVER_REF), userDefinition, // the same as in delta1
    new PrismReferenceValue("target-oid-1", UserType.COMPLEX_TYPE));
    repositoryService.modifyObject(UserType.class, userOid, Arrays.asList(delta1, delta2), new OperationResult("asdf"));
}
Also used : PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ReferenceDelta(com.evolveum.midpoint.prism.delta.ReferenceDelta) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) Test(org.testng.annotations.Test)

Aggregations

ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)49 Task (com.evolveum.midpoint.task.api.Task)44 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)42 Test (org.testng.annotations.Test)41 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)33 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)27 Collection (java.util.Collection)21 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 ArrayList (java.util.ArrayList)12 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)11 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)8 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)7 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)6