Search in sources :

Example 1 with ResourceEventDescription

use of com.evolveum.midpoint.provisioning.api.ResourceEventDescription in project midpoint by Evolveum.

the class ModelCrudService method notifyChange.

public void notifyChange(ResourceObjectShadowChangeDescriptionType changeDescription, OperationResult parentResult, Task task) throws SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectNotFoundException, GenericConnectorException, ObjectAlreadyExistsException, ExpressionEvaluationException {
    String oldShadowOid = changeDescription.getOldShadowOid();
    ResourceEventDescription eventDescription = new ResourceEventDescription();
    PrismObject<ShadowType> oldShadow = null;
    LOGGER.trace("resolving old object");
    if (!StringUtils.isEmpty(oldShadowOid)) {
        oldShadow = getObject(ShadowType.class, oldShadowOid, SelectorOptions.createCollection(GetOperationOptions.createDoNotDiscovery()), task, parentResult);
        eventDescription.setOldShadow(oldShadow);
        LOGGER.trace("old object resolved to: {}", oldShadow.debugDump());
    } else {
        LOGGER.trace("Old shadow null");
    }
    PrismObject<ShadowType> currentShadow = null;
    ShadowType currentShadowType = changeDescription.getCurrentShadow();
    LOGGER.trace("resolving current shadow");
    if (currentShadowType != null) {
        prismContext.adopt(currentShadowType);
        currentShadow = currentShadowType.asPrismObject();
        LOGGER.trace("current shadow resolved to {}", currentShadow.debugDump());
    }
    eventDescription.setCurrentShadow(currentShadow);
    ObjectDeltaType deltaType = changeDescription.getObjectDelta();
    ObjectDelta delta = null;
    PrismObject<ShadowType> shadowToAdd = null;
    if (deltaType != null) {
        delta = ObjectDelta.createEmptyDelta(ShadowType.class, deltaType.getOid(), prismContext, ChangeType.toChangeType(deltaType.getChangeType()));
        if (delta.getChangeType() == ChangeType.ADD) {
            //						LOGGER.trace("determined ADD change ");
            if (deltaType.getObjectToAdd() == null) {
                LOGGER.trace("No object to add specified. Check your delta. Add delta must contain object to add");
                throw new IllegalArgumentException("No object to add specified. Check your delta. Add delta must contain object to add");
            //							return handleTaskResult(task);
            }
            Object objToAdd = deltaType.getObjectToAdd();
            if (!(objToAdd instanceof ShadowType)) {
                LOGGER.trace("Wrong object specified in change description. Expected on the the shadow type, but got " + objToAdd.getClass().getSimpleName());
                throw new IllegalArgumentException("Wrong object specified in change description. Expected on the the shadow type, but got " + objToAdd.getClass().getSimpleName());
            //							return handleTaskResult(task);
            }
            prismContext.adopt((ShadowType) objToAdd);
            shadowToAdd = ((ShadowType) objToAdd).asPrismObject();
            LOGGER.trace("object to add: {}", shadowToAdd.debugDump());
            delta.setObjectToAdd(shadowToAdd);
        } else {
            Collection<? extends ItemDelta> modifications = DeltaConvertor.toModifications(deltaType.getItemDelta(), prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(ShadowType.class));
            delta.getModifications().addAll(modifications);
        }
    }
    Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
    deltas.add(delta);
    Utils.encrypt(deltas, protector, null, parentResult);
    eventDescription.setDelta(delta);
    eventDescription.setSourceChannel(changeDescription.getChannel());
    dispatcher.notifyEvent(eventDescription, task, parentResult);
    parentResult.computeStatus();
    task.setResult(parentResult);
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) PrismObject(com.evolveum.midpoint.prism.PrismObject) ResourceEventDescription(com.evolveum.midpoint.provisioning.api.ResourceEventDescription) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Aggregations

PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ResourceEventDescription (com.evolveum.midpoint.provisioning.api.ResourceEventDescription)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)1 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)1 ArrayList (java.util.ArrayList)1