Search in sources :

Example 21 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class DependencyProcessor method determineProjectionWaveDeprovision.

private <F extends ObjectType> LensProjectionContext determineProjectionWaveDeprovision(LensContext<F> context, LensProjectionContext projectionContext, ResourceObjectTypeDependencyType inDependency, List<ResourceObjectTypeDependencyType> depPath) throws PolicyViolationException {
    if (depPath == null) {
        depPath = new ArrayList<ResourceObjectTypeDependencyType>();
    }
    int determinedWave = 0;
    int determinedOrder = 0;
    // This needs to go in the reverse. We need to figure out who depends on us.
    for (DependencyAndSource ds : findReverseDependecies(context, projectionContext)) {
        LensProjectionContext dependencySourceContext = ds.sourceProjectionContext;
        ResourceObjectTypeDependencyType outDependency = ds.dependency;
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("DEP(rev): {}", outDependency);
        }
        if (inDependency != null && isHigerOrder(outDependency, inDependency)) {
            // otherwise we can end up in endless loop even for legal dependencies.
            continue;
        }
        checkForCircular(depPath, outDependency);
        depPath.add(outDependency);
        ResourceShadowDiscriminator refDiscr = new ResourceShadowDiscriminator(outDependency, projectionContext.getResource().getOid(), projectionContext.getKind());
        dependencySourceContext = determineProjectionWave(context, dependencySourceContext, outDependency, depPath);
        if (dependencySourceContext.getWave() + 1 > determinedWave) {
            determinedWave = dependencySourceContext.getWave() + 1;
            if (outDependency.getOrder() == null) {
                determinedOrder = 0;
            } else {
                determinedOrder = outDependency.getOrder();
            }
        }
        depPath.remove(outDependency);
    }
    LensProjectionContext resultAccountContext = projectionContext;
    if (projectionContext.getWave() >= 0 && projectionContext.getWave() != determinedWave) {
        // therefore there is a circular dependency. Therefore we need to create another context to split it.
        if (!projectionContext.isDelete()) {
            resultAccountContext = createAnotherContext(context, projectionContext, determinedOrder);
        }
    }
    //			LOGGER.trace("Wave for {}: {}", resultAccountContext.getResourceAccountType(), wave);
    resultAccountContext.setWave(determinedWave);
    return resultAccountContext;
}
Also used : ResourceObjectTypeDependencyType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectTypeDependencyType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 22 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class DependencyProcessor method findDependencyTargetContext.

/**
	 * Find context that has the closest order to the dependency.
	 */
private <F extends ObjectType> LensProjectionContext findDependencyTargetContext(LensContext<F> context, LensProjectionContext sourceProjContext, ResourceObjectTypeDependencyType dependency) {
    ResourceShadowDiscriminator refDiscr = new ResourceShadowDiscriminator(dependency, sourceProjContext.getResource().getOid(), sourceProjContext.getKind());
    LensProjectionContext selected = null;
    for (LensProjectionContext projectionContext : context.getProjectionContexts()) {
        if (!projectionContext.compareResourceShadowDiscriminator(refDiscr, false)) {
            continue;
        }
        int ctxOrder = projectionContext.getResourceShadowDiscriminator().getOrder();
        if (ctxOrder > refDiscr.getOrder()) {
            continue;
        }
        if (selected == null) {
            selected = projectionContext;
        } else {
            if (ctxOrder > selected.getResourceShadowDiscriminator().getOrder()) {
                selected = projectionContext;
            }
        }
    }
    return selected;
}
Also used : LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 23 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class TestAddAssociationLegacy method test100AddJackToGuests.

/**
     * Add entitlement for 'guests' to user jack - should be created without starting wf process
     */
