Class DefaultEntityHelper

java.lang.Object
io.fluxcapacitor.javaclient.modeling.DefaultEntityHelper
All Implemented Interfaces:
EntityHelper

public class DefaultEntityHelper extends Object implements EntityHelper
The DefaultEntityHelper provides the default implementation of the EntityHelper interface.

It is responsible for orchestrating the behavior of domain model entities with respect to: - Intercepting messages using @InterceptApply handlers - Applying updates or events via @Apply handlers - Validating updates and asserting legal state transitions using @AssertLegal handlers

This helper is heavily used during message handling and event sourcing to delegate message processing and validation logic to methods annotated on the entity class or its nested members.

The class supports efficient handler resolution through memoized lookups, enabling fast, repeatable application of complex domain behaviors.

  • Constructor Details

    • DefaultEntityHelper

      public DefaultEntityHelper(List<ParameterResolver<? super DeserializingMessage>> parameterResolvers, boolean disablePayloadValidation)
      Creates a new helper using the given parameter resolvers and configuration.
      Parameters:
      parameterResolvers - Resolvers used to inject values into annotated handler methods
      disablePayloadValidation - If true, disables bean validation of payloads
  • Method Details

    • getRootAnnotation

      public static Aggregate getRootAnnotation(Class<?> type)
      Returns the cached or default @Aggregate annotation for a given type.
    • intercept

      public Stream<?> intercept(Object value, Entity<?> entity)
      Intercepts the given value using @InterceptApply methods defined on the entity. Interceptors may transform or replace the original message.
      Specified by:
      intercept in interface EntityHelper
      Parameters:
      value - the value to be intercepted, typically the payload of a message
      entity - the entity receiving the value
      Returns:
      a stream of intercepted values or messages to be applied
    • getInterceptInvoker

      Recursively resolves the best-matching interceptor method, including nested members.
    • applyInvoker

      public Optional<HandlerInvoker> applyInvoker(DeserializingMessage event, Entity<?> entity, boolean searchChildren)
      Finds a handler method annotated with @Apply and wraps it to preserve apply context flags.
      Specified by:
      applyInvoker in interface EntityHelper
      Parameters:
      event - the event to apply
      entity - the root or intermediate entity
      searchChildren - whether to search nested child entities for applicable handlers
      Returns:
      a handler invoker if a suitable method is located
    • assertLegal

      public <E extends Exception> void assertLegal(Object value, Entity<?> entity) throws E
      Performs a validation check using @AssertLegal handlers for the provided payload. This method is called both before and after the handler completes, depending on the annotation's settings.
      Specified by:
      assertLegal in interface EntityHelper
      Type Parameters:
      E - the type of exception that may be thrown
      Parameters:
      value - the value to validate
      entity - the current entity state
      Throws:
      E - if the value is deemed illegal
    • checkLegality

      public <E extends Exception> Optional<E> checkLegality(Object value, Entity<?> entity)
      Returns an exception if the value is illegal for the current entity, or Optional.empty() if legal.
      Specified by:
      checkLegality in interface EntityHelper
      Type Parameters:
      E - the type of exception
      Parameters:
      value - the value to validate
      entity - the entity context
      Returns:
      an exception if illegal, or an empty Optional if legal
    • isLegal

      public boolean isLegal(Object value, Entity<?> entity)
      Convenience method that returns true if checkLegality(java.lang.Object, io.fluxcapacitor.javaclient.modeling.Entity<?>) yields no error.
      Specified by:
      isLegal in interface EntityHelper
      Parameters:
      value - the value to check
      entity - the entity context
      Returns:
      true if legal, false otherwise