Search in sources :

Example 1 with ShadowedExternalChange

use of com.evolveum.midpoint.provisioning.impl.shadows.ShadowedExternalChange in project midpoint by Evolveum.

the class ExternalResourceEventListenerImpl method notifyEvent.

// TODO clean up this!
@Override
public void notifyEvent(ExternalResourceEvent event, Task task, OperationResult result) {
    Validate.notNull(event, "Event description must not be null.");
    Validate.notNull(task, "Task must not be null.");
    Validate.notNull(result, "Operation result must not be null");
    LOGGER.trace("Received event notification with the description: {}", event.debugDumpLazily());
    if (event.getResourceObject() == null && event.getObjectDelta() == null) {
        throw new IllegalStateException("Neither current shadow, nor delta specified. It is required to have at least one of them specified.");
    }
    try {
        applyDefinitions(event, task, result);
        PrismObject<ShadowType> anyShadow = getAnyShadow(event);
        ProvisioningContext ctx = provisioningContextFactory.createForShadow(anyShadow, task, result);
        ctx.assertDefinition();
        Object primaryIdentifierRealValue = getPrimaryIdentifierRealValue(anyShadow, event);
        Collection<ResourceAttribute<?>> identifiers = emptyIfNull(ShadowUtil.getAllIdentifiers(anyShadow));
        if (identifiers.isEmpty()) {
            throw new SchemaException("No identifiers");
        }
        ExternalResourceObjectChange resourceObjectChange = new ExternalResourceObjectChange(currentSequenceNumber.getAndIncrement(), primaryIdentifierRealValue, ctx.getObjectClassDefinition(), identifiers, getResourceObject(event), event.getObjectDelta(), ctx, resourceObjectConverter);
        resourceObjectChange.initialize(task, result);
        ShadowedExternalChange adoptedChange = new ShadowedExternalChange(resourceObjectChange, changeProcessingBeans);
        adoptedChange.initialize(task, result);
        InitializationState initializationState = adoptedChange.getInitializationState();
        initializationState.checkAfterInitialization();
        if (initializationState.isOk()) {
            ResourceObjectShadowChangeDescription shadowChangeDescription = adoptedChange.getShadowChangeDescription();
            eventDispatcher.notifyChange(shadowChangeDescription, task, result);
        } else {
            Throwable t = initializationState.getExceptionEncountered();
            if (t != null) {
                throw t;
            } else if (initializationState.isNotApplicable()) {
                LOGGER.debug("Change is not applicable:\n{}", adoptedChange.debugDumpLazily());
                result.recordNotApplicable();
            } else {
                throw new AssertionError();
            }
        }
    } catch (Throwable t) {
        // Currently we do very simple error handling: throw any exception to the client, wrapped if needed
        if (t instanceof CommonException) {
            throw new TunnelException(t);
        } else if (t instanceof RuntimeException) {
            throw (RuntimeException) t;
        } else if (t instanceof Error) {
            throw (Error) t;
        } else {
            throw new SystemException(t);
        }
    }
}
Also used : InitializationState(com.evolveum.midpoint.provisioning.util.InitializationState) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowedExternalChange(com.evolveum.midpoint.provisioning.impl.shadows.ShadowedExternalChange) PrismObject(com.evolveum.midpoint.prism.PrismObject) ExternalResourceObjectChange(com.evolveum.midpoint.provisioning.impl.resourceobjects.ExternalResourceObjectChange) ResourceAttribute(com.evolveum.midpoint.schema.processor.ResourceAttribute)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ExternalResourceObjectChange (com.evolveum.midpoint.provisioning.impl.resourceobjects.ExternalResourceObjectChange)1 ShadowedExternalChange (com.evolveum.midpoint.provisioning.impl.shadows.ShadowedExternalChange)1 InitializationState (com.evolveum.midpoint.provisioning.util.InitializationState)1 ResourceAttribute (com.evolveum.midpoint.schema.processor.ResourceAttribute)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1