Skip to content

Commit

Permalink
sqale: Container IDs are unique only inside container, not whole object
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Aug 30, 2021
1 parent b49012b commit e740204
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class ContainerValueIdGenerator {
private static final Trace LOGGER = TraceManager.getTrace(ContainerValueIdGenerator.class);

private final PrismObject<? extends ObjectType> object;
private final Set<Long> usedIds = new HashSet<>();
private final Set<Long> overwrittenIds = new HashSet<>(); // ids of PCV overwritten by ADD
private final List<PrismContainerValue<?>> pcvsWithoutId = new ArrayList<>();

Expand Down Expand Up @@ -98,7 +97,7 @@ private void freeIdsFromReplacedContainer(ItemDelta<?, ?> modification) {
ItemDefinition<?> definition = modification.getDefinition();
// we check all containers, even single-value container can contain multi-value ones
if (definition instanceof PrismContainerDefinition<?>) {
Visitable<?> container = object.findContainer(modification.getPath());
Visitable container = object.findContainer(modification.getPath());
if (container != null) {
container.accept(visitable -> {
if (visitable instanceof PrismContainer
Expand All @@ -125,7 +124,6 @@ private void identifyReplacedContainers(ItemDelta<?, ?> modification) {
if (oldValue != null) {
Long cid = oldValue.getId();
overwrittenIds.add(cid);
usedIds.remove(cid); // technically, it's used, new PCV will take it again
pcv.setId(cid);
}
}
Expand All @@ -134,12 +132,6 @@ private void identifyReplacedContainers(ItemDelta<?, ?> modification) {
}

private void freeContainerIds(PrismContainer<?> container) {
for (PrismContainerValue<?> val : container.getValues()) {
Long cid = val.getId();
if (cid != null) {
usedIds.remove(cid);
}
}
}

private void processModificationValues(Collection<? extends PrismValue> values)
Expand All @@ -149,8 +141,9 @@ private void processModificationValues(Collection<? extends PrismValue> values)
if (prismValue instanceof PrismContainerValue) {
PrismContainerValue<?> pcv = (PrismContainerValue<?>) prismValue;
// the top level value is not covered by checkExistingContainers()
// FIXME: How to process here?
if (pcv.getDefinition().isMultiValue()) {
processContainerValue(pcv);
processContainerValue(pcv, new HashSet<>());
}

checkExistingContainers(pcv);
Expand All @@ -163,7 +156,7 @@ private void processModificationValues(Collection<? extends PrismValue> values)
* Checks the provided container (possibly the whole object) and finds values requiring CID.
* This does NOT cover top-level PCV if provided as parameter.
*/
private void checkExistingContainers(Visitable<?> object) throws SchemaException {
private void checkExistingContainers(Visitable object) throws SchemaException {
try {
object.accept(visitable -> {
if (visitable instanceof PrismContainer
Expand All @@ -179,17 +172,18 @@ private void checkExistingContainers(Visitable<?> object) throws SchemaException
}

private void processContainer(PrismContainer<?> container) {
Set<Long> usedIds = new HashSet<>();
for (PrismContainerValue<?> val : container.getValues()) {
processContainerValue(val);
processContainerValue(val, usedIds);
}
}

private void processContainerValue(PrismContainerValue<?> val) {
private void processContainerValue(PrismContainerValue<?> val, Set<Long> usedIds) {
Long cid = val.getId();
if (cid != null) {
if (!usedIds.add(cid)) {
maxUsedId = cid;
throw DuplicateContainerIdException.INSTANCE;
//maxUsedId = cid;
//throw DuplicateContainerIdException.INSTANCE;
}
maxUsedId = Math.max(maxUsedId, cid);
} else {
Expand Down

0 comments on commit e740204

Please sign in to comment.