Search in sources :

Example 1 with SynchronizationReactionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method findReactionDefinition.

private SynchronizationReactionType findReactionDefinition(ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation situation, String channel, ResourceType resource) throws ConfigurationException {
    SynchronizationReactionType defaultReaction = null;
    for (SynchronizationReactionType reaction : synchronizationPolicy.getReaction()) {
        SynchronizationSituationType reactionSituation = reaction.getSituation();
        if (reactionSituation == null) {
            throw new ConfigurationException("No situation defined for a reaction in " + resource);
        }
        if (reactionSituation.equals(situation.getSituation())) {
            if (reaction.getChannel() != null && !reaction.getChannel().isEmpty()) {
                if (reaction.getChannel().contains("") || reaction.getChannel().contains(null)) {
                    defaultReaction = reaction;
                }
                if (reaction.getChannel().contains(channel)) {
                    return reaction;
                } else {
                    LOGGER.trace("Skipping reaction {} because the channel does not match {}", reaction, channel);
                    continue;
                }
            } else {
                defaultReaction = reaction;
            }
        }
    }
    LOGGER.trace("Using default reaction {}", defaultReaction);
    return defaultReaction;
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) SynchronizationReactionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException)

Example 2 with SynchronizationReactionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method executeActions.

private <F extends FocusType> void executeActions(SynchronizationReactionType reactionDef, LensContext<F> context, SynchronizationSituation<F> situation, BeforeAfterType order, ResourceType resource, boolean logDebug, Task task, OperationResult parentResult) throws ConfigurationException, SchemaException {
    for (SynchronizationActionType actionDef : reactionDef.getAction()) {
        if ((actionDef.getOrder() == null && order == BeforeAfterType.BEFORE) || (actionDef.getOrder() != null && actionDef.getOrder() == order)) {
            String handlerUri = actionDef.getHandlerUri();
            if (handlerUri == null) {
                handlerUri = actionDef.getRef();
            }
            if (handlerUri == null) {
                LOGGER.error("Action definition in resource {} doesn't contain handler URI", resource);
                throw new ConfigurationException("Action definition in resource " + resource + " doesn't contain handler URI");
            }
            Action action = actionManager.getActionInstance(handlerUri);
            if (action == null) {
                LOGGER.warn("Couldn't create action with uri '{}' in resource {}, skipping action.", new Object[] { handlerUri, resource });
                continue;
            }
            // TODO: legacy userTemplate
            Map<QName, Object> parameters = null;
            if (actionDef.getParameters() != null) {
            // TODO: process parameters
            // parameters = actionDef.getParameters().getAny();
            }
            if (logDebug) {
                LOGGER.debug("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
            } else {
                LOGGER.trace("SYNCHRONIZATION: ACTION: Executing: {}.", new Object[] { action.getClass() });
            }
            action.handle(context, situation, parameters, task, parentResult);
        }
    }
}
Also used : SynchronizationActionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationActionType) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) QName(javax.xml.namespace.QName) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 3 with SynchronizationReactionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method reactToChange.

private <F extends FocusType> SynchronizationSituationType reactToChange(Class<F> focusClass, ResourceObjectShadowChangeDescription change, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ResourceType resource, boolean logDebug, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult parentResult) throws ConfigurationException, ObjectNotFoundException, SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectAlreadyExistsException, CommunicationException, SecurityViolationException {
    SynchronizationSituationType newSituation = situation.getSituation();
    SynchronizationReactionType reactionDefinition = findReactionDefinition(synchronizationPolicy, situation, change.getSourceChannel(), resource);
    if (reactionDefinition == null) {
        LOGGER.trace("No reaction is defined for situation {} in {}", situation.getSituation(), resource);
        return newSituation;
    }
    // seems to be unused so commented it out [med]
    // PrismObject<? extends ObjectType> shadow = null;
    // if (change.getCurrentShadow() != null) {
    // shadow = change.getCurrentShadow();
    // } else if (change.getOldShadow() != null) {
    // shadow = change.getOldShadow();
    // }
    Boolean doReconciliation = determineReconciliation(synchronizationPolicy, reactionDefinition);
    if (doReconciliation == null) {
        // shadow.
        if (change.getObjectDelta() == null) {
            doReconciliation = true;
        }
    }
    Boolean limitPropagation = determinePropagationLimitation(synchronizationPolicy, reactionDefinition, change.getSourceChannel());
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setReconcile(doReconciliation);
    options.setLimitPropagation(limitPropagation);
    final boolean willSynchronize = isSynchronize(reactionDefinition);
    LensContext<F> lensContext = null;
    if (willSynchronize) {
        lensContext = createLensContext(focusClass, change, reactionDefinition, synchronizationPolicy, situation, options, configuration, parentResult);
    }
    if (LOGGER.isTraceEnabled() && lensContext != null) {
        LOGGER.trace("---[ SYNCHRONIZATION context before action execution ]-------------------------\n" + "{}\n------------------------------------------", lensContext.debugDump());
    }
    if (willSynchronize) {
        // there's no point in calling executeAction without context - so
        // the actions are executed only if synchronize == true
        executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.BEFORE, resource, logDebug, task, parentResult);
        Iterator<LensProjectionContext> iterator = lensContext.getProjectionContextsIterator();
        LensProjectionContext originalProjectionContext = iterator.hasNext() ? iterator.next() : null;
        try {
            clockwork.run(lensContext, task, parentResult);
        } catch (ConfigurationException | ObjectNotFoundException | SchemaException | PolicyViolationException | ExpressionEvaluationException | ObjectAlreadyExistsException | CommunicationException | SecurityViolationException e) {
            LOGGER.error("SYNCHRONIZATION: Error in synchronization on {} for situation {}: {}: {}. Change was {}", new Object[] { resource, situation.getSituation(), e.getClass().getSimpleName(), e.getMessage(), change, e });
        // what to do here? We cannot throw the error back. All that the notifyChange method
        // could do is to convert it to SystemException. But that indicates an internal error and it will
        // break whatever code called the notifyChange in the first place. We do not want that.
        // If the clockwork could not do anything with the exception then perhaps nothing can be done at all.
        // So just log the error (the error should be remembered in the result and task already)
        // and then just go on.
        }
        // note: actions "AFTER" seem to be useless here (basically they
        // modify lens context - which is relevant only if followed by
        // clockwork run)
        executeActions(reactionDefinition, lensContext, situation, BeforeAfterType.AFTER, resource, logDebug, task, parentResult);
        if (originalProjectionContext != null) {
            newSituation = originalProjectionContext.getSynchronizationSituationResolved();
        }
    } else {
        LOGGER.trace("Skipping clockwork run on {} for situation {}, synchronize is set to false.", new Object[] { resource, situation.getSituation() });
    }
    return newSituation;
}
Also used : SynchronizationSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType) SynchronizationReactionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 4 with SynchronizationReactionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method createLensContext.

