@Override public String manifest(final Object event) { if (event instanceof Event) { return ((Event) event).getType(); } else { throw new IllegalArgumentException( "Unable to create manifest for a non-'Event' object! Was: " + event.getClass()); } }
@Override default JsonSchemaVersion getImplementedSchemaVersion() { return getDittoHeaders().getSchemaVersion().orElse(getLatestSchemaVersion()); }
/** * Returns all non hidden marked fields of this event. * * @return a JSON object representation of this event including only non hidden marked fields. */ @Override default JsonObject toJson() { return toJson(FieldType.notHidden()); }
/** * Creates a new {@code PolicyDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new PolicyDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code PolicyDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'PolicyDeleted' format. */ public static PolicyDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<PolicyDeleted>(TYPE, jsonObject).deserialize( (revision, timestamp) -> of(jsonObject.getValueOrThrow(JsonFields.POLICY_ID), revision, timestamp, dittoHeaders)); }
private <E extends Event<?>> void forwardEventToShardRegion(final E message, final Function<E, String> getId) { forwardToShardRegion( message, getId, Event::getType, event -> event.toJson(event.getImplementedSchemaVersion(), FieldType.regularOrSpecial()), Event::getDittoHeaders); }
public S hasResourcePath(final JsonPointer expectedResourcePath) { isNotNull(); final JsonPointer actualResourcePath = actual.getResourcePath(); Assertions.assertThat((CharSequence) actualResourcePath) .overridingErrorMessage("Expected Event to have resource path\n<%s> but it had\n<%s>", expectedResourcePath, actualResourcePath) .isEqualTo(expectedResourcePath); return myself; }
public S hasRevision(final long expectedRevision) { isNotNull(); final long actualRevision = actual.getRevision(); Assertions.assertThat(actualRevision) .overridingErrorMessage("Expected Event to have revision\n<%s> but it had\n<%s>", expectedRevision, actualRevision) .isEqualTo(expectedRevision); return myself; }
public S hasManifest(final CharSequence expectedManifest) { isNotNull(); final String actualManifest = actual.getManifest(); Assertions.assertThat(actualManifest) .overridingErrorMessage("Expected Event to have manifest\n<%s> but it had\n<%s>", expectedManifest, actualManifest) .isEqualTo(expectedManifest); return myself; }
@Override public Adaptable toAdaptable(final Event<?> event, final TopicPath.Channel channel) { if (event instanceof ThingEvent) { return toAdaptable((ThingEvent) event, channel); } else { throw UnknownEventException.newBuilder(event.getName()).build(); } }
/** * Constructs a new {@code EventJsonDeserializer} object. * * @param type the type of the target event of deserialization. * @param jsonObject the JSON object to deserialized. * @throws NullPointerException if any argument is {@code null}. * @throws IllegalArgumentException if {@code type} is empty or does not contain a type prefix. */ public EventJsonDeserializer(final String type, final JsonObject jsonObject) { validateType(argumentNotEmpty(type, "event type")); checkNotNull(jsonObject, "JSON object to be deserialized"); this.jsonObject = jsonObject; expectedType = type; eventTypePrefix = type.split(":")[0]; }
/** * Creates a new {@code PolicyDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new PolicyDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code PolicyDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'PolicyDeleted' format. */ public static PolicyDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<PolicyDeleted>(TYPE, jsonObject).deserialize( (revision, timestamp) -> of(jsonObject.getValueOrThrow(JsonFields.POLICY_ID), revision, timestamp, dittoHeaders)); }
@Override public String manifest(final Object event) { if (event instanceof Event) { return ((Event) event).getType(); } else { throw new IllegalArgumentException( "Unable to create manifest for a non-'Event' object! Was: " + event.getClass()); } }
private <E extends Event<?>> void forwardEventToShardRegion(final E message, final Function<E, String> getId) { forwardToShardRegion( message, getId, Event::getType, event -> event.toJson(event.getImplementedSchemaVersion(), FieldType.regularOrSpecial()), Event::getDittoHeaders); }
/** * Creates a new {@code AttributesDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new AttributesDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code AttributesDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'AttributesDeleted' format. */ public static AttributesDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<AttributesDeleted>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String extractedThingId = jsonObject.getValueOrThrow(JsonFields.THING_ID); return of(extractedThingId, revision, dittoHeaders); }); }
@Override public String manifest(final Object event) { if (event instanceof Event) { return ((Event) event).getType(); } else { throw new IllegalArgumentException( "Unable to create manifest for a non-'Event' object! Was: " + event.getClass()); } }
/** * Creates a new {@code ThingDeleted} from a JSON object. * * @param jsonObject the JSON object from which a new ThingDeleted instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code ThingDeleted} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'ThingDeleted' format. */ public static ThingDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<ThingDeleted>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String extractedThingId = jsonObject.getValueOrThrow(JsonFields.THING_ID); return of(extractedThingId, revision, timestamp, dittoHeaders); }); }
@Override public String manifest(final Object event) { if (event instanceof Event) { return ((Event) event).getType(); } else { throw new IllegalArgumentException( "Unable to create manifest for a non-'Event' object! Was: " + event.getClass()); } }
/** * Creates a {@code ConnectionDeleted} event from a JSON object. * * @param jsonObject the JSON object of which the event is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the event. * @throws NullPointerException if any argument is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * format. */ public static ConnectionDeleted fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<ConnectionDeleted>(TYPE, jsonObject) .deserialize((revision, timestamp) -> { final String readConnectionId = jsonObject.getValueOrThrow(JsonFields.CONNECTION_ID); return of(readConnectionId, timestamp, dittoHeaders); }); }
private <E extends Event> void persistEvent(final E event, final Consumer<E> consumer) { persist(event, persistedEvent -> { log.info("Successfully persisted Event '{}'", persistedEvent.getType()); consumer.accept(persistedEvent); // save a snapshot if there were too many changes since the last snapshot if ((lastSequenceNr() - lastSnapshotSequenceNr) > snapshotThreshold) { doSaveSnapshot(); } }); }
/** * Creates a new {@code PolicyIdModified} from a JSON object. * * @param jsonObject the JSON object from which a new PolicyIdModified instance is to be created. * @param dittoHeaders the headers of the command which was the cause of this event. * @return the {@code PolicyIdModified} which was created from the given JSON object. * @throws NullPointerException if {@code jsonObject} is {@code null}. * @throws org.eclipse.ditto.json.JsonParseException if the passed in {@code jsonObject} was not in the expected * 'PolicyIdModified' format. */ public static PolicyIdModified fromJson(final JsonObject jsonObject, final DittoHeaders dittoHeaders) { return new EventJsonDeserializer<PolicyIdModified>(TYPE, jsonObject).deserialize((revision, timestamp) -> { final String extractedThingId = jsonObject.getValueOrThrow(JsonFields.THING_ID); final String extractedPolicyId = jsonObject.getValueOrThrow(JSON_POLICY_ID); return of(extractedThingId, extractedPolicyId, revision, timestamp, dittoHeaders); }); }