Search in sources :

Example 1 with ShadowCoordinatesQualifiedObjectDelta

use of com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta in project midpoint by Evolveum.

the class ContextFactory method createContext.

public <F extends ObjectType> LensContext<F> createContext(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    ObjectDelta<F> focusDelta = null;
    Collection<ObjectDelta<ShadowType>> projectionDeltas = new ArrayList<>(deltas.size());
    ObjectDelta<? extends ObjectType> confDelta = null;
    Class<F> focusClass = null;
    // Sort deltas to focus and projection deltas, check if the classes are correct;
    for (ObjectDelta<? extends ObjectType> delta : deltas) {
        Class<? extends ObjectType> typeClass = delta.getObjectTypeClass();
        Validate.notNull(typeClass, "Object type class is null in " + delta);
        if (isFocalClass(typeClass)) {
            if (confDelta != null) {
                throw new IllegalArgumentException("Mixed configuration and focus deltas in one executeChanges invocation");
            }
            focusClass = (Class<F>) typeClass;
            if (!delta.isAdd() && delta.getOid() == null) {
                throw new IllegalArgumentException("Delta " + delta + " does not have an OID");
            }
            if (InternalsConfig.consistencyChecks) {
                // Focus delta has to be complete now with all the definition already in place
                delta.checkConsistence(false, true, true, ConsistencyCheckScope.THOROUGH);
            } else {
                // TODO is this necessary? Perhaps it would be sufficient to check on model/repo entry
                delta.checkConsistence(ConsistencyCheckScope.MANDATORY_CHECKS_ONLY);
            }
            if (focusDelta != null) {
                throw new IllegalStateException("More than one focus delta used in model operation");
            }
            // Make sure we clone request delta here. Clockwork will modify the delta (e.g. normalize it).
            // And we do not want to touch request delta. It may even be immutable.
            focusDelta = (ObjectDelta<F>) delta.clone();
        } else if (isProjectionClass(typeClass)) {
            if (confDelta != null) {
                throw new IllegalArgumentException("Mixed configuration and projection deltas in one executeChanges invocation");
            }
            // Make sure we clone request delta here. Clockwork will modify the delta (e.g. normalize it).
            // And we do not want to touch request delta. It may even be immutable.
            ObjectDelta<ShadowType> projectionDelta = (ObjectDelta<ShadowType>) delta.clone();
            projectionDeltas.add(projectionDelta);
        } else {
            if (confDelta != null) {
                throw new IllegalArgumentException("More than one configuration delta in a single executeChanges invocation");
            }
            // Make sure we clone request delta here. Clockwork will modify the delta (e.g. normalize it).
            // And we do not want to touch request delta. It may even be immutable.
            confDelta = delta.clone();
        }
    }
    if (confDelta != null) {
        // noinspection unchecked
        focusClass = (Class<F>) confDelta.getObjectTypeClass();
    }
    if (focusClass == null) {
        focusClass = determineFocusClass();
    }
    LensContext<F> context = new LensContext<>(focusClass);
    context.setChannel(task.getChannel());
    context.setOptions(options);
    context.setDoReconciliationForAllProjections(ModelExecuteOptions.isReconcile(options));
    if (confDelta != null) {
        LensFocusContext<F> focusContext = context.createFocusContext();
        // noinspection unchecked
        focusContext.setPrimaryDelta((ObjectDelta<F>) confDelta);
    } else {
        if (focusDelta != null) {
            LensFocusContext<F> focusContext = context.createFocusContext();
            focusContext.setPrimaryDelta(focusDelta);
        }
        for (ObjectDelta<ShadowType> projectionDelta : projectionDeltas) {
            LensProjectionContext projectionContext = context.createProjectionContext();
            if (context.isDoReconciliationForAllProjections()) {
                projectionContext.setDoReconciliation(true);
            }
            projectionContext.setPrimaryDelta(projectionDelta);
            // We are little bit more liberal regarding projection deltas.
            // If the deltas represent shadows we tolerate missing attribute definitions.
            // We try to add the definitions by calling provisioning
            provisioningService.applyDefinition(projectionDelta, task, result);
            if (projectionDelta instanceof ShadowCoordinatesQualifiedObjectDelta) {
                projectionContext.setResourceShadowDiscriminator(new ResourceShadowDiscriminator(((ShadowCoordinatesQualifiedObjectDelta<ShadowType>) projectionDelta).getCoordinates()));
            } else {
                if (!projectionDelta.isAdd() && projectionDelta.getOid() == null) {
                    throw new IllegalArgumentException("Delta " + projectionDelta + " does not have an OID");
                }
            }
        }
    }
    // This forces context reload before the next projection
    context.rot("context initialization");
    if (InternalsConfig.consistencyChecks)
        context.checkConsistence();
    context.finishBuild();
    return context;
}
Also used : ArrayList(java.util.ArrayList) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta)

Example 2 with ShadowCoordinatesQualifiedObjectDelta

use of com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta in project midpoint by Evolveum.

the class DefinitionsHelper method applyDefinition.

public void applyDefinition(ObjectDelta<ShadowType> delta, @Nullable ShadowType repoShadow, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, ExpressionEvaluationException {
    PrismObject<ShadowType> shadow = null;
    ResourceShadowCoordinates coordinates = null;
    if (delta.isAdd()) {
        shadow = delta.getObjectToAdd();
    } else if (delta.isModify()) {
        if (delta instanceof ShadowCoordinatesQualifiedObjectDelta) {
            // This one does not have OID, it has to be specially processed
            coordinates = ((ShadowCoordinatesQualifiedObjectDelta<?>) delta).getCoordinates();
        } else {
            String shadowOid = delta.getOid();
            if (shadowOid == null) {
                if (repoShadow == null) {
                    throw new IllegalArgumentException("No OID in object delta " + delta + " and no externally-supplied shadow is present as well.");
                }
                shadow = repoShadow.asPrismObject();
            } else {
                // TODO consider fetching only when really necessary
                shadow = repositoryService.getObject(delta.getObjectTypeClass(), shadowOid, null, result);
            }
        }
    } else {
        // Delete delta, nothing to do at all
        return;
    }
    ProvisioningContext ctx;
    if (shadow == null) {
        stateCheck(coordinates != null, "No shadow nor coordinates");
        ctx = ctxFactory.createForCoordinates(coordinates, task, result);
    } else {
        ctx = ctxFactory.createForShadow(shadow, task, result);
    }
    shadowCaretaker.applyAttributesDefinition(ctx, delta);
}
Also used : ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates)

Aggregations

ShadowCoordinatesQualifiedObjectDelta (com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta)2 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ProvisioningContext (com.evolveum.midpoint.provisioning.impl.ProvisioningContext)1 ResourceShadowCoordinates (com.evolveum.midpoint.schema.ResourceShadowCoordinates)1 ResourceShadowDiscriminator (com.evolveum.midpoint.schema.ResourceShadowDiscriminator)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 ArrayList (java.util.ArrayList)1