You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * The incorporate method uses a simple state machine for an order's status to generate * the current state of an order using event sourcing and aggregation. * <p> * The event diagram below represents how events are incorporated into generating the * order status. The event log for the order status can be used to rollback the state * of the order in the case of a failed distributed transaction. * <p> * Events: +<--PURCHASED+ +<--CREATED+ +<---ORDERED+ +<----SHIPPED+ * * | | | | | | | | * Status +PURCHASED---+PENDING------+CONFIRMED-----+SHIPPED--------+DELIVERED * * | | | | | | | | * Events: +CREATED---->+ +ORDERED-->+ +SHIPPED--->+ +DELIVERED-->+ * * @param orderEvent is the event to incorporate into the state machine * @return the aggregate {@link Order} with the aggregated order status */publicOrderincorporate(OrderEventorderEvent) {
if (orderStatus == null)
orderStatus = OrderStatus.PURCHASED;
switch (orderStatus) {
casePURCHASED:
if (orderEvent.getType() == OrderEventType.CREATED)
orderStatus = OrderStatus.PENDING;
break;
casePENDING:
if (orderEvent.getType() == OrderEventType.ORDERED) {
orderStatus = OrderStatus.CONFIRMED;
} elseif (orderEvent.getType() == OrderEventType.PURCHASED) {
orderStatus = OrderStatus.PURCHASED;
}
break;
caseCONFIRMED:
if (orderEvent.getType() == OrderEventType.SHIPPED) {
orderStatus = OrderStatus.SHIPPED;
} elseif (orderEvent.getType() == OrderEventType.CREATED) {
orderStatus = OrderStatus.PENDING;
}
break;
caseSHIPPED:
if (orderEvent.getType() == OrderEventType.DELIVERED) {
orderStatus = OrderStatus.DELIVERED;
} elseif (orderEvent.getType() == OrderEventType.ORDERED) {
orderStatus = OrderStatus.CONFIRMED;
}
break;
caseDELIVERED:
if (orderEvent.getType() == OrderEventType.SHIPPED)
orderStatus = OrderStatus.SHIPPED;
break;
default:
// Invalid event type with regards to the order statusbreak;
}
returnthis;
}
The text was updated successfully, but these errors were encountered:
https://github.com/kbastani/spring-cloud-event-sourcing-example/blob/master/order-service/src/main/java/demo/order/Order.java#L86-L144
The text was updated successfully, but these errors were encountered: