Record Class Associations

java.lang.Object
java.lang.Record
io.axoniq.framework.workflow.runtime.association.Associations

public record Associations(ValueComparisonOperatorRegistry registry, Set<String> criteria) extends Record
Immutable value object representing one or more association constraints used to correlate incoming events with a waiting workflow step.

Each entry in criteria() is stored in the canonical serialized association DSL form <source>:<path><operator><value>, for example payload:orderId=123. At runtime the workflow engine evaluates these criteria against candidate events to determine whether an event belongs to the waiting step.

There are two primary construction styles:

  1. Programmatic construction using associate(ValueRetriever, Matcher) or associate(ValueRetriever, String, Object). This is the normal author-facing path used by workflow code. Start with one association and optionally extend it with and(ValueRetriever, Matcher) or and(ValueRetriever, String, Object).
  2. Parsing canonical string representations using parse(ValueComparisonOperatorRegistry, String...), which is useful for configuration-driven or persisted association definitions.

Typical usage from workflow code looks like this:


 var associations = Associations.associate(
         payloadProperty("orderId"),
         Matcher("=", workflowOrderId)
 ).and(
         payloadProperty("tenantId"),
         Matcher("=", tenantId)
 );
 
The DSL layer usually wraps this with friendlier helpers such as associate(payloadProperty("orderId"), equalsTo(...)), but those helpers still produce this same Associations value object underneath.

This type is immutable. Methods such as and(ValueRetriever, Matcher) return a new Associations instance instead of mutating the existing one, which makes it safe to reuse base association sets across workflow definitions.

Since:
5.4.0
Author:
Simon Zambrovski
  • Constructor Details

    • Associations

      public Associations(ValueComparisonOperatorRegistry registry, Set<String> criteria)
      Creates new associations.
      Parameters:
      registry - operator registry to use
      criteria - association criteria
  • Method Details

    • associate

      public static Associations associate(ValueRetriever retriever, String operator, Object value)
      Create new associations providing the first one.
      Parameters:
      retriever - value retriever, see PayloadPropertyValueRetriever.payloadProperty(String) for example.
      operator - operator for value comparison
      value - right side of comparison
      Returns:
      an association upon which can be build further, for fluent interface.
    • associate

      public static Associations associate(ValueRetriever retriever, Associations.Matcher matcher)
      Create associations providing the first one.
      Parameters:
      retriever - value retriever, see PayloadPropertyValueRetriever.payloadProperty(String) for example.
      matcher - variable matcher, see Associations.Matcher for example.
      Returns:
      an association upon which can be build further, for fluent interface
    • parse

      public static Associations parse(ValueComparisonOperatorRegistry registry, String... associations)
      Creates new associations parsing string representations.
      Parameters:
      registry - registry to use
      associations - associations to parse
      Returns:
      associations instance
    • and

      public Associations and(ValueRetriever retriever, String operator, Object value)
      Add additional associations to existing ones.
      Parameters:
      retriever - value retriever for the left side of the comparison, see PayloadPropertyValueRetriever.payloadProperty(String) for example.
      operator - operator for value comparison
      value - right side of comparison
      Returns:
      new associations containing old associations and new one
    • and

      public Associations and(ValueRetriever retriever, Associations.Matcher matcher)
      Add additional association to existing ones.
      Parameters:
      retriever - value retriever for the left side of the comparison, see PayloadPropertyValueRetriever.payloadProperty(String) for example.
      matcher - value matcher including operator and value for comparison
      Returns:
      new associations containing old associations and new one
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • registry

      Returns the value of the registry record component.
      Returns:
      the value of the registry record component
    • criteria

      public Set<String> criteria()
      Returns the value of the criteria record component.
      Returns:
      the value of the criteria record component