Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

java - How to transition another substate before transitioning to parent end state

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...