Search in sources :

Example 11 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TestPreviewChanges method test210GuybrushAddAccount.

@Test
public void test210GuybrushAddAccount() throws Exception {
    final String TEST_NAME = "test210GuybrushAddAccount";
    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_JACK_DUMMY_FILE);
    ObjectDelta<ShadowType> accountDelta = ObjectDelta.createAddDelta(account);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(accountDelta);
    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();
    assertNull("Unexpected model focus context", focusContext);
    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);
    // Decision does not matter now
    //		assertEquals("Wrong policy decision", SynchronizationPolicyDecision.ADD, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
    PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
    assertNotNull("No object in account primary add delta", accountToAddPrimary);
    assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
    PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
    assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    PrismAsserts.assertModifications(accountSecondaryDelta, 1);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) 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) PrismReference(com.evolveum.midpoint.prism.PrismReference) 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 12 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TestPreviewChanges method assertAddAccount.

private void assertAddAccount(ModelContext<UserType> modelContext, boolean expectFullNameDelta) {
    assertNotNull("Null model context", modelContext);
    ModelElementContext<UserType> focusContext = modelContext.getFocusContext();
    assertNotNull("Null model focus context", focusContext);
    assertNull("Unexpected focus primary delta: " + focusContext.getPrimaryDelta(), focusContext.getPrimaryDelta());
    assertSideEffectiveDeltasOnly(focusContext.getSecondaryDelta(), "focus secondary delta", ActivationStatusType.ENABLED);
    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.ADD, accContext.getSynchronizationPolicyDecision());
    ObjectDelta<ShadowType> accountPrimaryDelta = accContext.getPrimaryDelta();
    assertEquals(ChangeType.ADD, accountPrimaryDelta.getChangeType());
    PrismObject<ShadowType> accountToAddPrimary = accountPrimaryDelta.getObjectToAdd();
    assertNotNull("No object in account primary add delta", accountToAddPrimary);
    assertEquals(getDummyResourceController().getAccountObjectClass(), accountToAddPrimary.findProperty(ShadowType.F_OBJECT_CLASS).getRealValue());
    PrismReference resourceRef = accountToAddPrimary.findReference(ShadowType.F_RESOURCE_REF);
    assertEquals(getDummyResourceObject().getOid(), resourceRef.getOid());
    ObjectDelta<ShadowType> accountSecondaryDelta = accContext.getSecondaryDelta();
    assertEquals(ChangeType.MODIFY, accountSecondaryDelta.getChangeType());
    PropertyDelta<String> fullNameDelta = accountSecondaryDelta.findPropertyDelta(dummyResourceCtl.getAttributeFullnamePath());
    if (expectFullNameDelta) {
        assertNotNull("No full name delta in account secondary delta", fullNameDelta);
        PrismAsserts.assertReplace(fullNameDelta, "Jack Sparrow");
        PrismAsserts.assertOrigin(fullNameDelta, OriginType.OUTBOUND);
    } else {
        assertNull("Unexpected full name delta in account secondary delta", fullNameDelta);
    }
    PrismObject<ShadowType> accountNew = accContext.getObjectNew();
    IntegrationTestTools.assertIcfsNameAttribute(accountNew, "jack");
    IntegrationTestTools.assertAttribute(accountNew, dummyResourceCtl.getAttributeFullnameQName(), "Jack Sparrow");
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) PrismReference(com.evolveum.midpoint.prism.PrismReference) ModelProjectionContext(com.evolveum.midpoint.model.api.context.ModelProjectionContext) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)

Example 13 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TaskQuartzImpl method setOwner.

@Override
public void setOwner(PrismObject<UserType> owner) {
    if (isPersistent()) {
        throw new IllegalStateException("setOwner method can be called only on transient tasks!");
    }
    PrismReference ownerRef;
    try {
        ownerRef = taskPrism.findOrCreateReference(TaskType.F_OWNER_REF);
    } catch (SchemaException e) {
        // This should not happen
        throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
    }
    ownerRef.getValue().setObject(owner);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 14 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TaskQuartzImpl method setObjectTransient.

@Override
public void setObjectTransient(PrismObject object) {
    if (object == null) {
        PrismReference objectRef = taskPrism.findReference(TaskType.F_OBJECT_REF);
        if (objectRef != null) {
            taskPrism.getValue().remove(objectRef);
        }
    } else {
        PrismReference objectRef;
        try {
            objectRef = taskPrism.findOrCreateReference(TaskType.F_OBJECT_REF);
        } catch (SchemaException e) {
            // This should not happen
            throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
        }
        objectRef.getValue().setObject(object);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Example 15 with PrismReference

use of com.evolveum.midpoint.prism.PrismReference in project midpoint by Evolveum.

the class TaskQuartzImpl method setObjectRefTransient.

public void setObjectRefTransient(ObjectReferenceType objectRefType) {
    PrismReference objectRef;
    try {
        objectRef = taskPrism.findOrCreateReference(TaskType.F_OBJECT_REF);
    } catch (SchemaException e) {
        // This should not happen
        throw new IllegalStateException("Internal schema error: " + e.getMessage(), e);
    }
    objectRef.getValue().setOid(objectRefType.getOid());
    objectRef.getValue().setTargetType(objectRefType.getType());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismReference(com.evolveum.midpoint.prism.PrismReference)

Aggregations

PrismReference (com.evolveum.midpoint.prism.PrismReference)41 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)15 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 PrismObject (com.evolveum.midpoint.prism.PrismObject)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)8 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 QName (javax.xml.namespace.QName)7 Test (org.testng.annotations.Test)7 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)6 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)5 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)5 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4