Skip to content

Commit

Permalink
#1691 fixed persisting inline "_policy" in ThingMerged events
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Jäckle <thomas.jaeckle@beyonnex.io>
  • Loading branch information
thjaeckle committed Jul 17, 2023
1 parent 3a0419a commit df4462c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ public String toString() {
/**
* An enumeration of the JSON fields of a {@code ThingMerged} event.
*/
static final class JsonFields {
public static final class JsonFields {

private JsonFields() {
throw new AssertionError();
}

static final JsonFieldDefinition<String> JSON_PATH =
public static final JsonFieldDefinition<String> JSON_PATH =
JsonFactory.newStringFieldDefinition("path", FieldType.REGULAR, JsonSchemaVersion.V_2);

static final JsonFieldDefinition<JsonValue> JSON_VALUE =
public static final JsonFieldDefinition<JsonValue> JSON_VALUE =
JsonFactory.newJsonValueFieldDefinition("value", FieldType.REGULAR, JsonSchemaVersion.V_2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.policies.model.Policy;
import org.eclipse.ditto.things.model.signals.events.ThingEvent;
import org.eclipse.ditto.things.model.signals.events.ThingMerged;
import org.eclipse.ditto.things.service.common.config.DefaultThingConfig;

import akka.actor.ExtendedActorSystem;
Expand All @@ -35,6 +36,10 @@ public final class ThingMongoEventAdapter extends AbstractMongoEventAdapter<Thin
private static final JsonPointer POLICY_IN_THING_EVENT_PAYLOAD = ThingEvent.JsonFields.THING.getPointer()
.append(JsonPointer.of(Policy.INLINED_FIELD_NAME));

private static final JsonPointer POLICY_IN_THING_MERGED_VALUE_PAYLOAD =
ThingMerged.JsonFields.JSON_VALUE.getPointer()
.append(JsonPointer.of(Policy.INLINED_FIELD_NAME));

public ThingMongoEventAdapter(final ExtendedActorSystem system) {
super(system, GlobalEventRegistry.getInstance(), DefaultThingConfig.of(
DittoServiceConfig.of(DefaultScopedConfig.dittoScoped(system.settings().config()), "things")
Expand All @@ -43,8 +48,13 @@ public ThingMongoEventAdapter(final ExtendedActorSystem system) {

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

}

0 comments on commit df4462c

Please sign in to comment.