Skip to content

Commit

Permalink
fix that JsonObjectBuilder.remove removes too much in certain cases
Browse files Browse the repository at this point in the history
* also make ThingMongoEventAdapter more resilient, removing an inline policy from ThingMerged events

Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Nov 8, 2023
1 parent d008959 commit 4697680
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
Expand Up @@ -175,7 +175,7 @@ private ImmutableJsonObjectBuilder remove(final JsonPointer pointer) {
rootObject = rootObject.remove(nextPointerLevel);
set(JsonFactory.newField(jsonField.getKey(), rootObject,
jsonField.getDefinition().orElse(null)));
} else {
} else if (nextPointerLevel.isEmpty()) {
fields.remove(jsonField.getKeyName());
}
});
Expand Down
Expand Up @@ -289,6 +289,7 @@ public void removeWithJsonPointerWorksAsExpected() {
.set(robert)
.set(cersei)
.remove(JsonFactory.newPointer(fooKey, bazKey))
.remove(JsonFactory.newPointer(robert.getKey(), JsonKey.of("non-existing")))
.build();

assertThat(actualJsonObject).isEqualTo(expectedJsonObject);
Expand Down
Expand Up @@ -12,6 +12,7 @@
*/
package org.eclipse.ditto.things.service.persistence.serializer;

import org.apache.pekko.actor.ExtendedActorSystem;
import org.eclipse.ditto.base.model.signals.events.Event;
import org.eclipse.ditto.base.model.signals.events.GlobalEventRegistry;
import org.eclipse.ditto.base.service.config.DittoServiceConfig;
Expand All @@ -25,8 +26,6 @@
import org.eclipse.ditto.things.model.signals.events.ThingMerged;
import org.eclipse.ditto.things.service.common.config.DefaultThingConfig;

import org.apache.pekko.actor.ExtendedActorSystem;

/**
* EventAdapter for {@link Event}s persisted into pekko-persistence event-journal. Converts Event to MongoDB
* BSON objects and vice versa.
Expand All @@ -48,7 +47,7 @@ public ThingMongoEventAdapter(final ExtendedActorSystem system) {

@Override
protected JsonObjectBuilder performToJournalMigration(final Event<?> event, final JsonObject jsonObject) {
if (event instanceof ThingMerged) {
if (event instanceof ThingMerged thingMerged && thingMerged.getResourcePath().isEmpty()) {
return super.performToJournalMigration(event, jsonObject)
.remove(POLICY_IN_THING_MERGED_VALUE_PAYLOAD); // remove the policy entries from thing merged payload
} else {
Expand Down

0 comments on commit 4697680

Please sign in to comment.