Permalink
Browse files

More changes for the saga stuff, needed to make the api more consitent

  • Loading branch information...
1 parent 5974299 commit 15ad3e6ee0bf4f240d0802f68ceb7ffa5a4f32da @jettro jettro committed Dec 5, 2011
Showing with 208 additions and 129 deletions.
  1. +14 −5 ...main/java/org/axonframework/samples/trader/app/api/portfolio/item/AddItemsToPortfolioCommand.java
  2. +8 −5 ...axonframework/samples/trader/app/api/portfolio/item/CancelItemReservationForPortfolioCommand.java
  3. +8 −5 ...xonframework/samples/trader/app/api/portfolio/item/ConfirmItemReservationForPortfolioCommand.java
  4. +5 −5 ...xonframework/samples/trader/app/api/portfolio/item/ItemReservationCancelledForPortfolioEvent.java
  5. +5 −5 ...xonframework/samples/trader/app/api/portfolio/item/ItemReservationConfirmedForPortfolioEvent.java
  6. +5 −5 ...xonframework/samples/trader/app/api/portfolio/item/ItemToReserveNotAvailableInPortfolioEvent.java
  7. +7 −5 ...main/java/org/axonframework/samples/trader/app/api/portfolio/item/ItemsAddedToPortfolioEvent.java
  8. +5 −5 app/src/main/java/org/axonframework/samples/trader/app/api/portfolio/item/ItemsReservedEvent.java
  9. +5 −5 ...nframework/samples/trader/app/api/portfolio/item/NotEnoughItemsAvailableToReserveInPortfolio.java
  10. +5 −5 app/src/main/java/org/axonframework/samples/trader/app/api/portfolio/item/ReserveItemsCommand.java
  11. +24 −24 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Portfolio.java
  12. +4 −4 app/src/main/java/org/axonframework/samples/trader/app/command/trading/PortfolioCommandHandler.java
  13. +1 −1 app/src/main/java/org/axonframework/samples/trader/app/command/trading/SellTradeManagerSaga.java
  14. +9 −9 ...rc/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioItemEventListener.java
  15. +1 −1 ...g/axonframework/samples/trader/app/query/transaction/repositories/TransactionQueryRepository.java
  16. +24 −24 ...c/test/java/org/axonframework/samples/trader/app/command/trading/PortfolioCommandHandlerTest.java
  17. +21 −13 app/src/test/java/org/axonframework/samples/trader/app/command/trading/SellTradeManagerSagaTest.java
  18. +50 −0 ...samples/trader/app/command/trading/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java
  19. +2 −2 ...va/org/axonframework/samples/trader/app/command/trading/matchers/ReservedItemsCommandMatcher.java
  20. +5 −1 ...t/java/org/axonframework/samples/trader/app/command/trading/matchers/TradeManagerSagaMatcher.java
