Search in sources :

Example 16 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class AbstractModelImplementationIntegrationTest method fillContextWithAccount.

protected LensProjectionContext fillContextWithAccount(LensContext<UserType> context, PrismObject<ShadowType> account, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    ShadowType accountType = account.asObjectable();
    String resourceOid = accountType.getResourceRef().getOid();
    ResourceType resourceType = provisioningService.getObject(ResourceType.class, resourceOid, null, task, result).asObjectable();
    applyResourceSchema(accountType, resourceType);
    ResourceShadowDiscriminator rat = new ResourceShadowDiscriminator(resourceOid, ShadowKindType.ACCOUNT, ShadowUtil.getIntent(accountType));
    LensProjectionContext accountSyncContext = context.findOrCreateProjectionContext(rat);
    accountSyncContext.setOid(account.getOid());
    accountSyncContext.setLoadedObject(account);
    accountSyncContext.setResource(resourceType);
    accountSyncContext.setExists(true);
    context.rememberResource(resourceType);
    return accountSyncContext;
}
Also used : LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 17 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class AssignmentProcessor method evaluateConstructions.

private <F extends FocusType> void evaluateConstructions(LensContext<F> context, Collection<EvaluatedAssignmentImpl<F>> evaluatedAssignments, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (evaluatedAssignments == null) {
        return;
    }
    ObjectDeltaObject<F> focusOdo = null;
    LensFocusContext<F> focusContext = context.getFocusContext();
    if (focusContext != null) {
        focusOdo = focusContext.getObjectDeltaObject();
    }
    Iterator<EvaluatedAssignmentImpl<F>> iterator = evaluatedAssignments.iterator();
    while (iterator.hasNext()) {
        EvaluatedAssignmentImpl<F> evaluatedAssignment = iterator.next();
        try {
            evaluatedAssignment.evaluateConstructions(focusOdo, context.getSystemConfiguration(), task, result);
        } catch (ObjectNotFoundException ex) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
            }
            iterator.remove();
            if (!ModelExecuteOptions.isForce(context.getOptions())) {
                ModelUtils.recordFatalError(result, ex);
            }
        } catch (SchemaException ex) {
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing of assignment resulted in error {}: {}", ex, SchemaDebugUtil.prettyPrint(evaluatedAssignment.getAssignmentType()));
            }
            ModelUtils.recordFatalError(result, ex);
            String resourceOid = FocusTypeUtil.determineConstructionResource(evaluatedAssignment.getAssignmentType());
            if (resourceOid == null) {
                // This is a role assignment or something like that. Just throw the original exception for now.
                throw ex;
            }
            ResourceShadowDiscriminator rad = new ResourceShadowDiscriminator(resourceOid, FocusTypeUtil.determineConstructionKind(evaluatedAssignment.getAssignmentType()), FocusTypeUtil.determineConstructionIntent(evaluatedAssignment.getAssignmentType()));
            LensProjectionContext accCtx = context.findProjectionContext(rad);
            if (accCtx != null) {
                accCtx.setSynchronizationPolicyDecision(SynchronizationPolicyDecision.BROKEN);
            }
            iterator.remove();
        }
    }
}
Also used : EvaluatedAssignmentImpl(com.evolveum.midpoint.model.impl.lens.EvaluatedAssignmentImpl) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 18 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class LensProjectionContext method fromLensProjectionContextType.

public static LensProjectionContext fromLensProjectionContextType(LensProjectionContextType projectionContextType, LensContext lensContext, Task task, OperationResult result) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
    String objectTypeClassString = projectionContextType.getObjectTypeClass();
    if (StringUtils.isEmpty(objectTypeClassString)) {
        throw new SystemException("Object type class is undefined in LensProjectionContextType");
    }
    ResourceShadowDiscriminator resourceShadowDiscriminator = ResourceShadowDiscriminator.fromResourceShadowDiscriminatorType(projectionContextType.getResourceShadowDiscriminator());
    LensProjectionContext projectionContext = new LensProjectionContext(lensContext, resourceShadowDiscriminator);
    projectionContext.retrieveFromLensElementContextType(projectionContextType, task, result);
    if (projectionContextType.getSyncDelta() != null) {
        projectionContext.syncDelta = DeltaConvertor.createObjectDelta(projectionContextType.getSyncDelta(), lensContext.getPrismContext());
    } else {
        projectionContext.syncDelta = null;
    }
    ObjectDeltaType secondaryDeltaType = projectionContextType.getSecondaryDelta();
    projectionContext.secondaryDelta = secondaryDeltaType != null ? (ObjectDelta) DeltaConvertor.createObjectDelta(secondaryDeltaType, lensContext.getPrismContext()) : null;
    ObjectType object = projectionContextType.getObjectNew() != null ? projectionContextType.getObjectNew() : projectionContextType.getObjectOld();
    projectionContext.fixProvisioningTypeInDelta(projectionContext.secondaryDelta, object, task, result);
    projectionContext.wave = projectionContextType.getWave() != null ? projectionContextType.getWave() : 0;
    projectionContext.fullShadow = projectionContextType.isFullShadow() != null ? projectionContextType.isFullShadow() : false;
    projectionContext.isAssigned = projectionContextType.isIsAssigned() != null ? projectionContextType.isIsAssigned() : false;
    projectionContext.isAssignedOld = projectionContextType.isIsAssignedOld() != null ? projectionContextType.isIsAssignedOld() : false;
    projectionContext.isActive = projectionContextType.isIsActive() != null ? projectionContextType.isIsActive() : false;
    projectionContext.isLegal = projectionContextType.isIsLegal();
    projectionContext.isLegalOld = projectionContextType.isIsLegalOld();
    projectionContext.isExists = projectionContextType.isIsExists() != null ? projectionContextType.isIsExists() : false;
    projectionContext.synchronizationPolicyDecision = SynchronizationPolicyDecision.fromSynchronizationPolicyDecisionType(projectionContextType.getSynchronizationPolicyDecision());
    projectionContext.doReconciliation = projectionContextType.isDoReconciliation() != null ? projectionContextType.isDoReconciliation() : false;
    projectionContext.synchronizationSituationDetected = projectionContextType.getSynchronizationSituationDetected();
    projectionContext.synchronizationSituationResolved = projectionContextType.getSynchronizationSituationResolved();
    projectionContext.accountPasswordPolicy = projectionContextType.getAccountPasswordPolicy();
    projectionContext.syncAbsoluteTrigger = projectionContextType.isSyncAbsoluteTrigger();
    return projectionContext;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 19 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class LensUtil method findRelatedContexts.

/**
	 * Returns a list of context that have equivalent discriminator with the reference context. Ordered by "order" in the
	 * discriminator.
	 */
public static <F extends ObjectType> List<LensProjectionContext> findRelatedContexts(LensContext<F> context, LensProjectionContext refProjCtx) {
    List<LensProjectionContext> projCtxs = new ArrayList<LensProjectionContext>();
    ResourceShadowDiscriminator refDiscr = refProjCtx.getResourceShadowDiscriminator();
    if (refDiscr == null) {
        return projCtxs;
    }
    for (LensProjectionContext aProjCtx : context.getProjectionContexts()) {
        ResourceShadowDiscriminator aDiscr = aProjCtx.getResourceShadowDiscriminator();
        if (refDiscr.equivalent(aDiscr)) {
            projCtxs.add(aProjCtx);
        }
    }
    Comparator<? super LensProjectionContext> orderComparator = new Comparator<LensProjectionContext>() {

        @Override
        public int compare(LensProjectionContext ctx1, LensProjectionContext ctx2) {
            int order1 = ctx1.getResourceShadowDiscriminator().getOrder();
            int order2 = ctx2.getResourceShadowDiscriminator().getOrder();
            return Integer.compare(order1, order2);
        }
    };
    Collections.sort(projCtxs, orderComparator);
    return projCtxs;
}
Also used : ArrayList(java.util.ArrayList) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) Comparator(java.util.Comparator)

Example 20 with ResourceShadowDiscriminator

use of com.evolveum.midpoint.schema.ResourceShadowDiscriminator in project midpoint by Evolveum.

the class TestSynchronizationService method test100AddedAccountJack.

@Test
public void test100AddedAccountJack() throws Exception {
    final String TEST_NAME = "test100AddedAccountJack";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = taskManager.createTaskInstance(TestSynchronizationService.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    PrismObject<UserType> userBefore = getUser(USER_JACK_OID);
    assertLinks(userBefore, 0);
    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);
    display("Dummy resource before", getDummyResource());
    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);
    PrismObject<UserType> userAfter = getUser(USER_JACK_OID);
    assertLinks(userAfter, 1);
    assertLinked(userAfter, shadow);
}
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) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)78 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)41 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)34 Task (com.evolveum.midpoint.task.api.Task)30 Test (org.testng.annotations.Test)30 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)28 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)18 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)17 ResourceObjectShadowChangeDescription (com.evolveum.midpoint.provisioning.api.ResourceObjectShadowChangeDescription)17 ModelProjectionContext (com.evolveum.midpoint.model.api.context.ModelProjectionContext)11 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)10 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)9 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)9 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)9 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)8 MockLensDebugListener (com.evolveum.midpoint.model.impl.util.mock.MockLensDebugListener)8 PrismObject (com.evolveum.midpoint.prism.PrismObject)8 QName (javax.xml.namespace.QName)7 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)6