Class StateEntityServiceImpl<T extends StateEntity>

java.lang.Object
org.chenile.workflow.service.impl.StateEntityServiceImpl<T>
Type Parameters:
T -
All Implemented Interfaces:
StateEntityService<T>

public class StateEntityServiceImpl<T extends StateEntity> extends Object implements StateEntityService<T>
A generic implementation of the StateEntityService for all state entities.
This implementation uses the Chenile State Machine
The state transition diagram should be customized for the particular entity and must be read by the State Transition Machine that is injected into this service. After that, the machine would entirely control the workflow. Please read the Chenile tutorial page about how to generate a project that uses this state machine.
  • Field Details

  • Constructor Details

    • StateEntityServiceImpl

      public StateEntityServiceImpl(STM<T> stm, STMActionsInfoProvider stmActionsInfoProvider, EntityStore<T> entityStore)
      Parameters:
      stm - the state machine that has read the corresponding State Transition Diagram
      stmActionsInfoProvider - the provider that gives out info about the state diagram
      entityStore - the store for persisting the entity
  • Method Details

    • processEntity

      protected T processEntity(T entity, String event, Object payload)
      Internally used by both the create and process methods.
      Parameters:
      entity - the entity which needs to be created or processed.
      event - the event if it is not a create operation.
      payload - the payload if the event field is not null
      Returns:
      the mutated entity along with allowed actions
    • create

      public StateEntityServiceResponse<T> create(T entity)
      An implementation of the create method that delegates to the entity store after filling up the mandatory attributes. It makes sure that it empties out the state if state has been supplied because we want STM to supply the initial state.
      Specified by:
      create in interface StateEntityService<T extends StateEntity>
      Parameters:
      entity - the state entity that needs to be created.
      Returns:
      the entity with the allowed actions
    • process

      public StateEntityServiceResponse<T> process(T entity, String event, Object payload)
      An implementation of the process method that allows to track all the changes to the entity via events. This form is best suited for internal use and will not be exposed to the web. (We made the method public for some rare situations. This will be made protected over future releases)
      Specified by:
      process in interface StateEntityService<T extends StateEntity>
      Parameters:
      entity - the entity on which the event has happened
      event - - the name of the event that happened on the entity
      payload - - Additional parameters for the event (event specific)
      Returns:
      the mutated entity along with allowed actions
    • processById

      public StateEntityServiceResponse<T> processById(String id, String event, Object payload)
      This form is expected from the web. The client merely must pass the ID and the event rather than the whole entity.
      Specified by:
      processById in interface StateEntityService<T extends StateEntity>
      Parameters:
      id - - the ID of the event. This is useful if the entire entity is not passed by the front end
      event - - Name of the event that has happened on the entity
      payload - - Additional parameters for the event (event specific)
      Returns:
      the mutated entity along with allowed actions
    • getAllowedActionsAndMetadata

      public List<Map<String,String>> getAllowedActionsAndMetadata(State state)
      Specified by:
      getAllowedActionsAndMetadata in interface StateEntityService<T extends StateEntity>
    • getAllowedActionsAndMetadata

      public List<Map<String,String>> getAllowedActionsAndMetadata(String id)
      Specified by:
      getAllowedActionsAndMetadata in interface StateEntityService<T extends StateEntity>
    • makeStateEntityResponse

      protected StateEntityServiceResponse<T> makeStateEntityResponse(T entity)
    • retrieve

      public StateEntityServiceResponse<T> retrieve(String id)
      Specified by:
      retrieve in interface StateEntityService<T extends StateEntity>
      Parameters:
      id - The ID of the state entity
      Returns:
      the state entity along with allowed actions