Search in sources :

Example 91 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class ContainerDelta method expand.

/**
	 * Post processing of delta to expand missing values from the object. E.g. a delete deltas may
	 * be "id-only" so they contain only id of the value to delete. In such case locate the full value
	 * in the object and fill it into the delta.
	 * This method may even delete in-only values that are no longer present in the object.
	 */
public <O extends Objectable> void expand(PrismObject<O> object) throws SchemaException {
    if (valuesToDelete != null) {
        ItemPath path = this.getPath();
        PrismContainer<Containerable> container = null;
        if (object != null) {
            container = object.findContainer(path);
        }
        Iterator<PrismContainerValue<V>> iterator = valuesToDelete.iterator();
        while (iterator.hasNext()) {
            PrismContainerValue<V> deltaCVal = iterator.next();
            if ((deltaCVal.getItems() == null || deltaCVal.getItems().isEmpty())) {
                Long id = deltaCVal.getId();
                if (id == null) {
                    throw new IllegalArgumentException("No id and no items in value " + deltaCVal + " in delete set in " + this);
                }
                if (container != null) {
                    PrismContainerValue<Containerable> containerCVal = container.findValue(id);
                    if (containerCVal != null) {
                        for (Item<?, ?> containerItem : containerCVal.getItems()) {
                            deltaCVal.add(containerItem.clone());
                        }
                        continue;
                    }
                }
                // id-only value with ID that is not in the object any more: delete the value from delta
                iterator.remove();
            }
        }
    }
}
Also used : ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 92 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class ItemDelta method applyDefinition.

public static void applyDefinition(Collection<? extends ItemDelta> deltas, PrismObjectDefinition definition) throws SchemaException {
    for (ItemDelta itemDelta : deltas) {
        ItemPath path = itemDelta.getPath();
        ItemDefinition itemDefinition = definition.findItemDefinition(path, ItemDefinition.class);
        if (itemDefinition == null) {
            throw new SchemaException("Object type " + definition.getTypeName() + " doesn't contain definition for path " + new XPathHolder(path).getXPathWithDeclarations(false));
        }
        itemDelta.applyDefinition(itemDefinition);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) XPathHolder(com.evolveum.midpoint.prism.marshaller.XPathHolder) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 93 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class ItemDelta method accept.

public static void accept(Collection<? extends ItemDelta> modifications, Visitor visitor, ItemPath path, boolean recursive) {
    for (ItemDelta modification : modifications) {
        ItemPath modPath = modification.getPath();
        CompareResult rel = modPath.compareComplex(path);
        if (rel == CompareResult.EQUIVALENT) {
            modification.accept(visitor, null, recursive);
        } else if (rel == CompareResult.SUBPATH) {
            modification.accept(visitor, path.substract(modPath), recursive);
        }
    }
}
Also used : CompareResult(com.evolveum.midpoint.prism.path.ItemPath.CompareResult) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 94 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class ObjectDelta method applyDefinition.

public void applyDefinition(PrismObjectDefinition<T> objectDefinition, boolean force) throws SchemaException {
    if (objectToAdd != null) {
        objectToAdd.applyDefinition(objectDefinition, force);
    }
    if (modifications != null) {
        for (ItemDelta modification : modifications) {
            ItemPath path = modification.getPath();
            ItemDefinition itemDefinition = objectDefinition.findItemDefinition(path);
            modification.applyDefinition(itemDefinition, force);
        }
    }
}
Also used : ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 95 with ItemPath

use of com.evolveum.midpoint.prism.path.ItemPath in project midpoint by Evolveum.

the class ObjectTypeUtil method isModificationOf.

//TODO: refactor after new schema
public static boolean isModificationOf(ItemDeltaType modification, QName elementName, ItemPathType path) {
    //        if (path == null && XPathHolder.isDefault(modification.getPath())) {
    //            return (elementName.equals(ObjectTypeUtil.getElementName(modification)));
    //        }
    ItemPathType modificationPath = modification.getPath();
    if (ItemPathUtil.isDefault(modificationPath)) {
        throw new IllegalArgumentException("Path in the delta must not be null");
    }
    if (path == null) {
        return false;
    }
    //        XPathHolder modPath = new XPathHolder(modification.getPath());
    ItemPath full = new ItemPath(path.getItemPath(), elementName);
    ItemPathType fullPath = new ItemPathType(full);
    return fullPath.equivalent(modificationPath);
//        if (fullPath.equals(modificationPath)) {
//            return (elementName.equals(getElementName(modification)));
//        }
//        return false;
}
Also used : ItemPathType(com.evolveum.prism.xml.ns._public.types_3.ItemPathType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)693 Test (org.testng.annotations.Test)184 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)143 QName (javax.xml.namespace.QName)137 Task (com.evolveum.midpoint.task.api.Task)104 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)84 ArrayList (java.util.ArrayList)79 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)71 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)68 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)61 ItemPathType (com.evolveum.prism.xml.ns._public.types_3.ItemPathType)48 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)46 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)41 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)38 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)38 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)38 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)33 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)31 NotNull (org.jetbrains.annotations.NotNull)30