Class ReplaceAggregateLifecycleApply

java.lang.Object
org.openrewrite.Recipe
org.axonframework.migration.ReplaceAggregateLifecycleApply
All Implemented Interfaces:
Cloneable

public class ReplaceAggregateLifecycleApply extends org.openrewrite.Recipe
Replaces calls to AggregateLifecycle.apply(...) with calls to eventAppender.append(...) on an injected EventAppender parameter, matching the AF5 entity migration pattern documented at docs/reference-guide/.../paths/aggregates/index.adoc.

For every method that contains at least one apply(...) call resolved to AF4 org.axonframework.modelling.command.AggregateLifecycle.apply (or its post-Axon4ToAxon5Modelling location org.axonframework.modelling.entity.AggregateLifecycle.apply), this recipe:

  1. injects an EventAppender eventAppender parameter into the method declaration if one is not already present;
  2. rewrites every matching apply(X) call inside that method to eventAppender.append(X);
  3. adds the import org.axonframework.messaging.eventhandling.gateway.EventAppender; import.
Idempotent: methods that no longer call apply are left alone, and the static-import cleanup is handled by maybeRemoveImport.

Constructors are explicitly skipped. AF5 constructors are for entity instantiation; they have no associated command, so the framework provides no EventAppender for them to inject. AF4 constructors that emitted a creation event via apply(...) need a non-mechanical rewrite (the creation event belongs on the static factory method produced by ConvertCommandHandlerConstructorToStaticMethod, not on the constructor) — the leftover apply(...) call is left untouched so the developer can decide.

Since:
5.1.1
Author:
Mateusz Nowak
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.openrewrite.Recipe

    org.openrewrite.Recipe.Builder, org.openrewrite.Recipe.DelegatingRecipe
  • Field Summary

    Fields inherited from class org.openrewrite.Recipe

    contributors, examples, PANIC
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
     
    org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext>
     

    Methods inherited from class org.openrewrite.Recipe

    addDataTable, builder, buildRecipeList, causesAnotherCycle, clone, createRecipeDescriptor, equals, getContributors, getDataTableDescriptors, getDescriptor, getEstimatedEffortPerOccurrence, getExamples, getInstanceName, getInstanceNameSuffix, getJacksonPolymorphicTypeTag, getMaintainers, getName, getRecipeList, getTags, hashCode, maxCycles, noop, onComplete, run, run, run, setContributors, setExamples, validate, validate, validateAll, validateAll, withOptions

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ReplaceAggregateLifecycleApply

      public ReplaceAggregateLifecycleApply()
  • Method Details

    • getDisplayName

      public String getDisplayName()
      Specified by:
      getDisplayName in class org.openrewrite.Recipe
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in class org.openrewrite.Recipe
    • getVisitor

      public org.openrewrite.TreeVisitor<?,org.openrewrite.ExecutionContext> getVisitor()
      Overrides:
      getVisitor in class org.openrewrite.Recipe