Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add the transaction stuff to the code base

  • Loading branch information...
commit 47eef8c2e97499d2db15807d27f2f477aadedd71 1 parent c74ac79
@jettro jettro authored
Showing with 1,100 additions and 0 deletions.
  1. +51 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/AbstractStartTransactionCommand.java
  2. +56 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/AbstractTransactionStartedEvent.java
  3. +44 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionCancelledEvent.java
  4. +28 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionConfirmedEvent.java
  5. +44 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionExecutedEvent.java
  6. +63 −0 ...rc/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionPartiallyExecutedEvent.java
  7. +31 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionStartedEvent.java
  8. +33 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/CancelTransactionCommand.java
  9. +33 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/ConfirmTransactionCommand.java
  10. +45 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/ExecutedTransactionCommand.java
  11. +44 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionCancelledEvent.java
  12. +29 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionConfirmedEvent.java
  13. +52 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionExecutedEvent.java
  14. +63 −0 ...c/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionPartiallyExecutedEvent.java
  15. +27 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionStartedEvent.java
  16. +27 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/StartBuyTransactionCommand.java
  17. +27 −0 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/StartSellTransactionCommand.java
  18. +147 −0 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Transaction.java
  19. +77 −0 app/src/main/java/org/axonframework/samples/trader/app/command/trading/TransactionCommandHandler.java
  20. +23 −0 app/src/main/java/org/axonframework/samples/trader/app/command/trading/TransactionType.java
  21. +17 −0 app/src/main/resources/META-INF/spring/command-context.xml
  22. +139 −0 app/src/test/java/org/axonframework/samples/trader/app/command/trading/TransactionCommandHandlingTest.java
View
51 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/AbstractStartTransactionCommand.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class AbstractStartTransactionCommand {
+ private AggregateIdentifier orderbookIdentifier;
+ private AggregateIdentifier portfolioIdentifier;
+ private long tradeCount;
+ private long itemPrice;
+
+ public AbstractStartTransactionCommand(AggregateIdentifier orderbookIdentifier, AggregateIdentifier portfolioIdentifier, long tradeCount, long itemPrice) {
+ this.itemPrice = itemPrice;
+ this.orderbookIdentifier = orderbookIdentifier;
+ this.portfolioIdentifier = portfolioIdentifier;
+ this.tradeCount = tradeCount;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+
+ public AggregateIdentifier getOrderbookIdentifier() {
+ return orderbookIdentifier;
+ }
+
+ public AggregateIdentifier getPortfolioIdentifier() {
+ return portfolioIdentifier;
+ }
+
+ public long getTradeCount() {
+ return tradeCount;
+ }
+}
View
56 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/AbstractTransactionStartedEvent.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public abstract class AbstractTransactionStartedEvent extends DomainEvent {
+ private AggregateIdentifier orderbookIdentifier;
+ private AggregateIdentifier portfolioIdentifier;
+ private long totalItems;
+ private long pricePerItem;
+
+ public AbstractTransactionStartedEvent(AggregateIdentifier orderbookIdentifier,
+ AggregateIdentifier portfolioIdentifier,
+ long totalItems,
+ long pricePerItem) {
+ this.orderbookIdentifier = orderbookIdentifier;
+ this.portfolioIdentifier = portfolioIdentifier;
+ this.totalItems = totalItems;
+ this.pricePerItem = pricePerItem;
+ }
+
+ public AggregateIdentifier getOrderbookIdentifier() {
+ return orderbookIdentifier;
+ }
+
+ public AggregateIdentifier getPortfolioIdentifier() {
+ return portfolioIdentifier;
+ }
+
+ public long getPricePerItem() {
+ return pricePerItem;
+ }
+
+ public long getTotalItems() {
+ return totalItems;
+ }
+
+}
View
44 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionCancelledEvent.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class BuyTransactionCancelledEvent extends DomainEvent {
+ private long totalAmountOfItems;
+ private long amountOfExecutedItems;
+
+ public BuyTransactionCancelledEvent(long totalAmountOfItems, long amountOfExecutedItems) {
+ this.totalAmountOfItems = totalAmountOfItems;
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return super.getAggregateIdentifier();
+ }
+
+ public long getAmountOfExecutedItems() {
+ return amountOfExecutedItems;
+ }
+
+ public long getTotalAmountOfItems() {
+ return totalAmountOfItems;
+ }
+}
View
28 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionConfirmedEvent.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class BuyTransactionConfirmedEvent extends DomainEvent {
+ public AggregateIdentifier getTransactionIdentifier() {
+ return super.getAggregateIdentifier();
+ }
+}
View
44 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionExecutedEvent.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class BuyTransactionExecutedEvent extends DomainEvent {
+ private long amountOfItems;
+ private long itemPrice;
+
+ public BuyTransactionExecutedEvent(long amountOfItems, long itemPrice) {
+ this.amountOfItems = amountOfItems;
+ this.itemPrice = itemPrice;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return this.getAggregateIdentifier();
+ }
+
+ public long getAmountOfItems() {
+ return amountOfItems;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+}
View
63 ...main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionPartiallyExecutedEvent.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class BuyTransactionPartiallyExecutedEvent extends DomainEvent {
+ private long amountOfExecutedItems;
+ private long totalOfExecutedItems;
+ private long itemPrice;
+
+ public BuyTransactionPartiallyExecutedEvent(long amountOfExecutedItems, long totalOfExecutedItems, long itemPrice) {
+
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ this.totalOfExecutedItems = totalOfExecutedItems;
+ this.itemPrice = itemPrice;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return this.getAggregateIdentifier();
+ }
+
+ public long getAmountOfExecutedItems() {
+ return amountOfExecutedItems;
+ }
+
+ public void setAmountOfExecutedItems(long amountOfExecutedItems) {
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+
+ public void setItemPrice(long itemPrice) {
+ this.itemPrice = itemPrice;
+ }
+
+ public long getTotalOfExecutedItems() {
+ return totalOfExecutedItems;
+ }
+
+ public void setTotalOfExecutedItems(long totalOfExecutedItems) {
+ this.totalOfExecutedItems = totalOfExecutedItems;
+ }
+}
View
31 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/BuyTransactionStartedEvent.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class BuyTransactionStartedEvent extends AbstractTransactionStartedEvent {
+
+ public BuyTransactionStartedEvent(AggregateIdentifier orderbookIdentifier,
+ AggregateIdentifier portfolioIdentifier,
+ long totalItems,
+ long pricePerItem) {
+ super(orderbookIdentifier, portfolioIdentifier, totalItems, pricePerItem);
+ }
+}
View
33 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/CancelTransactionCommand.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class CancelTransactionCommand {
+ private AggregateIdentifier transactionIdentifier;
+
+ public CancelTransactionCommand(AggregateIdentifier transactionIdentifier) {
+ this.transactionIdentifier = transactionIdentifier;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return transactionIdentifier;
+ }
+}
View
33 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/ConfirmTransactionCommand.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class ConfirmTransactionCommand {
+ private AggregateIdentifier transactionIdentifier;
+
+ public ConfirmTransactionCommand(AggregateIdentifier transactionIdentifier) {
+ this.transactionIdentifier = transactionIdentifier;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return transactionIdentifier;
+ }
+}
View
45 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/ExecutedTransactionCommand.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class ExecutedTransactionCommand {
+ private AggregateIdentifier transactionIdentifier;
+ private long amountOfItems;
+ private long itemPrice;
+
+ public ExecutedTransactionCommand(AggregateIdentifier transactionIdentifier, long amountOfItems, long itemPrice) {
+ this.transactionIdentifier = transactionIdentifier;
+ this.amountOfItems = amountOfItems;
+ this.itemPrice = itemPrice;
+ }
+
+ public long getAmountOfItems() {
+ return amountOfItems;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return transactionIdentifier;
+ }
+}
View
44 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionCancelledEvent.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class SellTransactionCancelledEvent extends DomainEvent {
+ private long amountOfItems;
+ private long amountOfExecutedItems;
+
+ public SellTransactionCancelledEvent(long amountOfItems, long amountOfExecutedItems) {
+ this.amountOfItems = amountOfItems;
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return this.getAggregateIdentifier();
+ }
+
+ public long getAmountOfExecutedItems() {
+ return amountOfExecutedItems;
+ }
+
+ public long getAmountOfItems() {
+ return amountOfItems;
+ }
+}
View
29 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionConfirmedEvent.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class SellTransactionConfirmedEvent extends DomainEvent {
+ public AggregateIdentifier getTransactionIdentifier() {
+ return super.getAggregateIdentifier();
+ }
+
+}
View
52 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionExecutedEvent.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class SellTransactionExecutedEvent extends DomainEvent {
+ private long amountOfItems;
+ private long itemPrice;
+
+ public SellTransactionExecutedEvent(long amountOfItems, long itemPrice) {
+ this.amountOfItems = amountOfItems;
+ this.itemPrice = itemPrice;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return this.getAggregateIdentifier();
+ }
+
+ public long getAmountOfItems() {
+ return amountOfItems;
+ }
+
+ public void setAmountOfItems(long amountOfItems) {
+ this.amountOfItems = amountOfItems;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+
+ public void setItemPrice(long itemPrice) {
+ this.itemPrice = itemPrice;
+ }
+}
View
63 ...ain/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionPartiallyExecutedEvent.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.DomainEvent;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class SellTransactionPartiallyExecutedEvent extends DomainEvent {
+ private long amountOfExecutedItems;
+ private long totalOfExecutedItems;
+ private long itemPrice;
+
+ public SellTransactionPartiallyExecutedEvent(long amountOfExecutedItems, long totalOfExecutedItems, long itemPrice) {
+
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ this.totalOfExecutedItems = totalOfExecutedItems;
+ this.itemPrice = itemPrice;
+ }
+
+ public AggregateIdentifier getTransactionIdentifier() {
+ return this.getAggregateIdentifier();
+ }
+
+ public long getAmountOfExecutedItems() {
+ return amountOfExecutedItems;
+ }
+
+ public void setAmountOfExecutedItems(long amountOfExecutedItems) {
+ this.amountOfExecutedItems = amountOfExecutedItems;
+ }
+
+ public long getItemPrice() {
+ return itemPrice;
+ }
+
+ public void setItemPrice(long itemPrice) {
+ this.itemPrice = itemPrice;
+ }
+
+ public long getTotalOfExecutedItems() {
+ return totalOfExecutedItems;
+ }
+
+ public void setTotalOfExecutedItems(long totalOfExecutedItems) {
+ this.totalOfExecutedItems = totalOfExecutedItems;
+ }
+}
View
27 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/SellTransactionStartedEvent.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class SellTransactionStartedEvent extends AbstractTransactionStartedEvent {
+ public SellTransactionStartedEvent(AggregateIdentifier orderbookIdentifier, AggregateIdentifier portfolioIdentifier, long totalItems, long pricePerItem) {
+ super(orderbookIdentifier, portfolioIdentifier, totalItems, pricePerItem);
+ }
+}
View
27 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/StartBuyTransactionCommand.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class StartBuyTransactionCommand extends AbstractStartTransactionCommand {
+ public StartBuyTransactionCommand(AggregateIdentifier orderbookIdentifier, AggregateIdentifier portfolioIdentifier, long tradeCount, long itemPrice) {
+ super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
+ }
+}
View
27 app/src/main/java/org/axonframework/samples/trader/app/api/transaction/StartSellTransactionCommand.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.api.transaction;
+
+import org.axonframework.domain.AggregateIdentifier;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class StartSellTransactionCommand extends AbstractStartTransactionCommand {
+ public StartSellTransactionCommand(AggregateIdentifier orderbookIdentifier, AggregateIdentifier portfolioIdentifier, long tradeCount, long itemPrice) {
+ super(orderbookIdentifier, portfolioIdentifier, tradeCount, itemPrice);
+ }
+}
View
147 app/src/main/java/org/axonframework/samples/trader/app/command/trading/Transaction.java
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.command.trading;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.eventhandling.annotation.EventHandler;
+import org.axonframework.eventsourcing.annotation.AbstractAnnotatedAggregateRoot;
+import org.axonframework.samples.trader.app.api.transaction.*;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class Transaction extends AbstractAnnotatedAggregateRoot {
+ private long amountOfItems;
+ private long amountOfExecutedItems;
+ private TransactionType type;
+
+ protected Transaction(AggregateIdentifier identifier) {
+ super(identifier);
+ }
+
+ public Transaction(TransactionType type,
+ AggregateIdentifier orderbookIdentifier,
+ AggregateIdentifier portfolioIdentifier,
+ long amountOfItems,
+ long pricePerItem) {
+ switch (type) {
+ case BUY:
+ apply(new BuyTransactionStartedEvent(orderbookIdentifier, portfolioIdentifier, amountOfItems, pricePerItem));
+ break;
+ case SELL:
+ apply(new SellTransactionStartedEvent(orderbookIdentifier, portfolioIdentifier, amountOfItems, pricePerItem));
+ break;
+
+ }
+ }
+
+ public void confirm() {
+ switch (this.type) {
+ case BUY:
+ apply(new BuyTransactionConfirmedEvent());
+ break;
+ case SELL:
+ apply(new SellTransactionConfirmedEvent());
+ break;
+ }
+ }
+
+ public void cancel() {
+ switch (this.type) {
+ case BUY:
+ apply(new BuyTransactionCancelledEvent(amountOfItems, amountOfExecutedItems));
+ break;
+ case SELL:
+ apply(new SellTransactionCancelledEvent(amountOfItems, amountOfExecutedItems));
+ break;
+ }
+ }
+
+ public void execute(long amountOfItems, long itemPrice) {
+ switch (this.type) {
+ case BUY:
+ if (isPartiallyExecuted(amountOfItems)) {
+ apply(new BuyTransactionPartiallyExecutedEvent(amountOfItems, amountOfItems + amountOfExecutedItems, itemPrice));
+ } else {
+ apply(new BuyTransactionExecutedEvent(amountOfItems, itemPrice));
+ }
+ break;
+ case SELL:
+ if (isPartiallyExecuted(amountOfItems)) {
+ apply(new SellTransactionPartiallyExecutedEvent(amountOfItems, amountOfItems + amountOfExecutedItems, itemPrice));
+ } else {
+ apply(new SellTransactionExecutedEvent(amountOfItems, itemPrice));
+ }
+ break;
+ }
+ }
+
+ private boolean isPartiallyExecuted(long amountOfItems) {
+ return this.amountOfExecutedItems + amountOfItems < this.amountOfItems;
+ }
+
+ @EventHandler
+ public void onBuyTransactionStarted(BuyTransactionStartedEvent event) {
+ this.amountOfItems = event.getTotalItems();
+ this.type = TransactionType.BUY;
+ }
+
+ @EventHandler
+ public void onSellTransactionStarted(SellTransactionStartedEvent event) {
+ this.amountOfItems = event.getTotalItems();
+ this.type = TransactionType.SELL;
+ }
+
+ @EventHandler
+ public void onTransactionConfirmed(BuyTransactionConfirmedEvent event) {
+ // do nothing for now
+ }
+
+ @EventHandler
+ public void onTransactionConfirmed(SellTransactionConfirmedEvent event) {
+ // do nothing for now
+ }
+
+ @EventHandler
+ public void onTransactionCancelled(BuyTransactionCancelledEvent event) {
+ // do nothing for now
+ }
+
+ @EventHandler
+ public void onTransactionCancelled(SellTransactionCancelledEvent event) {
+ // do nothing for now
+ }
+
+ @EventHandler
+ public void onTransactionExecuted(BuyTransactionExecutedEvent event) {
+ this.amountOfExecutedItems = event.getAmountOfItems();
+ }
+
+ @EventHandler
+ public void onTransactionExecuted(SellTransactionExecutedEvent event) {
+ this.amountOfExecutedItems = event.getAmountOfItems();
+ }
+
+ @EventHandler
+ public void onTransactionPartiallyExecuted(SellTransactionPartiallyExecutedEvent event) {
+ this.amountOfExecutedItems += event.getAmountOfExecutedItems();
+ }
+
+ @EventHandler
+ public void onTransactionPartiallyExecuted(BuyTransactionPartiallyExecutedEvent event) {
+ this.amountOfExecutedItems += event.getAmountOfExecutedItems();
+ }
+}
View
77 app/src/main/java/org/axonframework/samples/trader/app/command/trading/TransactionCommandHandler.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.command.trading;
+
+import org.axonframework.commandhandling.annotation.CommandHandler;
+import org.axonframework.repository.Repository;
+import org.axonframework.samples.trader.app.api.transaction.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Jettro Coenradie
+ */
+@Component
+public class TransactionCommandHandler {
+ private Repository<Transaction> repository;
+
+ @CommandHandler
+ public void handleStartBuyTransactionCommand(StartBuyTransactionCommand command) {
+ Transaction transaction = new Transaction(
+ TransactionType.BUY,
+ command.getOrderbookIdentifier(),
+ command.getPortfolioIdentifier(),
+ command.getTradeCount(),
+ command.getItemPrice());
+ repository.add(transaction);
+ }
+
+ @CommandHandler
+ public void handleStartSellTransactionCommand(StartSellTransactionCommand command) {
+ Transaction transaction = new Transaction(
+ TransactionType.SELL,
+ command.getOrderbookIdentifier(),
+ command.getPortfolioIdentifier(),
+ command.getTradeCount(),
+ command.getItemPrice());
+ repository.add(transaction);
+ }
+
+ @CommandHandler
+ public void handleConfirmTransactionCommand(ConfirmTransactionCommand command) {
+ Transaction transaction = repository.load(command.getTransactionIdentifier());
+ transaction.confirm();
+ }
+
+ @CommandHandler
+ public void handleCancelTransactionCommand(CancelTransactionCommand command) {
+ Transaction transaction = repository.load(command.getTransactionIdentifier());
+ transaction.cancel();
+ }
+
+ @CommandHandler
+ public void handleExecutedTransactionCommand(ExecutedTransactionCommand command) {
+ Transaction transaction = repository.load(command.getTransactionIdentifier());
+ transaction.execute(command.getAmountOfItems(), command.getItemPrice());
+ }
+
+ @Autowired
+ @Qualifier("transactionRepository")
+ public void setRepository(Repository<Transaction> repository) {
+ this.repository = repository;
+ }
+}
View
23 app/src/main/java/org/axonframework/samples/trader/app/command/trading/TransactionType.java
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.command.trading;
+
+/**
+ * @author Jettro Coenradie
+ */
+public enum TransactionType {
+ SELL, BUY
+}
View
17 app/src/main/resources/META-INF/spring/command-context.xml
@@ -53,6 +53,23 @@
<axon:snapshotter-trigger event-count-threshold="50" snapshotter-ref="snapshotter"/>
</axon:event-sourcing-repository>
+ <axon:event-sourcing-repository id="portfolioRepository"
+ aggregate-type="org.axonframework.samples.trader.app.command.trading.Portfolio"
+ cache-ref="ehcache"
+ event-bus="eventBus"
+ event-store="eventStore">
+ <axon:snapshotter-trigger event-count-threshold="50" snapshotter-ref="snapshotter"/>
+ </axon:event-sourcing-repository>
+
+ <axon:event-sourcing-repository id="transactionRepository"
+ aggregate-type="org.axonframework.samples.trader.app.command.trading.Transaction"
+ cache-ref="ehcache"
+ event-bus="eventBus"
+ event-store="eventStore">
+ <axon:snapshotter-trigger event-count-threshold="50" snapshotter-ref="snapshotter"/>
+ </axon:event-sourcing-repository>
+
+
<bean id="snapshotter" class="org.axonframework.eventsourcing.SpringAggregateSnapshotter">
<property name="eventStore" ref="eventStore"/>
<property name="executor" ref="taskExecutor"/>
View
139 app/src/test/java/org/axonframework/samples/trader/app/command/trading/TransactionCommandHandlingTest.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.command.trading;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.UUIDAggregateIdentifier;
+import org.axonframework.samples.trader.app.api.transaction.*;
+import org.axonframework.test.FixtureConfiguration;
+import org.axonframework.test.Fixtures;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class TransactionCommandHandlingTest {
+ private FixtureConfiguration fixture;
+
+ @Before
+ public void setUp() {
+ fixture = Fixtures.newGivenWhenThenFixture();
+ TransactionCommandHandler commandHandler = new TransactionCommandHandler();
+ commandHandler.setRepository(fixture.createGenericRepository(Transaction.class));
+ fixture.registerAnnotatedCommandHandler(commandHandler);
+ }
+
+ @Test
+ public void testStartBuyTransaction() {
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+ StartBuyTransactionCommand command = new StartBuyTransactionCommand(orderBook, portfolio, 200, 20);
+ fixture.given()
+ .when(command)
+ .expectEvents(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20));
+ }
+
+ @Test
+ public void testStartSellTransaction() {
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+ StartSellTransactionCommand command = new StartSellTransactionCommand(orderBook, portfolio, 200, 20);
+ fixture.given()
+ .when(command)
+ .expectEvents(new SellTransactionStartedEvent(orderBook, portfolio, 200, 20));
+ }
+
+ @Test
+ public void testConfirmTransaction() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ ConfirmTransactionCommand command = new ConfirmTransactionCommand(transactionIdentifier);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20))
+ .when(command)
+ .expectEvents(new BuyTransactionConfirmedEvent());
+ }
+
+ @Test
+ public void testCancelTransaction() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ CancelTransactionCommand command = new CancelTransactionCommand(transactionIdentifier);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20))
+ .when(command)
+ .expectEvents(new BuyTransactionCancelledEvent(200, 0));
+ }
+
+ @Test
+ public void testCancelTransaction_partiallyExecuted() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ CancelTransactionCommand command = new CancelTransactionCommand(transactionIdentifier);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20),
+ new BuyTransactionPartiallyExecutedEvent(100, 100, 20))
+ .when(command)
+ .expectEvents(new BuyTransactionCancelledEvent(200, 100));
+ }
+
+ @Test
+ public void testExecuteTransaction() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionIdentifier, 200, 20);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20),
+ new BuyTransactionConfirmedEvent())
+ .when(command)
+ .expectEvents(new BuyTransactionExecutedEvent(200, 20));
+ }
+
+ @Test
+ public void testExecuteTransaction_partiallyExecuted() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionIdentifier, 50, 20);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20),
+ new BuyTransactionConfirmedEvent())
+ .when(command)
+ .expectEvents(new BuyTransactionPartiallyExecutedEvent(50, 50, 20));
+ }
+
+ @Test
+ public void testExecuteTransaction_completeAfterPartiallyExecuted() {
+ AggregateIdentifier transactionIdentifier = fixture.getAggregateIdentifier();
+ AggregateIdentifier orderBook = new UUIDAggregateIdentifier();
+ AggregateIdentifier portfolio = new UUIDAggregateIdentifier();
+
+ ExecutedTransactionCommand command = new ExecutedTransactionCommand(transactionIdentifier, 150, 20);
+ fixture.given(new BuyTransactionStartedEvent(orderBook, portfolio, 200, 20),
+ new BuyTransactionConfirmedEvent(),
+ new BuyTransactionPartiallyExecutedEvent(50, 50, 20)
+ )
+ .when(command)
+ .expectEvents(new BuyTransactionExecutedEvent(150, 20));
+ // TODO moeten we nu ook nog een partially executed event gooien?
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.