Class WorkflowRegistry

java.lang.Object
com.axelor.workflow.registry.WorkflowRegistry
All Implemented Interfaces:
WorkflowDefinitions

@Singleton public class WorkflowRegistry extends Object implements WorkflowDefinitions
Resolves the ordered workflows eligible for a model and trigger: each (model, jsonModel, name) collapses to its highest-priority active definition, ordered by sequence, then id. It also keeps, per tenant, which models have any workflow, so the flush listener never queries. Snapshots rebuild when a (count, sum(version), max(id)) stamp over META_WORKFLOW moves, checked at dispatch, on repository saves and on each scheduler poll. Bulk JPQL updates bypass the stamp; the repository is the supported write path.
  • Constructor Details

    • WorkflowRegistry

      public WorkflowRegistry()
  • Method Details

    • dispatches

      public boolean dispatches(String model, String jsonModel)
      Whether a save here could dispatch a workflow. Answers from memory and says true before any snapshot exists.
      Specified by:
      dispatches in interface WorkflowDefinitions
      Parameters:
      jsonModel - the custom model, when model is MetaJsonRecord; else null
    • currentStamp

      public String currentStamp()
      The engine's contract; delegates to stamp().
      Specified by:
      currentStamp in interface WorkflowDefinitions
    • stamp

      public static String stamp()
      The stamp this tenant's snapshot was built on, or null before one exists. Read from memory, for the capture written during a business transaction.
    • hasWorkflows

      public boolean hasWorkflows(String model, String jsonModel)
      Whether any workflow could be bound to a record here, manual ones included; the same fail-open rule.
      Specified by:
      hasWorkflows in interface WorkflowDefinitions
      Parameters:
      jsonModel - the custom model, when model is MetaJsonRecord; else null
    • refresh

      public void refresh()
      Rebuild this tenant's snapshot when the stamp has moved. count catches deletes, the version sum updates, and max(id) an insert that happens to restore both. Needs an EntityManager; never call from a flush.
      Specified by:
      refresh in interface WorkflowDefinitions
    • evict

      public void evict()
      Drop every cached snapshot. dispatches(java.lang.String, java.lang.String) fails open until the next refresh().
    • resolve

      public List<WorkflowRegistration> resolve(String model, String jsonModel, TriggerKind trigger)
      Description copied from interface: WorkflowDefinitions
      The definitions eligible for this record and trigger, in the order they should run.
      Specified by:
      resolve in interface WorkflowDefinitions
    • startingOn

      public List<WorkflowRegistration> startingOn(String messageName)
      The definitions that start on this message name, across every model. The name is in the XML, so this compiles the message-started definitions once per name per snapshot.
      Specified by:
      startingOn in interface WorkflowDefinitions
    • resolveOne

      public MetaWorkflow resolveOne(String name, String model, String jsonModel)
      The effective definition for (model, jsonModel, name), for a programmatic run.
      Specified by:
      resolveOne in interface WorkflowDefinitions
    • resolveByName

      public MetaWorkflow resolveByName(String model, String jsonModel, String name)
      The effective (highest-priority active) workflow for an override key, or null.
    • identityOf

      public WorkflowCatalog.WorkflowRef identityOf(String name)
      The identity of the active workflow named name, or null; throws when the name is used on several models.
    • resolveByRef

      public MetaWorkflow resolveByRef(String name)
      The highest-priority active workflow named name, or null.
      Specified by:
      resolveByRef in interface WorkflowDefinitions