How can I always transition to FULFILLMENT_ORDER_CANCELLED
substate before transitioning to OrderState.CANCELLED
state.
For Example:
Suppose, I want to cancel an order. I would trigger event OrderEvent.CANCEL
. With this event, Order should get cancelled and should end at OrderState.CANCELLED
. But before cancel I want to transition to FULFILLMENT_ORDER_CANCELLED
state and then to OrderState.CANCELLED
.
Sample flow required is:
Trigger OrderEvent.CANCEL
-> OrderState.FULFILLMENT_ORDER_CANCELLED
-> OrderState.CANCELLED
.
This is required from all other states as well, whenever cancel gets trigger same flow should is needed.
states
.withStates()
.initial(OrderState.START)
.states(EnumSet.allOf(OrderState.class))
.end(OrderState.DELIVERED)
.end(OrderState.CANCELLED)
.and()
.withStates()
.parent(OrderState.CREATED)
.initial(OrderState.FULFILLMENT_ORDER_CREATED)
.state(OrderState.FULFILLMENT_ORDER_CREATED)
.state(OrderState.FULFILLMENT_ORDER_PROCESSING)
.state(OrderState.FULFILLMENT_ORDER_PENDING_FOR_STOCK)
.state(OrderState.FULFILLMENT_ORDER_PACKED)
.state(OrderState.FULFILLMENT_ORDER_INVOICED)
.state(OrderState.FULFILLMENT_ORDER_CANCELLED)
.and()
.withStates()
.parent(OrderState.DELIVERY_IN_PROCESS)
.state(OrderState.OUT_FOR_DELIVERY)
.state(OrderState.UNATTEMPTED);
transitions
.withExternal()
.source(OrderState.START).target(OrderState.CREATED).event(OrderEvent.CREATE)
.and()
.withExternal()
.source(OrderState.CREATED).target(OrderState.FULFILLMENT_ORDER_CREATED).event(OrderEvent.FULFILLMENT_ORDER_CREATE)
.and()
.withExternal()
.source(OrderState.FULFILLMENT_ORDER_CREATED).target(OrderState.FULFILLMENT_ORDER_PROCESSING).event(OrderEvent.FULFILLMENT_ORDER_PROCESS)
.and()
.withExternal()
.source(OrderState.FULFILLMENT_ORDER_PROCESSING).target(OrderState.FULFILLMENT_ORDER_PACKED).event(OrderEvent.FULFILLMENT_ORDER_PACKED)
.and()
.withExternal()
.source(OrderState.FULFILLMENT_ORDER_PACKED).target(OrderState.BILLED).event(OrderEvent.BILLED)
.and()
.withExternal()
.source(OrderState.BILLED).target(OrderState.DELIVERED).event(OrderEvent.DELIVERED)
.and()
.withExternal()
.source(OrderState.BILLED).target(OrderState.CANCELLED).event(OrderEvent.CANCEL);
```
question from:
https://stackoverflow.com/questions/65875629/how-to-transition-another-substate-before-transitioning-to-parent-end-state 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…