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;
}
Aggregations