@Test
public void test100AddJackToGuests() throws Exception {
    final String TEST_NAME = "test100AddJackToGuests";
    TestUtil.displayTestTile(this, TEST_NAME);
    Task modelTask = taskManager.createTaskInstance(TEST_NAME);
    OperationResult result = new OperationResult(TEST_NAME);
    modelTask.setOwner(repositoryService.getObject(UserType.class, USER_ADMINISTRATOR_OID, null, result));
    LensContext<UserType> context = createUserLensContext();
    fillContextWithUser(context, USER_JACK_OID, result);
    UserType jack = context.getFocusContext().getObjectCurrent().asObjectable();
    AssertJUnit.assertEquals("Jack has wrong number of accounts", 1, jack.getLinkRef().size());
    jackAccountShadowOid = jack.getLinkRef().get(0).getOid();
    ShadowType accountBefore = getObject(ShadowType.class, jackAccountShadowOid).asObjectable();
    assertEquals("Wrong # of jack's account associations", 1, accountBefore.getAssociation().size());
    assertHasAssociation(accountBefore, new QName("group"), GROUP_TESTERS_OID);
    LensProjectionContext accountContext = fillContextWithAccount(context, jackAccountShadowOid, modelTask, result);
    ObjectModificationType modElement = PrismTestUtil.parseAtomicValue(REQ_SHADOW_MODIFY_ADD_ENTITLEMENT_GUESTS, ObjectModificationType.COMPLEX_TYPE);
    ObjectDelta shadowDelta = DeltaConvertor.createObjectDelta(modElement, ShadowType.class, prismContext);
    shadowDelta.setOid(jackAccountShadowOid);
    accountContext.setPrimaryDelta(shadowDelta);
    HookOperationMode mode = clockwork.run(context, modelTask, result);
    assertEquals("Unexpected state of the context - workflow was started even if it should not", ModelState.FINAL, context.getState());
    assertEquals("Wrong mode after clockwork.run in " + context.getState(), HookOperationMode.FOREGROUND, mode);
    ShadowType accountAfter = getObject(ShadowType.class, jackAccountShadowOid).asObjectable();
    assertEquals("Wrong # of jack's account associations", 2, accountAfter.getAssociation().size());
    assertHasAssociation(accountAfter, new QName("group"), GROUP_TESTERS_OID);
    assertHasAssociation(accountAfter, new QName("group"), GROUP_GUESTS_OID);
}
Also used : ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) Task(com.evolveum.midpoint.task.api.Task) HookOperationMode(com.evolveum.midpoint.model.api.hooks.HookOperationMode) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) QName(javax.xml.namespace.QName) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 24 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class TestSynchronizationService method test010AddedAccountJack.

