Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1691 fixed persisting inline "_policy" in ThingMerged events #1695

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
}
}

}