Skip to content

Commit

Permalink
MID-8503:adding fake negative id for container values from template w…
Browse files Browse the repository at this point in the history
…ithout id
  • Loading branch information
skublik committed Mar 22, 2023
1 parent c1903d9 commit 989e079
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public static boolean isValueFromResourceTemplate(PrismValue valueFromDelta, Pri
return false;
}

private static boolean hasValueMetadata(PrismValue value) {
public static boolean hasValueMetadata(PrismValue value) {
if (value == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.evolveum.midpoint.gui.api.factory.wrapper.WrapperContext;
import com.evolveum.midpoint.gui.api.prism.ItemStatus;
import com.evolveum.midpoint.gui.api.prism.wrapper.*;
import com.evolveum.midpoint.gui.api.util.WebPrismUtil;
import com.evolveum.midpoint.gui.impl.prism.wrapper.ResourceWrapper;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.util.QNameUtil;
Expand Down Expand Up @@ -54,4 +55,36 @@ protected void addItemWrapper(ItemDefinition<?> def, PrismContainerValueWrapper<
}
super.addItemWrapper(def, containerValueWrapper, context, wrappers);
}

@Override
public PrismObjectWrapper<ResourceType> createObjectWrapper(PrismObject<ResourceType> object, ItemStatus status, WrapperContext context) throws SchemaException {
if (object.getOid() != null && object.asObjectable().getSuper() != null) {
long fakeId = -1;
addFakeNegativeIdForMergedValuesFromTemplate(object.getValue(), fakeId);
}
return super.createObjectWrapper(object, status, context);
}

/**
* If we use merged resource from template, then resource can contain values, of multivalued container, without id.
* GUI can process deltas from that containers, so we set fake id for that values.
**/
private void addFakeNegativeIdForMergedValuesFromTemplate(PrismContainerValue<?> parentValue, long fakeId) {
for (Item<?, ?> item : parentValue.getItems()) {
if (item.isOperational()) {
continue;
}
if (!(item instanceof PrismContainer)) {
continue;
}
PrismContainer<?> container = (PrismContainer) item;
for (PrismContainerValue<?> containerValue : container.getValues()) {
if (!container.isSingleValue() && containerValue.getId() == null && WebPrismUtil.hasValueMetadata(containerValue)) {
containerValue.setId(fakeId);
fakeId--;
}
addFakeNegativeIdForMergedValuesFromTemplate(containerValue, fakeId);
}
}
}
}

0 comments on commit 989e079

Please sign in to comment.