@Test
public void test010AddedAccountJack() throws Exception {
    final String TEST_NAME = "test010AddedAccountJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    MockLensDebugListener mockListener = new MockLensDebugListener();
    clockwork.setDebugListener(mockListener);
    PrismObject<ShadowType> accountShadowJack = repoAddObjectFromFile(ACCOUNT_SHADOW_JACK_DUMMY_FILE, result);
    accountShadowJackDummyOid = accountShadowJack.getOid();
    provisioningService.applyDefinition(accountShadowJack, task, result);
    assertNotNull("No oid in shadow", accountShadowJack.getOid());
    DummyAccount dummyAccount = new DummyAccount();
    dummyAccount.setName(ACCOUNT_JACK_DUMMY_USERNAME);
    dummyAccount.setPassword("deadMenTellNoTales");
    dummyAccount.setEnabled(true);
    dummyAccount.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Jack Sparrow");
    getDummyResource().addAccount(dummyAccount);
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(accountShadowJack);
    change.setResource(getDummyResourceObject());
    // WHEN
    synchronizationService.notifyChange(change, task, result);
    // THEN
    LensContext<UserType> context = mockListener.getLastSyncContext();
    display("Resulting context (as seen by debug listener)", context);
    assertNotNull("No resulting context (as seen by debug listener)", context);
    assertNull("Unexpected user primary delta", context.getFocusContext().getPrimaryDelta());
    assertSideEffectiveDeltasOnly(context.getFocusContext().getSecondaryDelta(), "user secondary delta", ActivationStatusType.ENABLED);
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ACCOUNT, null);
    LensProjectionContext accCtx = context.findProjectionContext(rat);
    assertNotNull("No account sync context for " + rat, accCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNLINKED, accCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, accCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected account primary delta", accCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(context.getFocusContext().getObjectOld().getOid(), accountShadowJack.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(accountShadowJackDummyOid);
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
    result.computeStatus();
    TestUtil.assertSuccess(result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Example 25 with LensProjectionContext

use of com.evolveum.midpoint.model.impl.lens.LensProjectionContext in project midpoint by Evolveum.

the class TestSynchronizationService method test210AddedGroupPirates.

@Test
public void test210AddedGroupPirates() throws Exception {
    final String TEST_NAME = "test210AddedGroupPirates";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    MockLensDebugListener mockListener = new MockLensDebugListener();
    clockwork.setDebugListener(mockListener);
    PrismObject<ShadowType> shadowPirates = repoAddObjectFromFile(SHADOW_PIRATES_DUMMY_FILE, result);
    provisioningService.applyDefinition(shadowPirates, task, result);
    assertNotNull("No oid in shadow", shadowPirates.getOid());
    DummyGroup dummyGroup = new DummyGroup();
    dummyGroup.setName(GROUP_PIRATES_DUMMY_NAME);
    dummyGroup.setEnabled(true);
    dummyGroup.addAttributeValues(DummyResourceContoller.DUMMY_GROUP_ATTRIBUTE_DESCRIPTION, "Scurvy Pirates");
    getDummyResource().addGroup(dummyGroup);
    ResourceObjectShadowChangeDescription change = new ResourceObjectShadowChangeDescription();
    change.setCurrentShadow(shadowPirates);
    change.setResource(getDummyResourceObject());
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    synchronizationService.notifyChange(change, task, result);
    // THEN
    TestUtil.displayWhen(TEST_NAME);
    result.computeStatus();
    TestUtil.assertSuccess(result);
    LensContext<UserType> context = mockListener.getLastSyncContext();
    display("Resulting context (as seen by debug listener)", context);
    assertNotNull("No resulting context (as seen by debug listener)", context);
    assertNotNull("No focus primary delta", context.getFocusContext().getPrimaryDelta());
    //        assertNotNull("No focus secondary delta", context.getFocusContext().getSecondaryDelta());
    assertFalse("No executed focus deltas", context.getFocusContext().getExecutedDeltas().isEmpty());
    ObjectDelta<UserType> userSecondaryDelta = (ObjectDelta<UserType>) context.getFocusContext().getExecutedDeltas().iterator().next().getObjectDelta();
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(getDummyResourceObject().getOid(), ShadowKindType.ENTITLEMENT, INTENT_GROUP);
    LensProjectionContext projCtx = context.findProjectionContext(rat);
    assertNotNull("No projection sync context for " + rat, projCtx);
    assertEquals("Wrong detected situation in context", SynchronizationSituationType.UNMATCHED, projCtx.getSynchronizationSituationDetected());
    assertEquals("Wrong resolved situation in context", SynchronizationSituationType.LINKED, projCtx.getSynchronizationSituationResolved());
    PrismAsserts.assertNoDelta("Unexpected projection primary delta", projCtx.getPrimaryDelta());
    //it this really expected?? delta was already executed, should we expect it in the secondary delta?
    //		assertNotNull("Missing account secondary delta", accCtx.getSecondaryDelta());
    //		assertIterationDelta(accCtx.getSecondaryDelta(), 0, "");
    assertLinked(RoleType.class, context.getFocusContext().getOid(), shadowPirates.getOid());
    PrismObject<ShadowType> shadow = getShadowModelNoFetch(shadowPirates.getOid());
    assertIteration(shadow, 0, "");
    assertSituation(shadow, SynchronizationSituationType.LINKED);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MockLensDebugListener(com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener) ResourceObjectShadowChangeDescription(com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyGroup(com.evolveum.icf.dummy.resource.DummyGroup) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)71 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)28 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)24 Task (com.evolveum.midpoint.task.api.Task)19 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)18 Test (org.testng.annotations.Test)17 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)14 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)12 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)11 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)10 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)8 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)7 SynchronizationPolicyDecision (com.evolveum.midpoint.model.api.context.SynchronizationPolicyDecision)5 LensContext (com.evolveum.midpoint.model.impl.lens.LensContext)5 PrismReference (com.evolveum.midpoint.prism.PrismReference)5 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)5