Search in sources :

Example 36 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class DeltaConvertor method addOldValues.

private static void addOldValues(ItemDelta delta, ItemDeltaType mod, Collection<PrismValue> values, DeltaConversionOptions options) throws SchemaException {
    if (values == null || values.isEmpty()) {
    //            RawType modValue = new RawType(delta.getPrismContext());
    //            mod.getEstimatedOldValue().add(modValue);
    } else {
        for (PrismValue value : values) {
            XNode xnode = toXNode(delta, value, options);
            RawType modValue = new RawType(xnode, delta.getPrismContext());
            mod.getEstimatedOldValue().add(modValue);
        }
    }
}
Also used : XNode(com.evolveum.midpoint.prism.xnode.XNode) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 37 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class DeltaConvertor method addModValues.

// requires delta.prismContext to be set
private static void addModValues(ItemDelta delta, ItemDeltaType mod, Collection<PrismValue> values, DeltaConversionOptions options) throws SchemaException {
    if (values == null || values.isEmpty()) {
    //            RawType modValue = new RawType(delta.getPrismContext());
    //            mod.getValue().add(modValue);
    } else {
        for (PrismValue value : values) {
            XNode xnode = toXNode(delta, value, options);
            RawType modValue = new RawType(xnode, value.getPrismContext());
            mod.getValue().add(modValue);
        }
    }
}
Also used : XNode(com.evolveum.midpoint.prism.xnode.XNode) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType)

Example 38 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class DeltaConvertor method createObjectDelta.

public static <T extends Objectable> ObjectDelta<T> createObjectDelta(ObjectDeltaType objectDeltaType, PrismContext prismContext, boolean allowRawValues) throws SchemaException {
    Validate.notNull(prismContext, "No prismContext in DeltaConvertor.createObjectDelta call");
    QName objectType = objectDeltaType.getObjectType();
    if (objectType == null) {
        throw new SchemaException("No objectType specified");
    }
    PrismObjectDefinition<T> objDef = prismContext.getSchemaRegistry().findObjectDefinitionByType(objectType);
    Class<T> type = objDef.getCompileTimeClass();
    if (objectDeltaType.getChangeType() == ChangeTypeType.ADD) {
        ObjectDelta<T> objectDelta = new ObjectDelta<T>(type, ChangeType.ADD, prismContext);
        objectDelta.setOid(objectDeltaType.getOid());
        ObjectType objectToAddElement = objectDeltaType.getObjectToAdd();
        //            PrismObject<T> objectToAdd = prismContext.getJaxbDomHack().parseObjectFromJaxb(objectToAddElement);
        if (objectToAddElement != null) {
            objectDelta.setObjectToAdd(objectToAddElement.asPrismObject());
        }
        return objectDelta;
    } else if (objectDeltaType.getChangeType() == ChangeTypeType.MODIFY) {
        ObjectDelta<T> objectDelta = new ObjectDelta<T>(type, ChangeType.MODIFY, prismContext);
        objectDelta.setOid(objectDeltaType.getOid());
        for (ItemDeltaType propMod : objectDeltaType.getItemDelta()) {
            ItemDelta itemDelta = createItemDelta(propMod, objDef, allowRawValues);
            if (itemDelta != null) {
                objectDelta.addModification(itemDelta);
            }
        }
        return objectDelta;
    } else if (objectDeltaType.getChangeType() == ChangeTypeType.DELETE) {
        ObjectDelta<T> objectDelta = new ObjectDelta<T>(type, ChangeType.DELETE, prismContext);
        objectDelta.setOid(objectDeltaType.getOid());
        return objectDelta;
    } else {
        throw new SchemaException("Unknown change type " + objectDeltaType.getChangeType());
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectType(com.evolveum.prism.xml.ns._public.types_3.ObjectType) QName(javax.xml.namespace.QName) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 39 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class DeltaConvertor method toModifications.

public static <T extends Objectable> Collection<? extends ItemDelta> toModifications(Collection<ItemDeltaType> itemDeltaTypes, PrismObjectDefinition<T> objDef) throws SchemaException {
    Collection<ItemDelta> modifications = new ArrayList<ItemDelta>();
    for (ItemDeltaType propMod : itemDeltaTypes) {
        ItemDelta itemDelta = createItemDelta(propMod, objDef);
        modifications.add(itemDelta);
    }
    return modifications;
}
Also used : ArrayList(java.util.ArrayList) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemDeltaType(com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)

Example 40 with ItemDeltaType

use of com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType in project midpoint by Evolveum.

the class DeltaConvertor method toObjectDeltaType.

public static ObjectDeltaType toObjectDeltaType(ObjectDelta<? extends ObjectType> objectDelta, DeltaConversionOptions options) throws SchemaException {
    Validate.notNull(objectDelta.getPrismContext(), "ObjectDelta without prismContext cannot be converted to ObjectDeltaType");
    ObjectDeltaType objectDeltaType = new ObjectDeltaType();
    objectDeltaType.setChangeType(convertChangeType(objectDelta.getChangeType()));
    Class<? extends Objectable> type = objectDelta.getObjectTypeClass();
    PrismObjectDefinition<? extends Objectable> objDef = objectDelta.getPrismContext().getSchemaRegistry().findObjectDefinitionByCompileTimeClass(type);
    if (objDef == null) {
        throw new SchemaException("Unknown compile time class: " + type);
    }
    objectDeltaType.setObjectType(objDef.getTypeName());
    objectDeltaType.setOid(objectDelta.getOid());
    if (objectDelta.getChangeType() == ChangeType.ADD) {
        PrismObject<? extends ObjectType> prismObject = objectDelta.getObjectToAdd();
        if (prismObject != null) {
            objectDeltaType.setObjectToAdd(prismObject.asObjectable());
        }
    } else if (objectDelta.getChangeType() == ChangeType.MODIFY) {
        ObjectModificationType modType = new ObjectModificationType();
        modType.setOid(objectDelta.getOid());
        for (ItemDelta<?, ?> propDelta : objectDelta.getModifications()) {
            Collection<ItemDeltaType> propPropModTypes;
            try {
                propPropModTypes = toItemDeltaTypes(propDelta, options);
            } catch (SchemaException e) {
                throw new SchemaException(e.getMessage() + " in " + objectDelta.toString(), e);
            }
            objectDeltaType.getItemDelta().addAll(propPropModTypes);
        }
    } else if (objectDelta.getChangeType() == ChangeType.DELETE) {
    // Nothing to do
    } else {
        throw new SystemException("Unknown changetype " + objectDelta.getChangeType());
    }
    return objectDeltaType;
}
Also used : ObjectDeltaType(com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectModificationType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType) SystemException(com.evolveum.midpoint.util.exception.SystemException) Collection(java.util.Collection) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta)

Aggregations

ItemDeltaType (com.evolveum.prism.xml.ns._public.types_3.ItemDeltaType)39 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)28 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)11 ObjectDeltaListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaListType)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)11 Test (org.testng.annotations.Test)11 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)8 QName (javax.xml.namespace.QName)8 Document (org.w3c.dom.Document)8 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)7 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)7 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)7 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)6 ObjectDeltaOperationListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)6 XNode (com.evolveum.midpoint.prism.xnode.XNode)4 ObjectModificationType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectModificationType)4 ObjectDeltaOperationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectDeltaOperationType)4 ResourceObjectShadowChangeDescriptionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceObjectShadowChangeDescriptionType)4