Skip to content

Commit

Permalink
Make swallowToPrimaryDelta work with frozen deltas
Browse files Browse the repository at this point in the history
Primary deltas are now frozen in lens element contexts. But we sometimes
need to modify them e.g. in scripting hooks. The swallowToPrimaryDelta
was changed to allow this.

Resolves MID-6097.
  • Loading branch information
mederly committed Mar 5, 2020
1 parent 1a766a4 commit 4a99b9d
Showing 1 changed file with 28 additions and 3 deletions.
Expand Up @@ -259,11 +259,36 @@ public void addPrimaryDelta(ObjectDelta<O> delta) throws SchemaException {
}

public void swallowToPrimaryDelta(ItemDelta<?,?> itemDelta) throws SchemaException {
createOrModifyPrimaryDelta(
delta -> delta.swallow(itemDelta),
() -> {
ObjectDelta<O> newPrimaryDelta = getPrismContext().deltaFactory().object().create(getObjectTypeClass(), ChangeType.MODIFY);
newPrimaryDelta.setOid(oid);
newPrimaryDelta.addModification(itemDelta);
return newPrimaryDelta;
});
}

@FunctionalInterface
private interface DeltaModifier<O extends Objectable> {
void modify(ObjectDelta<O> delta) throws SchemaException;
}

@FunctionalInterface
private interface DeltaCreator<O extends Objectable> {
ObjectDelta<O> create() throws SchemaException;
}

private void createOrModifyPrimaryDelta(DeltaModifier<O> modifier, DeltaCreator<O> creator) throws SchemaException {
if (primaryDelta == null) {
primaryDelta = getPrismContext().deltaFactory().object().create(getObjectTypeClass(), ChangeType.MODIFY);
primaryDelta.setOid(oid);
primaryDelta = creator.create();
} else if (!primaryDelta.isImmutable()) {
modifier.modify(primaryDelta);
} else {
primaryDelta = primaryDelta.clone();
modifier.modify(primaryDelta);
primaryDelta.freeze();
}
primaryDelta.swallow(itemDelta);
}

public abstract void swallowToSecondaryDelta(ItemDelta<?,?> itemDelta) throws SchemaException;
Expand Down

0 comments on commit 4a99b9d

Please sign in to comment.