Skip to content

Commit

Permalink
Fixing ItemDeltaItem
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Jul 30, 2014
1 parent 1c579c7 commit a6c0239
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
Expand Up @@ -149,7 +149,8 @@ protected boolean isApplicableToType(Item item) {
return item instanceof PrismContainer;
}

public ItemDelta<?> findItemDelta(ItemPath path) {
@Override
public ItemDelta<?> getSubDelta(ItemPath path) {
if (path.isEmpty()) {
return this;
}
Expand Down
Expand Up @@ -1002,6 +1002,10 @@ public void applyToMatchingPath(Item item) throws SchemaException {
cleanupAllTheWayUp(item);
}

public ItemDelta<?> getSubDelta(ItemPath path) {
return this;
}

public boolean isApplicableTo(Item item) {
if (item == null) {
return false;
Expand Down
Expand Up @@ -200,7 +200,7 @@ public <X extends PrismValue> ItemDeltaItem<X> findIdi(ItemPath path) {
ItemDelta<X> subDelta= null;
if (delta != null) {
if (delta instanceof ContainerDelta<?>) {
subDelta = (ItemDelta<X>) ((ContainerDelta<?>)delta).findItemDelta(path);
subDelta = (ItemDelta<X>) ((ContainerDelta<?>)delta).getSubDelta(path);
} else {
CompareResult compareComplex = delta.getPath().compareComplex(newResolvePath);
if (compareComplex == CompareResult.EQUIVALENT || compareComplex == CompareResult.SUBPATH) {
Expand Down
Expand Up @@ -15,6 +15,9 @@
*/
package com.evolveum.midpoint.model.common.expression;

import java.util.ArrayList;
import java.util.Collection;

import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PartiallyResolvedValue;
Expand All @@ -26,6 +29,7 @@
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.prism.delta.PartiallyResolvedDelta;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPath.CompareResult;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand Down Expand Up @@ -117,19 +121,48 @@ public <V extends PrismValue> ItemDeltaItem<V> findIdi(ItemPath path) {
}
}
}
ItemDelta<V> itemDelta= null;
ItemDelta<V> itemDelta = null;
Collection<? extends ItemDelta<?>> subSubItemDeltas = null;
if (delta != null) {
PartiallyResolvedDelta<V> partialDelta = delta.findPartial(path);
if (partialDelta != null) {
itemDelta = partialDelta.getDelta();
if (subResidualPath == null) {
subResidualPath = partialDelta.getResidualPath();
}
if (delta.getChangeType() == ChangeType.ADD) {
PrismObject<T> objectToAdd = delta.getObjectToAdd();
PartiallyResolvedValue<V> partialValue = objectToAdd.findPartial(path);
if (partialValue != null && partialValue.getItem() != null) {
Item<V> 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) {
// TODO
throw new UnsupportedOperationException("delete");
} 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<V>) 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<V>) modification.getSubDelta(path);
}
}
}
}
ItemDeltaItem<V> subIdi = new ItemDeltaItem<V>(subItemOld, itemDelta, subItemNew);
subIdi.setResidualPath(subResidualPath);
subIdi.setSubItemDeltas(subSubItemDeltas);
subIdi.setResolvePath(path);
subIdi.setResidualPath(subResidualPath);
return subIdi;
}

Expand Down
Expand Up @@ -831,13 +831,15 @@ private <X extends PrismValue> Source<X> parseSource(MappingSourceDeclarationTyp
ItemDelta<X> delta = null;
Item<X> itemNew = null;
ItemPath residualPath = null;
Collection<? extends ItemDelta<?>> subItemDeltas = null;
if (sourceObject != null) {
if (sourceObject instanceof ItemDeltaItem<?>) {
itemOld = ((ItemDeltaItem<X>)sourceObject).getItemOld();
delta = ((ItemDeltaItem<X>)sourceObject).getDelta();
itemNew = ((ItemDeltaItem<X>)sourceObject).getItemNew();
residualPath = ((ItemDeltaItem<X>)sourceObject).getResidualPath();
resolvePath = ((ItemDeltaItem<X>)sourceObject).getResolvePath();
subItemDeltas = ((ItemDeltaItem<X>)sourceObject).getSubItemDeltas();
} else if (sourceObject instanceof Item<?>) {
itemOld = (Item<X>) sourceObject;
itemNew = (Item<X>) sourceObject;
Expand All @@ -848,6 +850,7 @@ private <X extends PrismValue> Source<X> parseSource(MappingSourceDeclarationTyp
Source<X> source = new Source<X>(itemOld, delta, itemNew, name);
source.setResidualPath(residualPath);
source.setResolvePath(resolvePath);
source.setSubItemDeltas(subItemDeltas);
return source;
}

Expand Down

0 comments on commit a6c0239

Please sign in to comment.