@NotNull
private <F extends FocusType> LensContext<F> createLensContext(Class<F> focusClass, ResourceObjectShadowChangeDescription change, SynchronizationReactionType reactionDefinition, ObjectSynchronizationType synchronizationPolicy, SynchronizationSituation<F> situation, ModelExecuteOptions options, PrismObject<SystemConfigurationType> configuration, OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
    LensContext<F> context = contextFactory.createSyncContext(focusClass, change);
    context.setLazyAuditRequest(true);
    context.setSystemConfiguration(configuration);
    context.setOptions(options);
    ResourceType resource = change.getResource().asObjectable();
    if (ModelExecuteOptions.isLimitPropagation(options)) {
        context.setTriggeredResource(resource);
    }
    context.rememberResource(resource);
    PrismObject<ShadowType> shadow = getShadowFromChange(change);
    if (InternalsConfig.consistencyChecks)
        shadow.checkConsistence();
    // Projection context
    ShadowKindType kind = getKind(shadow, synchronizationPolicy);
    String intent = getIntent(shadow, synchronizationPolicy);
    boolean thombstone = isThombstone(change);
    ResourceShadowDiscriminator descr = new ResourceShadowDiscriminator(resource.getOid(), kind, intent, thombstone);
    LensProjectionContext projectionContext = context.createProjectionContext(descr);
    projectionContext.setResource(resource);
    projectionContext.setOid(getOidFromChange(change));
    projectionContext.setSynchronizationSituationDetected(situation.getSituation());
    // insert object delta if available in change
    ObjectDelta<? extends ShadowType> delta = change.getObjectDelta();
    if (delta != null) {
        projectionContext.setSyncDelta((ObjectDelta<ShadowType>) delta);
    } else {
        projectionContext.setSyncAbsoluteTrigger(true);
    }
    // we insert account if available in change
    PrismObject<ShadowType> currentAccount = shadow;
    if (currentAccount != null) {
        projectionContext.setLoadedObject(currentAccount);
        if (!thombstone) {
            projectionContext.setFullShadow(true);
        }
        projectionContext.setFresh(true);
    }
    if (delta != null && delta.isDelete()) {
        projectionContext.setExists(false);
    } else {
        projectionContext.setExists(true);
    }
    projectionContext.setDoReconciliation(ModelExecuteOptions.isReconcile(options));
    // Focus context
    if (situation.getCurrentOwner() != null) {
        F focusType = situation.getCurrentOwner();
        LensFocusContext<F> focusContext = context.createFocusContext();
        PrismObject<F> focusOld = (PrismObject<F>) focusType.asPrismObject();
        focusContext.setLoadedObject(focusOld);
    }
    // Global stuff
    ObjectReferenceType objectTemplateRef = null;
    if (reactionDefinition.getObjectTemplateRef() != null) {
        objectTemplateRef = reactionDefinition.getObjectTemplateRef();
    } else if (synchronizationPolicy.getObjectTemplateRef() != null) {
        objectTemplateRef = synchronizationPolicy.getObjectTemplateRef();
    }
    if (objectTemplateRef != null) {
        ObjectTemplateType objectTemplate = repositoryService.getObject(ObjectTemplateType.class, objectTemplateRef.getOid(), null, parentResult).asObjectable();
        context.setFocusTemplate(objectTemplate);
    }
    return context;
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) LensProjectionContext(com.evolveum.midpoint.model.impl.lens.LensProjectionContext) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PrismObject(com.evolveum.midpoint.prism.PrismObject) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) ObjectTemplateType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType) ShadowKindType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with SynchronizationReactionType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType in project midpoint by Evolveum.

the class Migrator method migrateObjectSynchronization.

private void migrateObjectSynchronization(ObjectSynchronizationType sync) {
    if (sync == null || sync.getReaction() == null) {
        return;
    }
    List<SynchronizationReactionType> migratedReactions = new ArrayList<SynchronizationReactionType>();
    for (SynchronizationReactionType reaction : sync.getReaction()) {
        if (reaction.getAction() == null) {
            continue;
        }
        List<SynchronizationActionType> migratedAction = new ArrayList<SynchronizationActionType>();
        for (SynchronizationActionType action : reaction.getAction()) {
            migratedAction.add(migrateAction(action));
        }
        SynchronizationReactionType migratedReaction = reaction.clone();
        migratedReaction.getAction().clear();
        migratedReaction.getAction().addAll(migratedAction);
        migratedReactions.add(migratedReaction);
    }
    sync.getReaction().clear();
    sync.getReaction().addAll(migratedReactions);
}
Also used : SynchronizationActionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationActionType) SynchronizationReactionType(com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType) ArrayList(java.util.ArrayList)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)3 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)3 SynchronizationReactionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationReactionType)3 LensProjectionContext (com.evolveum.midpoint.model.impl.lens.LensProjectionContext)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 SynchronizationActionType (com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationActionType)2 SynchronizationSituationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType)2 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)1 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)1 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)1 PolicyViolationException (com.evolveum.midpoint.util.exception.PolicyViolationException)1 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)1 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)1 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)1 ObjectTemplateType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType)1 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)1 ShadowKindType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType)1