Class Event

java.lang.Object
net.pincette.jes.Event

public class Event extends Object
Utilities to work with events.
Since:
3.0
Author:
Werner Donné
  • Method Details

    • added

      public static boolean added(JsonObject event, String jsonPointer)
      Returns true if the field at jsonPointer was added. It examines the _ops field for this.
      Parameters:
      event - the full event, which has the _before field.
      jsonPointer - the path into the aggregate.
      Returns:
      true when the event expresses the addition of the given field.
      Since:
      1.4.1
    • applyEvent

      public static JsonObject applyEvent(JsonObject aggregate, JsonObject event)
      Applies an event to an aggregate instance, which results in the next version of the aggregate.
      Parameters:
      aggregate - the given aggregate instance.
      event - the given event.
      Returns:
      The next version of the aggregate instance.
      Since:
      1.2
    • changed

      public static boolean changed(JsonObject event, String jsonPointer)
      Returns true if the field at jsonPointer has changed. It examines the _ops field for this.
      Parameters:
      event - the event.
      jsonPointer - the path into the aggregate.
      Returns:
      true when the event expresses a change of the given field.
      Since:
      1.0
    • changed

      public static boolean changed(JsonObject event, String jsonPointer, JsonValue from, JsonValue to)
      Returns true if the field at jsonPointer has changed from the value in from to the value in to. It examines the _ops field for this.
      Parameters:
      event - the full event, which has the _before field.
      jsonPointer - the path into the aggregate.
      from - the original value.
      to - the new value.
      Returns:
      true when the event expresses a change of the given field.
      Since:
      1.0
    • isEvent

      public static boolean isEvent(JsonObject event)
      Checks if event has the proper event structure. This means it should be a managed object with an _ops field.
      Parameters:
      event - the given event.
      Returns:
      The check report.
      Since:
      1.0
      See Also:
    • isNext

      public static boolean isNext(JsonObject aggregate, JsonObject event)
      Checks if the event has the next sequence number for the aggregate. Event log replicators can use this to detect corruption.
      Parameters:
      aggregate - the aggregate instance.
      event - the event.
      Returns:
      true if the event is the next one, false otherwise.
      Since:
      1.0
    • removed

      public static boolean removed(JsonObject event, String jsonPointer)
      Returns true if the field at jsonPointer was removed. It examines the _ops field for this.
      Parameters:
      event - the event.
      jsonPointer - the path into the aggregate.
      Returns:
      true when the event expresses the removal of the given field.
      Since:
      1.4.1
    • sequenceErrorMessage

      public static String sequenceErrorMessage(JsonObject aggregate, JsonObject event)
      Creates a standard message to alert event sequence errors. Events are numbered with the _seq field. When an event listener detect a "hole" in the numbering it can use this message to log the corruption.
      Parameters:
      aggregate - the aggregate about which the error message is produced.
      event - the event about which the error message is produced.
      Returns:
      The generated error message.
      Since:
      1.0