Please help because there seems to be something I’m missing when modifying state transitions.
I’ve added a new state “Partially Completed” this should reflect the fact that some items in an order have been “Delivered”. The complication is that we do not know how many deliveries we have ahead of time.
Here is the scenario:
Order is placed for 2 items, and the order gets a default delivery record for all OrderRows
ItemA is delivered, add a new Delivery to the Order and set OrderRow.DeliveryId to the new Delivery.ID
ItemB is delivered, add a new Delivery to the Order and set OrderRow.DeliveryId to the new Delivery.ID
Both items have been delivered (and hence does not have related OrderRows anymore), so the original delivery gets set to Delivered
I’ve modified both the OrderStateBuilder to allow transition to PartiallyCompleted when not all Deliveries are in State Delivered; Completed when ALL Deliveries are in state Delivered
I’ve also added a related state to the DeliveryStateMachine to include a DeliveryState.Delivered to an OrderState.PartiallyDelivered (in addition to the previously existing related state DeliveryState to OrderState.Completed).
When running the OrderStateBuilder is invoked when the first Delivery is made (ItemA) but no longer after that (delivering ItemB cause no changes in the state machine).
I should additionally point out that after adding the related state for PartiallyCompleted, the second Delivery state does not actually change when I call SetDeliveryStatus
Any tips? Anything else I should be thinking about?
We need to send notifications for deliveries and to ensure that an intermediate state can be used to treat the order as not completed but passed the initial “Processing” state
In the OrderStateMachine I’ve defined a transition for
(A) Processing → ParitallyCompleted when ANY delivery is set to DeliveryState.Delivered; and
(B) PartiallyCompleted → Completed when ALL deliveries are set to DeliveryState.Delivered
We want to do this for purely functional reasons. The external client needs to be notified of order confirmation, each individual delivery and ultimately completion.
As it turns out, there was a constraint on transitioning a Delivery from DeliveryState.Init to DeliveryState.Processing where the OrderState had to have OrderState.Processing.
This is of course not the case with my scenario as the Order has transitioned from OrderState.Processing to OrderState.PartiallyCompleted.
Adding OrderState.PartiallyCompleted to this Delivery constraint solved my problem!
Note to self, analyze ALL state transitions to understand how the 2 engines interact with each other.