Search in sources :

Example 1 with PartiallyResolvedItem

use of com.evolveum.midpoint.prism.PartiallyResolvedItem in project midpoint by Evolveum.

the class ObjectDeltaObject method findIdi.

@Override
public <IV extends PrismValue, ID extends ItemDefinition> ItemDeltaItem<IV, ID> findIdi(ItemPath path) {
    Item<IV, ID> subItemOld = null;
    ItemPath subResidualPath = null;
    if (oldObject != null) {
        PartiallyResolvedItem<IV, ID> partialOld = oldObject.findPartial(path);
        if (partialOld != null) {
            subItemOld = partialOld.getItem();
            subResidualPath = partialOld.getResidualPath();
        }
    }
    Item<IV, ID> subItemNew = null;
    if (newObject != null) {
        PartiallyResolvedItem<IV, ID> partialNew = newObject.findPartial(path);
        if (partialNew != null) {
            subItemNew = partialNew.getItem();
            if (subResidualPath == null) {
                subResidualPath = partialNew.getResidualPath();
            }
        }
    }
    ItemDelta<IV, ID> itemDelta = null;
    Collection<? extends ItemDelta<?, ?>> subSubItemDeltas = null;
    if (delta != null) {
        if (delta.getChangeType() == ChangeType.ADD) {
            PrismObject<O> objectToAdd = delta.getObjectToAdd();
            PartiallyResolvedItem<IV, ID> partialValue = objectToAdd.findPartial(path);
            if (partialValue != null && partialValue.getItem() != null) {
                Item<IV, ID> item = partialValue.getItem();
                itemDelta = item.createDelta();
                itemDelta.addValuesToAdd(item.getClonedValues());
            } else {
            // No item for this path, itemDelta will stay empty.
            }
        } else if (delta.getChangeType() == ChangeType.DELETE) {
            if (subItemOld != null) {
                ItemPath subPath = subItemOld.getPath().remainder(path);
                PartiallyResolvedItem<IV, ID> partialValue = subItemOld.findPartial(subPath);
                if (partialValue != null && partialValue.getItem() != null) {
                    Item<IV, ID> item = partialValue.getItem();
                    itemDelta = item.createDelta();
                    itemDelta.addValuesToDelete(item.getClonedValues());
                } else {
                // No item for this path, itemDelta will stay empty.
                }
            }
        } else if (delta.getChangeType() == ChangeType.MODIFY) {
            for (ItemDelta<?, ?> modification : delta.getModifications()) {
                CompareResult compareComplex = modification.getPath().compareComplex(path);
                if (compareComplex == CompareResult.EQUIVALENT) {
                    if (itemDelta != null) {
                        throw new IllegalStateException("Conflicting modification in delta " + delta + ": " + itemDelta + " and " + modification);
                    }
                    itemDelta = (ItemDelta<IV, ID>) modification;
                } else if (compareComplex == CompareResult.SUPERPATH) {
                    if (subSubItemDeltas == null) {
                        subSubItemDeltas = new ArrayList<>();
                    }
                    ((Collection) subSubItemDeltas).add(modification);
                } else if (compareComplex == CompareResult.SUBPATH) {
                    if (itemDelta != null) {
                        throw new IllegalStateException("Conflicting modification in delta " + delta + ": " + itemDelta + " and " + modification);
                    }
                    itemDelta = (ItemDelta<IV, ID>) modification.getSubDelta(path.substract(modification.getPath()));
                }
            }
        }
    }
    ItemDeltaItem<IV, ID> subIdi = new ItemDeltaItem<IV, ID>(subItemOld, itemDelta, subItemNew);
    subIdi.setSubItemDeltas(subSubItemDeltas);
    subIdi.setResolvePath(path);
    subIdi.setResidualPath(subResidualPath);
    return subIdi;
}
Also used : ArrayList(java.util.ArrayList) CompareResult(com.evolveum.midpoint.prism.path.ItemPath.CompareResult) Item(com.evolveum.midpoint.prism.Item) PartiallyResolvedItem(com.evolveum.midpoint.prism.PartiallyResolvedItem) PartiallyResolvedItem(com.evolveum.midpoint.prism.PartiallyResolvedItem) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

Item (com.evolveum.midpoint.prism.Item)1 PartiallyResolvedItem (com.evolveum.midpoint.prism.PartiallyResolvedItem)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 CompareResult (com.evolveum.midpoint.prism.path.ItemPath.CompareResult)1 ArrayList (java.util.ArrayList)1