Search in sources :

Example 1 with CorrelationResult

use of com.evolveum.midpoint.model.api.correlator.CorrelationResult in project midpoint by Evolveum.

the class BaseCorrelator method correlate.

@Override
@NotNull
public CorrelationResult correlate(@NotNull CorrelationContext correlationContext, @NotNull OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException {
    OperationResult result = parentResult.subresult(getClass().getName() + OP_CORRELATE_SUFFIX).build();
    try {
        logger.trace("Correlating:\n{}", correlationContext.debugDumpLazily(1));
        CorrelationResult correlationResult = correlateInternal(correlationContext, result);
        logger.trace("Result:\n{}", correlationResult.debugDumpLazily(1));
        result.addArbitraryObjectAsReturn("correlationResult", correlationResult);
        return correlationResult;
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.close();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CorrelationResult(com.evolveum.midpoint.model.api.correlator.CorrelationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CorrelationResult

use of com.evolveum.midpoint.model.api.correlator.CorrelationResult in project midpoint by Evolveum.

the class CorrelationProcessing method correlateInRootCorrelator.

@NotNull
private CorrelationResult correlateInRootCorrelator(OperationResult result) {
    CorrelationResult correlationResult;
    try {
        correlationResult = instantiateRootCorrelator(result).correlate(correlationContext, result);
    } catch (Exception e) {
        // Other kinds of Throwable are intentionally passed upwards
        // The exception will be (probably) rethrown, so the stack trace is not strictly necessary here.
        LoggingUtils.logException(LOGGER, "Correlation ended with an exception", e);
        correlationResult = CorrelationResult.error(e);
    }
    LOGGER.trace("Correlation result:\n{}", correlationResult.debugDumpLazily(1));
    if (correlationResult.isDone()) {
        thisCorrelationEnd = XmlTypeConverter.createXMLGregorianCalendar();
    } else {
        thisCorrelationEnd = null;
    }
    return correlationResult;
}
Also used : CorrelationResult(com.evolveum.midpoint.model.api.correlator.CorrelationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CorrelationResult

use of com.evolveum.midpoint.model.api.correlator.CorrelationResult in project midpoint by Evolveum.

the class CorrelationProcessing method correlate.

@NotNull
public CorrelationResult correlate(OperationResult parentResult) throws CommonException {
    assert syncCtx.getLinkedOwner() == null;
    CorrelationResult existing = getResultFromExistingState(parentResult);
    if (existing != null) {
        LOGGER.debug("Result determined from existing correlation state in shadow: {}", existing.getSituation());
        return existing;
    }
    OperationResult result = parentResult.subresult(OP_CORRELATE).build();
    try {
        CorrelationResult correlationResult = correlateInRootCorrelator(result);
        applyResultToShadow(correlationResult);
        if (correlationResult.isUncertain()) {
            processUncertainResult(result);
        } else if (correlationResult.isError()) {
        // Nothing to do here
        } else {
            processFinalResult(result);
        }
        result.addArbitraryObjectAsReturn("correlationResult", correlationResult);
        return correlationResult;
    } catch (Throwable t) {
        result.recordFatalError(t);
        throw t;
    } finally {
        result.close();
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CorrelationResult(com.evolveum.midpoint.model.api.correlator.CorrelationResult) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CorrelationResult

use of com.evolveum.midpoint.model.api.correlator.CorrelationResult in project midpoint by Evolveum.

the class SynchronizationServiceImpl method determineSituationWithCorrelators.

/**
 * EITHER (todo update the description):
 *
 * account is not linked to user. you have to use correlation and
 * confirmation rule to be sure user for this account doesn't exists
 * resourceShadow only contains the data that were in the repository before
 * the change. But the correlation/confirmation should work on the updated
 * data. Therefore let's apply the changes before running
 * correlation/confirmation
 *
 * OR
 *
 * We need to update the correlator state.
 */
private <F extends FocusType> void determineSituationWithCorrelators(SynchronizationContext<F> syncCtx, ResourceObjectShadowChangeDescription change, OperationResult result) throws CommonException {
    if (change.isDelete()) {
        // account was deleted and it was not linked; there is nothing to do (not even updating the correlators)
        if (syncCtx.getSituation() == null) {
            syncCtx.setSituation(SynchronizationSituationType.DELETED);
        }
        return;
    }
    if (!syncCtx.isCorrelatorsUpdateRequested() && syncCtx.getCorrelatedOwner() != null) {
        // e.g. from sync sorter
        LOGGER.trace("Correlated owner present in synchronization context: {}", syncCtx.getCorrelatedOwner());
        if (syncCtx.getSituation() == null) {
            syncCtx.setSituation(SynchronizationSituationType.UNLINKED);
        }
        return;
    }
    PrismObject<? extends ShadowType> resourceObject = change.getShadowedResourceObject();
    ResourceType resource = change.getResource().asObjectable();
    setupResourceRefInShadowIfNeeded(resourceObject.asObjectable(), resource);
    evaluatePreMappings(syncCtx, result);
    if (syncCtx.isUpdatingCorrelatorsOnly()) {
        new CorrelationProcessing<>(syncCtx, beans).update(result);
        return;
    }
    CorrelationResult correlationResult = new CorrelationProcessing<>(syncCtx, beans).correlate(result);
    LOGGER.debug("Correlation result:\n{}", correlationResult.debugDumpLazily(1));
    SynchronizationSituationType state;
    F owner;
    switch(correlationResult.getSituation()) {
        case EXISTING_OWNER:
            state = SynchronizationSituationType.UNLINKED;
            // noinspection unchecked
            owner = (F) correlationResult.getOwner();
            break;
        case NO_OWNER:
            state = SynchronizationSituationType.UNMATCHED;
            owner = null;
            break;
        case UNCERTAIN:
        case ERROR:
            state = SynchronizationSituationType.DISPUTED;
            owner = null;
            break;
        default:
            throw new AssertionError(correlationResult.getSituation());
    }
    LOGGER.debug("Determined synchronization situation: {} with owner: {}", state, owner);
    syncCtx.setCorrelatedOwner(owner);
    if (syncCtx.getSituation() == null) {
        syncCtx.setSituation(state);
    }
    if (correlationResult.isError()) {
        // This is a very crude and preliminary error handling: we just write pending deltas to the shadow
        // (if there are any), to have a record of the unsuccessful correlation. Normally, we should do this
        // along with the other sync metadata. But the error handling in this class is not ready for it (yet).
        savePendingDeltas(syncCtx, result);
        correlationResult.throwCommonOrRuntimeExceptionIfPresent();
        throw new AssertionError("Not here");
    }
}
Also used : CorrelationResult(com.evolveum.midpoint.model.api.correlator.CorrelationResult)

Example 5 with CorrelationResult

use of com.evolveum.midpoint.model.api.correlator.CorrelationResult in project midpoint by Evolveum.

the class TestExpressionCorrelator method test100NoOwner.

/**
 * The correlation code returns no owner.
 */
@Test
public void test100NoOwner() throws Exception {
    given();
    Task task = getTestTask();
    OperationResult result = task.getResult();
    String accountName = getTestNameShort();
    DummyAccount account = DUMMY_RESOURCE_SOURCE.controller.addAccount(accountName);
    account.addAttributeValue(ATTR_CORRELATION_CODE, "[]");
    when();
    CorrelationResult correlationResult = correlateAccount(accountName, task, result);
    then();
    assertCorrelationResult(correlationResult, NO_OWNER, null);
    assertNoCorrelationCase(accountName, task, result);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CorrelationResult(com.evolveum.midpoint.model.api.correlator.CorrelationResult) DummyAccount(com.evolveum.icf.dummy.resource.DummyAccount) Test(org.testng.annotations.Test) AbstractInternalModelIntegrationTest(com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)

Aggregations

CorrelationResult (com.evolveum.midpoint.model.api.correlator.CorrelationResult)9 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)5 Task (com.evolveum.midpoint.task.api.Task)5 Test (org.testng.annotations.Test)5 NotNull (org.jetbrains.annotations.NotNull)3