I have a Task JPA @Entity which has field state - so it looks like state machine could be good abstraction to work with. The state may change by calling a REST endpoint in form like PUT /api/tasks/{id}/state. I wanted to utilize the concept of Actions, Guards as it looks like nice abstractions. I guess I need something along:
- In the REST endpoint create (or rather restore?) the state machine in state corresponding to the current
Tasks's state and associate the JPA entity with it's context so it is available forActions which can change thestatetask's state field (and others) and persist it back throughRepository - Send the event representing transition to new state
I assume point 1. will create the machine through builder as with @EnableStateMachineFactory you cannot really create the machine in particular state (which kind of make sense). I'm unclear how to add the entity which I probably findOne in @Repository to the state machine's context.
Would that be the right approach? Is there a sample covering this? I was pretty honest in going through the existing samples and didn't find anything similar.