@@ -18,25 +18,34 @@
import org.axonframework.domain.AggregateIdentifier;
/**
+ * Try to add new items for a specific OrderBook to the portfolio.
+ *
* @author Jettro Coenradie
*/
public class AddItemsToPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
- private AggregateIdentifier itemIdentfier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfItemsToAdd;
- public AddItemsToPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier itemIdentfier, int amountOfItemsToAdd) {
+ /**
+ * Create a new command.
+ *
+ * @param portfolioIdentifier Identifier of the Portfolio to add items to
+ * @param orderBookIdentifier Identifier of the OrderBook to add items for
+ * @param amountOfItemsToAdd AMount of items to add
+ */
+ public AddItemsToPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfItemsToAdd) {
this.portfolioIdentifier = portfolioIdentifier;
- this.itemIdentfier = itemIdentfier;
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsToAdd = amountOfItemsToAdd;
}
public int getAmountOfItemsToAdd() {
return amountOfItemsToAdd;
}
- public AggregateIdentifier getItemIdentfier() {
- return itemIdentfier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -18,16 +18,19 @@
import org.axonframework.domain.AggregateIdentifier;
/**
+ * Cancel a reservation for an amount of items for the OrderBook belonging to the provided identifier in the Portfolio
+ * of the provided identifier.
+ *
* @author Jettro Coenradie
*/
public class CancelItemReservationForPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfCancelledItems;
- public CancelItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier itemIdentifier, int amountOfCancelledItems) {
+ public CancelItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfCancelledItems) {
this.portfolioIdentifier = portfolioIdentifier;
- this.itemIdentifier = itemIdentifier;
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfCancelledItems = amountOfCancelledItems;
}
@@ -36,8 +39,8 @@ public int getAmountOfItemsToCancel() {
return amountOfCancelledItems;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -18,25 +18,28 @@
import org.axonframework.domain.AggregateIdentifier;
/**
+ * Confirm the reserved items belonging to OrderBook of the provided identifier for the Portfolio of the provided
+ * identifier.
+ *
* @author Jettro Coenradie
*/
public class ConfirmItemReservationForPortfolioCommand {
private AggregateIdentifier portfolioIdentifier;
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfItemsToConfirm;
- public ConfirmItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier itemIdentifier, int amountOfItemsToConfirm) {
+ public ConfirmItemReservationForPortfolioCommand(AggregateIdentifier portfolioIdentifier, AggregateIdentifier orderBookIdentifier, int amountOfItemsToConfirm) {
this.portfolioIdentifier = portfolioIdentifier;
- this.itemIdentifier = itemIdentifier;
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsToConfirm = amountOfItemsToConfirm;
}
public int getAmountOfItemsToConfirm() {
return amountOfItemsToConfirm;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -22,20 +22,20 @@
* @author Jettro Coenradie
*/
public class ItemReservationCancelledForPortfolioEvent extends DomainEvent {
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfCancelledItems;
- public ItemReservationCancelledForPortfolioEvent(AggregateIdentifier itemIdentifier, int amountOfCancelledItems) {
- this.itemIdentifier = itemIdentifier;
+ public ItemReservationCancelledForPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfCancelledItems) {
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfCancelledItems = amountOfCancelledItems;
}
public int getAmountOfCancelledItems() {
return amountOfCancelledItems;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -22,20 +22,20 @@
* @author Jettro Coenradie
*/
public class ItemReservationConfirmedForPortfolioEvent extends DomainEvent {
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfConfirmedItems;
- public ItemReservationConfirmedForPortfolioEvent(AggregateIdentifier itemIdentifier, int amountOfConfirmedItems) {
- this.itemIdentifier = itemIdentifier;
+ public ItemReservationConfirmedForPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfConfirmedItems) {
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfConfirmedItems = amountOfConfirmedItems;
}
public int getAmountOfConfirmedItems() {
return amountOfConfirmedItems;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -22,14 +22,14 @@
* @author Jettro Coenradie
*/
public class ItemToReserveNotAvailableInPortfolioEvent extends DomainEvent {
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
- public ItemToReserveNotAvailableInPortfolioEvent(AggregateIdentifier itemIdentifier) {
- this.itemIdentifier = itemIdentifier;
+ public ItemToReserveNotAvailableInPortfolioEvent(AggregateIdentifier orderBookIdentifier) {
+ this.orderBookIdentifier = orderBookIdentifier;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -19,23 +19,25 @@
import org.axonframework.domain.DomainEvent;
/**
+ * New items have been added to the portfolio for the OrderBook of the provided identifier.
+ *
* @author Jettro Coenradie
*/
public class ItemsAddedToPortfolioEvent extends DomainEvent {
- private AggregateIdentifier itemIdentfier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfItemsAdded;
- public ItemsAddedToPortfolioEvent(AggregateIdentifier itemIdentfier, int amountOfItemsAdded) {
- this.itemIdentfier = itemIdentfier;
+ public ItemsAddedToPortfolioEvent(AggregateIdentifier orderBookIdentifier, int amountOfItemsAdded) {
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsAdded = amountOfItemsAdded;
}
public int getAmountOfItemsAdded() {
return amountOfItemsAdded;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentfier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -22,20 +22,20 @@
* @author Jettro Coenradie
*/
public class ItemsReservedEvent extends DomainEvent {
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int amountOfItemsReserved;
- public ItemsReservedEvent(AggregateIdentifier itemIdentifier, int amountOfItemsReserved) {
- this.itemIdentifier = itemIdentifier;
+ public ItemsReservedEvent(AggregateIdentifier orderBookIdentifier, int amountOfItemsReserved) {
+ this.orderBookIdentifier = orderBookIdentifier;
this.amountOfItemsReserved = amountOfItemsReserved;
}
public int getAmountOfItemsReserved() {
return amountOfItemsReserved;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -23,12 +23,12 @@
*/
public class NotEnoughItemsAvailableToReserveInPortfolio extends DomainEvent {
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
private int availableAmountOfItems;
private int amountOfItemsToReserve;
- public NotEnoughItemsAvailableToReserveInPortfolio(AggregateIdentifier itemIdentifier, int availableAmountOfItems, int amountOfItemsToReserve) {
- this.itemIdentifier = itemIdentifier;
+ public NotEnoughItemsAvailableToReserveInPortfolio(AggregateIdentifier orderBookIdentifier, int availableAmountOfItems, int amountOfItemsToReserve) {
+ this.orderBookIdentifier = orderBookIdentifier;
this.availableAmountOfItems = availableAmountOfItems;
this.amountOfItemsToReserve = amountOfItemsToReserve;
}
@@ -41,8 +41,8 @@ public int getAvailableAmountOfItems() {
return availableAmountOfItems;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
public AggregateIdentifier getPortfolioIdentifier() {
@@ -23,14 +23,14 @@
public class ReserveItemsCommand {
private AggregateIdentifier portfolioIdentifier;
private int amountOfItemsToReserve;
- private AggregateIdentifier itemIdentifier;
+ private AggregateIdentifier orderBookIdentifier;
public ReserveItemsCommand(AggregateIdentifier portfolioIdentifier,
- AggregateIdentifier itemIdentifier,
+ AggregateIdentifier orderBookIdentifier,
int amountOfItemsToReserve) {
this.portfolioIdentifier = portfolioIdentifier;
this.amountOfItemsToReserve = amountOfItemsToReserve;
- this.itemIdentifier = itemIdentifier;
+ this.orderBookIdentifier = orderBookIdentifier;
}
public int getAmountOfItemsToReserve() {
@@ -41,7 +41,7 @@ public AggregateIdentifier getPortfolioIdentifier() {
return portfolioIdentifier;
}
- public AggregateIdentifier getItemIdentifier() {
- return itemIdentifier;
+ public AggregateIdentifier getOrderBookIdentifier() {
+ return orderBookIdentifier;
}
}
@@ -50,30 +50,30 @@ public Portfolio(AggregateIdentifier aggregateIdentifier, AggregateIdentifier us
apply(new PortfolioCreatedEvent(userIdentifier));
}
- public void addItems(AggregateIdentifier itemIdentifier, int amountOfItemsToAdd) {
- apply(new ItemsAddedToPortfolioEvent(itemIdentifier, amountOfItemsToAdd));
+ public void addItems(AggregateIdentifier orderBookIdentifier, int amountOfItemsToAdd) {
+ apply(new ItemsAddedToPortfolioEvent(orderBookIdentifier, amountOfItemsToAdd));
}
- public void reserveItems(AggregateIdentifier itemIdentifier, int amountOfItemsToReserve) {
- if (!availableItems.containsKey(itemIdentifier)) {
- apply(new ItemToReserveNotAvailableInPortfolioEvent(itemIdentifier));
+ public void reserveItems(AggregateIdentifier orderBookIdentifier, int amountOfItemsToReserve) {
+ if (!availableItems.containsKey(orderBookIdentifier)) {
+ apply(new ItemToReserveNotAvailableInPortfolioEvent(orderBookIdentifier));
} else {
- Integer availableAmountOfItems = availableItems.get(itemIdentifier);
+ Integer availableAmountOfItems = availableItems.get(orderBookIdentifier);
if (availableAmountOfItems < amountOfItemsToReserve) {
apply(new NotEnoughItemsAvailableToReserveInPortfolio(
- itemIdentifier, availableAmountOfItems, amountOfItemsToReserve));
+ orderBookIdentifier, availableAmountOfItems, amountOfItemsToReserve));
} else {
- apply(new ItemsReservedEvent(itemIdentifier, amountOfItemsToReserve));
+ apply(new ItemsReservedEvent(orderBookIdentifier, amountOfItemsToReserve));
}
}
}
- public void confirmReservation(AggregateIdentifier itemIdentifier, int amountOfItemsToConfirm) {
- apply(new ItemReservationConfirmedForPortfolioEvent(itemIdentifier, amountOfItemsToConfirm));
+ public void confirmReservation(AggregateIdentifier orderBookIdentifier, int amountOfItemsToConfirm) {
+ apply(new ItemReservationConfirmedForPortfolioEvent(orderBookIdentifier, amountOfItemsToConfirm));
}
- public void cancelReservation(AggregateIdentifier itemIdentifier, int amountOfItemsToCancel) {
- apply(new ItemReservationCancelledForPortfolioEvent(itemIdentifier, amountOfItemsToCancel));
+ public void cancelReservation(AggregateIdentifier orderBookIdentifier, int amountOfItemsToCancel) {
+ apply(new ItemReservationCancelledForPortfolioEvent(orderBookIdentifier, amountOfItemsToCancel));
}
public void addMoney(long moneyToAddInCents) {
@@ -118,32 +118,32 @@ public void onNotEnoughItemsAvailableToReserve(NotEnoughItemsAvailableToReserveI
@EventHandler
public void onItemsAddedToPortfolio(ItemsAddedToPortfolioEvent event) {
- int available = obtainCurrentAvailableItems(event.getItemIdentifier());
- availableItems.put(event.getItemIdentifier(), available + event.getAmountOfItemsAdded());
+ int available = obtainCurrentAvailableItems(event.getOrderBookIdentifier());
+ availableItems.put(event.getOrderBookIdentifier(), available + event.getAmountOfItemsAdded());
}
@EventHandler
public void onItemsReserved(ItemsReservedEvent event) {
- int available = obtainCurrentAvailableItems(event.getItemIdentifier());
- availableItems.put(event.getItemIdentifier(), available - event.getAmountOfItemsReserved());
+ int available = obtainCurrentAvailableItems(event.getOrderBookIdentifier());
+ availableItems.put(event.getOrderBookIdentifier(), available - event.getAmountOfItemsReserved());
- int reserved = obtainCurrentReservedItems(event.getItemIdentifier());
- reservedItems.put(event.getItemIdentifier(), reserved + event.getAmountOfItemsReserved());
+ int reserved = obtainCurrentReservedItems(event.getOrderBookIdentifier());
+ reservedItems.put(event.getOrderBookIdentifier(), reserved + event.getAmountOfItemsReserved());
}
@EventHandler
public void onReservationConfirmed(ItemReservationConfirmedForPortfolioEvent event) {
- int reserved = obtainCurrentReservedItems(event.getItemIdentifier());
- reservedItems.put(event.getItemIdentifier(), reserved - event.getAmountOfConfirmedItems());
+ int reserved = obtainCurrentReservedItems(event.getOrderBookIdentifier());
+ reservedItems.put(event.getOrderBookIdentifier(), reserved - event.getAmountOfConfirmedItems());
}
@EventHandler
public void onReservationCancelled(ItemReservationCancelledForPortfolioEvent event) {
- int reserved = obtainCurrentReservedItems(event.getItemIdentifier());
- reservedItems.put(event.getItemIdentifier(), reserved + event.getAmountOfCancelledItems());
+ int reserved = obtainCurrentReservedItems(event.getOrderBookIdentifier());
+ reservedItems.put(event.getOrderBookIdentifier(), reserved + event.getAmountOfCancelledItems());
- int available = obtainCurrentAvailableItems(event.getItemIdentifier());
- availableItems.put(event.getItemIdentifier(), available + event.getAmountOfCancelledItems());
+ int available = obtainCurrentAvailableItems(event.getOrderBookIdentifier());
+ availableItems.put(event.getOrderBookIdentifier(), available + event.getAmountOfCancelledItems());
}
@EventHandler
Oops, something went wrong.

0 comments on commit 15ad3e6

Please sign in to comment.