├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── README.md ├── companies ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── company │ │ └── command │ │ ├── Company.java │ │ └── CompanyOrderBookListener.java │ └── test │ ├── java │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── company │ │ └── command │ │ └── CompanyTest.java │ └── resources │ └── log4j.properties ├── core-api ├── pom.xml └── src │ └── main │ └── java │ └── org │ └── axonframework │ └── samples │ └── trader │ └── api │ ├── company │ ├── commands.kt │ ├── events.kt │ └── valueObjects.kt │ ├── orders │ ├── trades │ │ ├── commands.kt │ │ └── events.kt │ ├── transaction │ │ ├── commands.kt │ │ ├── events.kt │ │ └── valueObjects.kt │ └── valueObjects.kt │ ├── portfolio │ ├── cash │ │ ├── commands.kt │ │ └── events.kt │ ├── commands.kt │ ├── events.kt │ ├── stock │ │ ├── commands.kt │ │ └── events.kt │ └── valueObjects.kt │ └── users │ ├── UserAccount.java │ ├── commands.kt │ ├── events.kt │ └── valueObjects.kt ├── external-listeners ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── listener │ │ ├── BroadcastingTextWebSocketHandler.java │ │ ├── ExecutedTradesBroadcaster.java │ │ ├── WebSocketConfig.java │ │ └── config │ │ └── ExternalListenersConfig.java │ └── resources │ ├── META-INF │ └── spring │ │ └── external-context.xml │ └── external-config.properties ├── infrastructure ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── infra │ │ └── config │ │ ├── CQRSInfrastructureConfig.java │ │ ├── CQRSInfrastructureHSQLDBConfig.java │ │ └── PersistenceInfrastructureConfig.java │ └── resources │ ├── META-INF │ └── spring │ │ └── configuration-context.xml │ ├── ehcache.xml │ └── trader.properties ├── mvnw ├── mvnw.cmd ├── orders ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── orders │ │ ├── command │ │ ├── BuyTradeManagerSaga.java │ │ ├── Portfolio.java │ │ ├── PortfolioManagementUserListener.java │ │ ├── SellTradeManagerSaga.java │ │ ├── TradeManagerSaga.java │ │ └── Transaction.java │ │ └── config │ │ └── OrderConfig.java │ └── test │ ├── java │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── orders │ │ └── command │ │ ├── BuyTradeManagerSagaTest.java │ │ ├── PortfolioManagementUserListenerTest.java │ │ ├── PortfolioTest.java │ │ ├── SellTradeManagerSagaTest.java │ │ ├── TransactionCommandHandlingTest.java │ │ └── matchers │ │ ├── AddItemsToPortfolioCommandMatcher.java │ │ ├── BaseCommandMatcher.java │ │ ├── CancelItemReservationForPortfolioCommandMatcher.java │ │ ├── CancelMoneyReservationFromPortfolioCommandMatcher.java │ │ ├── CancelTransactionCommandMatcher.java │ │ ├── ConfirmItemReservationForPortfolioCommandMatcher.java │ │ ├── ConfirmMoneyReservationFromPortfolionCommandMatcher.java │ │ ├── ConfirmTransactionCommandMatcher.java │ │ ├── CreateBuyOrderCommandMatcher.java │ │ ├── CreateSellOrderCommandMatcher.java │ │ ├── DepositMoneyToPortfolioCommandMatcher.java │ │ ├── ExecutedTransactionCommandMatcher.java │ │ ├── ReserveMoneyFromPortfolioCommandMatcher.java │ │ └── ReservedItemsCommandMatcher.java │ └── resources │ └── log4j.properties ├── pom.xml ├── query ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── axonframework │ │ │ └── samples │ │ │ └── trader │ │ │ └── query │ │ │ ├── company │ │ │ ├── CompanyEventHandler.java │ │ │ ├── CompanyView.java │ │ │ └── CompanyViewRepository.java │ │ │ ├── config │ │ │ └── HsqlDbConfiguration.java │ │ │ ├── orderbook │ │ │ ├── OrderBookEventHandler.java │ │ │ ├── OrderBookView.java │ │ │ ├── OrderBookViewRepository.java │ │ │ └── OrderView.java │ │ │ ├── portfolio │ │ │ ├── ItemEntry.java │ │ │ ├── PortfolioItemEventHandler.java │ │ │ ├── PortfolioMoneyEventHandler.java │ │ │ ├── PortfolioView.java │ │ │ └── PortfolioViewRepository.java │ │ │ ├── tradeexecuted │ │ │ ├── TradeExecutedQueryRepository.java │ │ │ └── TradeExecutedView.java │ │ │ └── transaction │ │ │ ├── TransactionEventHandler.java │ │ │ ├── TransactionState.java │ │ │ ├── TransactionView.java │ │ │ └── TransactionViewRepository.java │ └── resources │ │ └── META-INF │ │ └── persistence.xml │ └── test │ └── java │ └── org │ └── axonframework │ └── samples │ └── trader │ └── query │ ├── company │ └── CompanyEventHandlerTest.java │ ├── portfolio │ ├── PortfolioEntryMatcher.java │ ├── PortfolioItemEventHandlerTest.java │ └── PortfolioViewTest.java │ └── transaction │ ├── TransactionEntryMatcher.java │ └── TransactionEventHandlerTest.java ├── trade-engine ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── tradeengine │ │ └── command │ │ ├── Order.java │ │ └── OrderBook.java │ └── test │ └── java │ └── org │ └── axonframework │ └── samples │ └── trader │ └── tradeengine │ └── command │ └── OrderBookTest.java ├── users-query ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── query │ │ └── users │ │ ├── UserEventHandler.java │ │ ├── UserView.java │ │ └── UserViewRepository.java │ └── test │ └── java │ └── org │ └── axonframework │ └── samples │ └── trader │ └── query │ └── users │ └── UserEventHandlerTest.java ├── users ├── pom.xml └── src │ ├── main │ └── java │ │ └── org │ │ └── axonframework │ │ └── samples │ │ └── trader │ │ └── users │ │ ├── command │ │ └── User.java │ │ └── util │ │ └── DigestUtils.java │ └── test │ └── java │ └── org │ └── axonframework │ └── samples │ └── trader │ └── app │ └── command │ └── user │ └── UserTest.java └── web-ui ├── pom.xml └── src └── main ├── java └── org │ └── axonframework │ └── samples │ └── trader │ └── webui │ ├── admin │ └── AdminController.java │ ├── companies │ └── CompanyController.java │ ├── config │ └── AppConfig.java │ ├── dashboard │ └── DashboardController.java │ ├── init │ ├── BaseDBInit.java │ ├── DBInit.java │ ├── DBInitException.java │ ├── DataController.java │ ├── DataResults.java │ ├── HsqlDBInit.java │ └── RunDBInitializerWhenNeeded.java │ ├── order │ ├── AbstractOrder.java │ ├── BuyOrder.java │ ├── CreateOrder.java │ ├── OrderBookController.java │ └── SellOrder.java │ ├── rest │ └── RestController.java │ ├── security │ ├── TraderAuthenticationProvider.java │ └── UserController.java │ └── util │ └── SecurityUtil.java ├── resources ├── META-INF │ └── spring │ │ └── security-context.xml ├── log4j.properties └── messages.properties └── webapp ├── WEB-INF ├── decorators.xml ├── decorators │ └── master.jsp ├── dispatcher-servlet.xml ├── jsp │ ├── admin │ │ └── portfolio │ │ │ ├── detail.jsp │ │ │ └── list.jsp │ ├── company │ │ ├── buy.jsp │ │ ├── details.jsp │ │ ├── form-include.jsp │ │ ├── list.jsp │ │ └── sell.jsp │ ├── dashboard │ │ └── index.jsp │ ├── data │ │ ├── collection.jsp │ │ ├── collections.jsp │ │ └── info.jsp │ ├── include.jsp │ ├── index.jsp │ ├── orderbook │ │ ├── list.jsp │ │ ├── orders.jsp │ │ └── socket.jsp │ └── user │ │ ├── detail.jsp │ │ └── list.jsp ├── messages │ ├── fields.properties │ └── validation.properties └── web.xml ├── favicon.ico ├── index.html ├── js ├── jquery-1.6.4.min.js ├── jquery.tablesorter.min.js └── sockjs-0.2.1.min.js ├── login.jsp └── style ├── bootstrap-1.3.0.min.css ├── bootstrap-1.4.0.min.css └── main.css /.gitignore: -------------------------------------------------------------------------------- 1 | # used to ignore certain files by git 2 | # mac osx files 3 | .DS_Store 4 | #gradle build files 5 | .gradle 6 | build 7 | # intellij files 8 | .idea/ 9 | **/.idea/* 10 | **/gradle.properties 11 | *.ipr 12 | *.iws 13 | *.iml 14 | target/ 15 | out/* 16 | rebel.xml -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxonFramework/Axon-trader/149c80498aef30baa45000fa241362e2fc0e2001/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Archived project 2 | 3 | This project has been discontinued and is not being updated to latest standards anymore. There are several sample applications around that show the usage of Axon Framework that are kept up-to-date continuously. 4 | 5 | A few examples (at the time of writing): 6 | - https://github.com/AxonIQ/hotel-demo 7 | - https://github.com/fraktalio/restaurant-demo 8 | - https://github.com/abuijze/bike-rental-demo 9 | - https://github.com/abuijze/bike-rental-extended 10 | 11 | --- 12 | 13 | This is a sample application to demonstrate the possibilities of the Axon framework in a high load environment. We have chosen to create a Trader application. All you need to run it is java and maven. 14 | 15 | 16 | Initial setup 17 | ------------- 18 | - Make sure you have java installed 19 | http://www.java.com/download/ 20 | 21 | Running the sample 22 | ------------------ 23 | - First you need to download the source code, if you are reading this file on your local machine you already have downloaded the source code. If you are on the main page of the Github project, you can easily find a url to clone the repository or to download a zip with all the sources. 24 | 25 | * Maven 26 | - Step into the main folder of the project 27 | > ./mvnw tomcat7:run 28 | - Browse to http://localhost:8080 and you should see the user accounts that you can use to login. 29 | (You can always refresh the data by calling /data/init on the application) 30 | 31 | More documentation 32 | ---------------------- 33 | We are documenting the sample on the wiki of the github project. 34 | https://github.com/AxonFramework/Axon-trader/wiki 35 | -------------------------------------------------------------------------------- /companies/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 4.0.0 22 | 23 | 24 | org.axonframework.samples 25 | axon-trader 26 | 2.0-SNAPSHOT 27 | 28 | 29 | axon-trader-companies 30 | 31 | 32 | 33 | 34 | ${project.groupId} 35 | axon-trader-core-api 36 | ${project.version} 37 | 38 | 39 | 40 | 41 | org.springframework 42 | spring-beans 43 | 44 | 45 | 46 | org.springframework 47 | spring-context 48 | 49 | 50 | 51 | org.axonframework 52 | axon-core 53 | ${axon.version} 54 | 55 | 56 | 57 | 58 | org.axonframework 59 | axon-test 60 | ${axon.version} 61 | test 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /companies/src/main/java/org/axonframework/samples/trader/company/command/Company.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.company.command; 18 | 19 | import org.axonframework.commandhandling.CommandHandler; 20 | import org.axonframework.commandhandling.model.AggregateIdentifier; 21 | import org.axonframework.eventsourcing.EventSourcingHandler; 22 | import org.axonframework.samples.trader.api.company.*; 23 | import org.axonframework.spring.stereotype.Aggregate; 24 | 25 | import static org.axonframework.commandhandling.model.AggregateLifecycle.apply; 26 | 27 | @Aggregate 28 | public class Company { 29 | 30 | @AggregateIdentifier 31 | private CompanyId companyId; 32 | 33 | @SuppressWarnings("UnusedDeclaration") 34 | public Company() { 35 | // Required by Axon Framework 36 | } 37 | 38 | @CommandHandler 39 | public Company(CreateCompanyCommand cmd) { 40 | apply(new CompanyCreatedEvent( 41 | cmd.getCompanyId(), cmd.getCompanyName(), cmd.getCompanyValue(), cmd.getAmountOfShares() 42 | )); 43 | } 44 | 45 | @CommandHandler 46 | public void handle(AddOrderBookToCompanyCommand cmd) { 47 | apply(new OrderBookAddedToCompanyEvent(companyId, cmd.getOrderBookId())); 48 | } 49 | 50 | 51 | @EventSourcingHandler 52 | public void on(CompanyCreatedEvent event) { 53 | companyId = event.getCompanyId(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /companies/src/main/java/org/axonframework/samples/trader/company/command/CompanyOrderBookListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.company.command; 18 | 19 | import org.axonframework.commandhandling.gateway.CommandGateway; 20 | import org.axonframework.config.ProcessingGroup; 21 | import org.axonframework.eventhandling.EventHandler; 22 | import org.axonframework.samples.trader.api.company.AddOrderBookToCompanyCommand; 23 | import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; 24 | import org.axonframework.samples.trader.api.orders.OrderBookId; 25 | import org.axonframework.samples.trader.api.orders.trades.CreateOrderBookCommand; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | import org.springframework.beans.factory.annotation.Autowired; 29 | import org.springframework.stereotype.Service; 30 | 31 | /** 32 | * This listener is used to create order book instances when we have created a new company

33 | * TODO #28 the OrderBook aggregate should be instantiated from the Company aggregate, as is possible since axon 3.3 34 | **/ 35 | @Service 36 | @ProcessingGroup("commandPublishingEventHandlers") 37 | public class CompanyOrderBookListener { 38 | 39 | private static final Logger logger = LoggerFactory.getLogger(CompanyOrderBookListener.class); 40 | 41 | private final CommandGateway commandGateway; 42 | 43 | @Autowired 44 | public CompanyOrderBookListener(CommandGateway commandGateway) { 45 | this.commandGateway = commandGateway; 46 | } 47 | 48 | @EventHandler 49 | public void on(CompanyCreatedEvent event) { 50 | logger.debug("About to dispatch a new command to create an OrderBook for the company {}", event.getCompanyId()); 51 | 52 | OrderBookId orderBookId = new OrderBookId(); 53 | commandGateway.send(new CreateOrderBookCommand(orderBookId)); 54 | commandGateway.send(new AddOrderBookToCompanyCommand(event.getCompanyId(), orderBookId)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /companies/src/test/java/org/axonframework/samples/trader/company/command/CompanyTest.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.company.command; 2 | 3 | import org.axonframework.samples.trader.api.company.*; 4 | import org.axonframework.samples.trader.api.orders.OrderBookId; 5 | import org.axonframework.samples.trader.api.users.UserId; 6 | import org.axonframework.test.aggregate.AggregateTestFixture; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class CompanyTest { 11 | 12 | private AggregateTestFixture fixture; 13 | 14 | private CompanyId companyId = new CompanyId(); 15 | private OrderBookId orderBookId = new OrderBookId(); 16 | 17 | private CompanyCreatedEvent companyCreatedEvent; 18 | 19 | @Before 20 | public void setUp() { 21 | fixture = new AggregateTestFixture<>(Company.class); 22 | 23 | companyCreatedEvent = new CompanyCreatedEvent(companyId, "TestItem", 1000L, 10000L); 24 | } 25 | 26 | @Test 27 | public void testCreateCompany() { 28 | fixture.givenNoPriorActivity() 29 | .when(new CreateCompanyCommand(companyId, new UserId(), "TestItem", 1000L, 10000L)) 30 | .expectEvents(companyCreatedEvent); 31 | } 32 | 33 | @Test 34 | public void testAddOrderBookToCompany() { 35 | fixture.given(companyCreatedEvent) 36 | .when(new AddOrderBookToCompanyCommand(companyId, orderBookId)) 37 | .expectEvents(new OrderBookAddedToCompanyEvent(companyId, orderBookId)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /companies/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=WARN,Stdout 18 | 19 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender 20 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.Stdout.layout.conversionPattern=%d [%t] %-5p %-30.30c{1} %x - %m%n 22 | 23 | log4j.logger.org.springframework=WARN 24 | log4j.logger.org.axonframework=DEBUG 25 | log4j.logger.org.axonframework.samples.trader=WARN 26 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/company/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.company 2 | 3 | import org.axonframework.commandhandling.TargetAggregateIdentifier 4 | import org.axonframework.samples.trader.api.orders.OrderBookId 5 | import org.axonframework.samples.trader.api.users.UserId 6 | 7 | abstract class CompanyCommand(@TargetAggregateIdentifier open val companyId: CompanyId) 8 | 9 | data class CreateCompanyCommand( 10 | override val companyId: CompanyId, 11 | val userId: UserId, 12 | val companyName: String, 13 | val companyValue: Long, 14 | val amountOfShares: Long 15 | ) : CompanyCommand(companyId) 16 | 17 | data class AddOrderBookToCompanyCommand( 18 | override val companyId: CompanyId, 19 | val orderBookId: OrderBookId 20 | ) : CompanyCommand(companyId) 21 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/company/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.company 2 | 3 | import org.axonframework.samples.trader.api.orders.OrderBookId 4 | 5 | abstract class CompanyEvent(open val companyId: CompanyId) 6 | 7 | data class CompanyCreatedEvent( 8 | override val companyId: CompanyId, 9 | val companyName: String, 10 | val companyValue: Long, 11 | val amountOfShares: Long 12 | ) : CompanyEvent(companyId) 13 | 14 | data class OrderBookAddedToCompanyEvent( 15 | override val companyId: CompanyId, 16 | val orderBookId: OrderBookId 17 | ) : CompanyEvent(companyId) 18 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/company/valueObjects.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.company 2 | 3 | import org.axonframework.common.IdentifierFactory 4 | import java.io.Serializable 5 | 6 | data class CompanyId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 7 | 8 | companion object { 9 | private const val serialVersionUID = -2521069615900157076L 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/orders/trades/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.orders.trades 2 | 3 | import org.axonframework.commandhandling.TargetAggregateIdentifier 4 | import org.axonframework.samples.trader.api.orders.OrderBookId 5 | import org.axonframework.samples.trader.api.orders.OrderId 6 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 7 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 8 | import javax.validation.constraints.Min 9 | 10 | abstract class AbstractOrderCommand( 11 | open val orderId: OrderId, 12 | open val portfolioId: PortfolioId, 13 | @TargetAggregateIdentifier open val orderBookId: OrderBookId, 14 | open val transactionId: TransactionId, 15 | @Min(0) open val tradeCount: Long, 16 | @Min(0) open val itemPrice: Long 17 | ) 18 | 19 | data class CreateBuyOrderCommand( 20 | override val orderId: OrderId, 21 | override val portfolioId: PortfolioId, 22 | override val orderBookId: OrderBookId, 23 | override val transactionId: TransactionId, 24 | override val tradeCount: Long, 25 | override val itemPrice: Long 26 | ) : AbstractOrderCommand(orderId, portfolioId, orderBookId, transactionId, tradeCount, itemPrice) 27 | 28 | data class CreateSellOrderCommand( 29 | override val orderId: OrderId, 30 | override val portfolioId: PortfolioId, 31 | override val orderBookId: OrderBookId, 32 | override val transactionId: TransactionId, 33 | override val tradeCount: Long, 34 | override val itemPrice: Long 35 | ) : AbstractOrderCommand(orderId, portfolioId, orderBookId, transactionId, tradeCount, itemPrice) 36 | 37 | abstract class OrderBookCommand(@TargetAggregateIdentifier open val orderBookId: OrderBookId) 38 | 39 | data class CreateOrderBookCommand(override val orderBookId: OrderBookId) : OrderBookCommand(orderBookId) 40 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/orders/trades/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.orders.trades 2 | 3 | import org.axonframework.samples.trader.api.orders.OrderBookId 4 | import org.axonframework.samples.trader.api.orders.OrderId 5 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 6 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 7 | import java.io.Serializable 8 | 9 | abstract class AbstractOrderPlacedEvent( 10 | open val orderBookId: OrderBookId, 11 | open val orderId: OrderId, 12 | open val transactionId: TransactionId, 13 | open val tradeCount: Long, 14 | open val itemPrice: Long, 15 | open val portfolioId: PortfolioId 16 | ) 17 | 18 | data class BuyOrderPlacedEvent( 19 | override val orderBookId: OrderBookId, 20 | override val orderId: OrderId, 21 | override val transactionId: TransactionId, 22 | override val tradeCount: Long, 23 | override val itemPrice: Long, 24 | override val portfolioId: PortfolioId 25 | ) : AbstractOrderPlacedEvent(orderBookId, orderId, transactionId, tradeCount, itemPrice, portfolioId) 26 | 27 | data class SellOrderPlacedEvent( 28 | override val orderBookId: OrderBookId, 29 | override val orderId: OrderId, 30 | override val transactionId: TransactionId, 31 | override val tradeCount: Long, 32 | override val itemPrice: Long, 33 | override val portfolioId: PortfolioId 34 | ) : AbstractOrderPlacedEvent(orderBookId, orderId, transactionId, tradeCount, itemPrice, portfolioId) 35 | 36 | abstract class OrderBookEvent(open val orderBookId: OrderBookId) 37 | 38 | data class OrderBookCreatedEvent(override val orderBookId: OrderBookId) : OrderBookEvent(orderBookId) 39 | 40 | data class TradeExecutedEvent( 41 | val orderBookId: OrderBookId, 42 | val tradeCount: Long, 43 | val tradePrice: Long, 44 | val buyOrderId: OrderId, 45 | val sellOrderId: OrderId, 46 | val buyTransactionId: TransactionId, 47 | val sellTransactionId: TransactionId 48 | ) : Serializable { 49 | companion object { 50 | private const val serialVersionUID = 6292249351659536792L 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/orders/transaction/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.orders.transaction 2 | 3 | import org.axonframework.commandhandling.TargetAggregateIdentifier 4 | import org.axonframework.samples.trader.api.orders.OrderBookId 5 | import org.axonframework.samples.trader.api.orders.TransactionType 6 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 7 | 8 | abstract class TransactionCommand(@TargetAggregateIdentifier open val transactionId: TransactionId) 9 | 10 | abstract class AbstractStartTransactionCommand( 11 | override val transactionId: TransactionId, 12 | open val orderBookId: OrderBookId, 13 | open val portfolioId: PortfolioId, 14 | open val tradeCount: Long, 15 | open val pricePerItem: Long 16 | ) : TransactionCommand(transactionId) { 17 | abstract val transactionType: TransactionType 18 | } 19 | 20 | data class StartBuyTransactionCommand( 21 | override val transactionId: TransactionId, 22 | override val orderBookId: OrderBookId, 23 | override val portfolioId: PortfolioId, 24 | override val tradeCount: Long, 25 | override val pricePerItem: Long 26 | ) : AbstractStartTransactionCommand(transactionId, orderBookId, portfolioId, tradeCount, pricePerItem) { 27 | override val transactionType: TransactionType = TransactionType.BUY 28 | } 29 | 30 | data class StartSellTransactionCommand( 31 | override val transactionId: TransactionId, 32 | override val orderBookId: OrderBookId, 33 | override val portfolioId: PortfolioId, 34 | override val tradeCount: Long, 35 | override val pricePerItem: Long 36 | ) : AbstractStartTransactionCommand(transactionId, orderBookId, portfolioId, tradeCount, pricePerItem) { 37 | override val transactionType: TransactionType = TransactionType.SELL 38 | } 39 | 40 | data class CancelTransactionCommand(override val transactionId: TransactionId) : TransactionCommand(transactionId) 41 | 42 | data class ConfirmTransactionCommand(override val transactionId: TransactionId) : TransactionCommand(transactionId) 43 | 44 | data class ExecutedTransactionCommand( 45 | override val transactionId: TransactionId, 46 | val amountOfItems: Long, 47 | val itemPrice: Long 48 | ) : TransactionCommand(transactionId) 49 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/orders/transaction/valueObjects.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.orders.transaction 2 | 3 | import org.axonframework.common.IdentifierFactory 4 | import java.io.Serializable 5 | 6 | data class TransactionId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 7 | 8 | companion object { 9 | private const val serialVersionUID = -5267104328616955617L 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/orders/valueObjects.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.orders 2 | 3 | import org.axonframework.common.IdentifierFactory 4 | import java.io.Serializable 5 | 6 | enum class TransactionType { 7 | SELL, BUY 8 | } 9 | 10 | data class OrderBookId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 11 | 12 | companion object { 13 | private const val serialVersionUID = -7842002574176005113L 14 | } 15 | 16 | } 17 | 18 | data class OrderId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 19 | 20 | companion object { 21 | private const val serialVersionUID = 4034328048230397374L 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/cash/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio.cash 2 | 3 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 4 | import org.axonframework.samples.trader.api.portfolio.PortfolioCommand 5 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 6 | import javax.validation.constraints.Min 7 | 8 | data class CancelCashReservationCommand( 9 | override val portfolioId: PortfolioId, 10 | val transactionId: TransactionId, 11 | val amountOfMoneyToCancel: Long 12 | ) : PortfolioCommand(portfolioId) 13 | 14 | data class ConfirmCashReservationCommand( 15 | override val portfolioId: PortfolioId, 16 | val transactionId: TransactionId, 17 | val amountOfMoneyToConfirmInCents: Long 18 | ) : PortfolioCommand(portfolioId) 19 | 20 | data class DepositCashCommand( 21 | override val portfolioId: PortfolioId, 22 | @Min(0) val moneyToAddInCents: Long 23 | ) : PortfolioCommand(portfolioId) 24 | 25 | data class ReserveCashCommand( 26 | override val portfolioId: PortfolioId, 27 | val transactionId: TransactionId, 28 | @Min(0) val amountOfMoneyToReserve: Long 29 | ) : PortfolioCommand(portfolioId) 30 | 31 | data class WithdrawCashCommand( 32 | override val portfolioId: PortfolioId, 33 | @Min(0) val amountToPayInCents: Long 34 | ) : PortfolioCommand(portfolioId) 35 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/cash/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio.cash 2 | 3 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 4 | import org.axonframework.samples.trader.api.portfolio.PortfolioEvent 5 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 6 | 7 | data class CashDepositedEvent( 8 | override val portfolioId: PortfolioId, 9 | val moneyAddedInCents: Long 10 | ) : PortfolioEvent(portfolioId) 11 | 12 | data class CashReservationCancelledEvent( 13 | override val portfolioId: PortfolioId, 14 | val transactionId: TransactionId, 15 | val amountOfMoneyToCancel: Long 16 | ) : PortfolioEvent(portfolioId) 17 | 18 | data class CashReservationConfirmedEvent( 19 | override val portfolioId: PortfolioId, 20 | val transactionId: TransactionId, 21 | val amountOfMoneyConfirmedInCents: Long 22 | ) : PortfolioEvent(portfolioId) 23 | 24 | data class CashReservationRejectedEvent( 25 | override val portfolioId: PortfolioId, 26 | val transactionId: TransactionId, 27 | val amountToPayInCents: Long 28 | ) : PortfolioEvent(portfolioId) 29 | 30 | data class CashReservedEvent( 31 | override val portfolioId: PortfolioId, 32 | val transactionId: TransactionId, 33 | val amountToReserve: Long 34 | ) : PortfolioEvent(portfolioId) 35 | 36 | data class CashWithdrawnEvent( 37 | override val portfolioId: PortfolioId, 38 | val amountPaidInCents: Long 39 | ) : PortfolioEvent(portfolioId) 40 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio 2 | 3 | import org.axonframework.commandhandling.TargetAggregateIdentifier 4 | import org.axonframework.samples.trader.api.users.UserId 5 | 6 | abstract class PortfolioCommand(@TargetAggregateIdentifier open val portfolioId: PortfolioId) 7 | 8 | data class CreatePortfolioCommand( 9 | override val portfolioId: PortfolioId, 10 | val userId: UserId 11 | ) : PortfolioCommand(portfolioId) 12 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio 2 | 3 | import org.axonframework.samples.trader.api.users.UserId 4 | 5 | abstract class PortfolioEvent(open val portfolioId: PortfolioId) 6 | 7 | class PortfolioCreatedEvent( 8 | override val portfolioId: PortfolioId, 9 | val userId: UserId 10 | ) : PortfolioEvent(portfolioId) 11 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/stock/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio.stock 2 | 3 | import org.axonframework.samples.trader.api.orders.OrderBookId 4 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 5 | import org.axonframework.samples.trader.api.portfolio.PortfolioCommand 6 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 7 | import javax.validation.constraints.Min 8 | 9 | data class AddItemsToPortfolioCommand( 10 | override val portfolioId: PortfolioId, 11 | val orderBookId: OrderBookId, 12 | @Min(0) val amountOfItemsToAdd: Long 13 | ) : PortfolioCommand(portfolioId) 14 | 15 | data class CancelItemReservationForPortfolioCommand( 16 | override val portfolioId: PortfolioId, 17 | val orderBookId: OrderBookId, 18 | val transactionId: TransactionId, 19 | val amountOfItemsToCancel: Long 20 | ) : PortfolioCommand(portfolioId) 21 | 22 | data class ConfirmItemReservationForPortfolioCommand( 23 | override val portfolioId: PortfolioId, 24 | val orderBookId: OrderBookId, 25 | val transactionId: TransactionId, 26 | val amountOfItemsToConfirm: Long 27 | ) : PortfolioCommand(portfolioId) 28 | 29 | data class ReserveItemsCommand( 30 | override val portfolioId: PortfolioId, 31 | val orderBookId: OrderBookId, 32 | val transactionId: TransactionId, 33 | val amountOfItemsToReserve: Long 34 | ) : PortfolioCommand(portfolioId) 35 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/stock/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio.stock 2 | 3 | import org.axonframework.samples.trader.api.orders.OrderBookId 4 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId 5 | import org.axonframework.samples.trader.api.portfolio.PortfolioEvent 6 | import org.axonframework.samples.trader.api.portfolio.PortfolioId 7 | 8 | data class ItemReservationCancelledForPortfolioEvent( 9 | override val portfolioId: PortfolioId, 10 | val orderBookId: OrderBookId, 11 | val transactionId: TransactionId, 12 | val amountOfCancelledItems: Long 13 | ) : PortfolioEvent(portfolioId) 14 | 15 | data class ItemReservationConfirmedForPortfolioEvent( 16 | override val portfolioId: PortfolioId, 17 | val orderBookId: OrderBookId, 18 | val transactionId: TransactionId, 19 | val amountOfConfirmedItems: Long 20 | ) : PortfolioEvent(portfolioId) 21 | 22 | data class ItemsAddedToPortfolioEvent( 23 | override val portfolioId: PortfolioId, 24 | val orderBookId: OrderBookId, 25 | val amountOfItemsAdded: Long 26 | ) : PortfolioEvent(portfolioId) 27 | 28 | data class ItemsReservedEvent( 29 | override val portfolioId: PortfolioId, 30 | val orderBookId: OrderBookId, 31 | val transactionId: TransactionId, 32 | val amountOfItemsReserved: Long 33 | ) : PortfolioEvent(portfolioId) 34 | 35 | data class ItemToReserveNotAvailableInPortfolioEvent( 36 | override val portfolioId: PortfolioId, 37 | val orderBookId: OrderBookId, 38 | val transactionId: TransactionId 39 | ) : PortfolioEvent(portfolioId) 40 | 41 | data class NotEnoughItemsAvailableToReserveInPortfolioEvent( 42 | override val portfolioId: PortfolioId, 43 | val orderBookId: OrderBookId, 44 | val transactionId: TransactionId, 45 | val availableAmountOfItems: Long, 46 | val amountOfItemsToReserve: Long 47 | ) : PortfolioEvent(portfolioId) 48 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/portfolio/valueObjects.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.portfolio 2 | 3 | import org.axonframework.common.IdentifierFactory 4 | import java.io.Serializable 5 | 6 | data class PortfolioId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 7 | 8 | companion object { 9 | private const val serialVersionUID = 6784433385287437985L 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/users/UserAccount.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.api.users; 18 | 19 | /** 20 | * Object used to obtain information about an available UserAccount 21 | * 22 | * @author Jettro Coenradie 23 | */ 24 | public interface UserAccount { 25 | 26 | String getUserId(); 27 | 28 | String getUserName(); 29 | 30 | String getFullName(); 31 | } 32 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/users/commands.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.users 2 | 3 | import org.axonframework.commandhandling.TargetAggregateIdentifier 4 | import java.util.* 5 | import javax.validation.constraints.NotNull 6 | import javax.validation.constraints.Size 7 | 8 | abstract class UserCommand(@TargetAggregateIdentifier open val userId: UserId) 9 | 10 | class CreateUserCommand( 11 | override val userId: UserId, 12 | val name: String, @NotNull @Size(min = 3) 13 | val username: String, @NotNull @Size(min = 3) 14 | val password: String 15 | ) : UserCommand(userId) 16 | 17 | data class AuthenticateUserCommand( 18 | override val userId: UserId, 19 | val userName: String, 20 | @NotNull @Size(min = 3) val password: CharArray 21 | ) : UserCommand(userId) { 22 | 23 | override fun equals(other: Any?): Boolean { 24 | if (this === other) return true 25 | if (other !is AuthenticateUserCommand) return false 26 | 27 | if (userId != other.userId) return false 28 | if (userName != other.userName) return false 29 | if (!Arrays.equals(password, other.password)) return false 30 | 31 | return true 32 | } 33 | 34 | override fun hashCode(): Int { 35 | var result = userId.hashCode() 36 | result = 31 * result + userName.hashCode() 37 | result = 31 * result + Arrays.hashCode(password) 38 | return result 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/users/events.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.users 2 | 3 | abstract class UserEvent(open val userId: UserId) 4 | 5 | data class UserCreatedEvent( 6 | override val userId: UserId, 7 | val name: String, 8 | val username: String, 9 | val password: String 10 | ) : UserEvent(userId) 11 | 12 | data class UserAuthenticatedEvent(override val userId: UserId) : UserEvent(userId) 13 | -------------------------------------------------------------------------------- /core-api/src/main/java/org/axonframework/samples/trader/api/users/valueObjects.kt: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.api.users 2 | 3 | import org.axonframework.common.IdentifierFactory 4 | import java.io.Serializable 5 | 6 | data class UserId(val identifier: String = IdentifierFactory.getInstance().generateIdentifier()) : Serializable { 7 | 8 | companion object { 9 | private const val serialVersionUID = -4860092244272266543L 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /external-listeners/src/main/java/org/axonframework/samples/trader/listener/BroadcastingTextWebSocketHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.listener; 18 | 19 | import org.slf4j.Logger; 20 | import org.slf4j.LoggerFactory; 21 | import org.springframework.web.socket.CloseStatus; 22 | import org.springframework.web.socket.TextMessage; 23 | import org.springframework.web.socket.WebSocketSession; 24 | import org.springframework.web.socket.handler.ConcurrentWebSocketSessionDecorator; 25 | import org.springframework.web.socket.handler.TextWebSocketHandler; 26 | 27 | import java.io.IOException; 28 | import java.util.Map; 29 | import java.util.concurrent.ConcurrentHashMap; 30 | import java.util.concurrent.TimeUnit; 31 | 32 | class BroadcastingTextWebSocketHandler extends TextWebSocketHandler { 33 | 34 | private static final Logger logger = LoggerFactory.getLogger(BroadcastingTextWebSocketHandler.class); 35 | private Map sessions = new ConcurrentHashMap<>(); 36 | 37 | @Override 38 | public void afterConnectionEstablished(WebSocketSession session) throws Exception { 39 | super.afterConnectionEstablished(session); 40 | 41 | sessions.put(session.getId(), 42 | new ConcurrentWebSocketSessionDecorator(session, (int) TimeUnit.SECONDS.toMillis(10), 5 * 1024)); 43 | } 44 | 45 | @Override 46 | public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { 47 | super.afterConnectionClosed(session, status); 48 | 49 | sessions.remove(session.getId()); 50 | } 51 | 52 | protected void broadcast(String data) { 53 | final TextMessage message = new TextMessage(data); 54 | sessions.forEach((key, session) -> { 55 | try { 56 | session.sendMessage(message); 57 | } catch (IOException e) { 58 | logger.warn("An error occurred while trying to send a message to a WebSocket", e); 59 | } 60 | }); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /external-listeners/src/main/java/org/axonframework/samples/trader/listener/ExecutedTradesBroadcaster.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.listener; 18 | 19 | import org.axonframework.eventhandling.EventHandler; 20 | import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; 21 | import org.codehaus.jackson.JsonFactory; 22 | import org.codehaus.jackson.JsonGenerator; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | import org.springframework.stereotype.Component; 26 | 27 | import java.io.IOException; 28 | import java.io.StringWriter; 29 | import java.io.Writer; 30 | 31 | /** 32 | *

Creates a JSON object and broadcasts it to every connected WebSocket session. The structure of the json object is:

33 | *
34 |  * {
35 |  *     tradeExecuted :
36 |  *     {
37 |  *         orderbookId: ... ,
38 |  *         count: ... ,
39 |  *         price: ...
40 |  *     }
41 |  * }
42 |  * 
43 | *

The url to send the request to can be configured.

44 | * 45 | * @author Jettro Coenradie 46 | */ 47 | @Component 48 | public class ExecutedTradesBroadcaster extends BroadcastingTextWebSocketHandler { 49 | private static final Logger logger = LoggerFactory.getLogger(ExecutedTradesBroadcaster.class); 50 | 51 | private JsonFactory jsonFactory = new JsonFactory(); 52 | 53 | @EventHandler 54 | public void handle(TradeExecutedEvent event) { 55 | try { 56 | doHandle(event); 57 | } catch (IOException e) { 58 | logger.warn("Problem while sending TradeExecutedEvent to external system"); 59 | } 60 | } 61 | 62 | private void doHandle(TradeExecutedEvent event) throws IOException { 63 | String jsonObjectAsString = createJsonInString(event); 64 | 65 | this.broadcast(jsonObjectAsString); 66 | } 67 | 68 | private String createJsonInString(TradeExecutedEvent event) throws IOException { 69 | Writer writer = new StringWriter(); 70 | JsonGenerator g = jsonFactory.createJsonGenerator(writer); 71 | g.writeStartObject(); 72 | g.writeObjectFieldStart("tradeExecuted"); 73 | g.writeStringField("orderbookId", event.getOrderBookId().toString()); 74 | g.writeStringField("count", String.valueOf(event.getTradeCount())); 75 | g.writeStringField("price", String.valueOf(event.getTradePrice())); 76 | g.writeEndObject(); // for trade-executed 77 | g.close(); 78 | return writer.toString(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /external-listeners/src/main/java/org/axonframework/samples/trader/listener/WebSocketConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.listener; 18 | 19 | import org.springframework.beans.factory.annotation.Autowired; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.web.socket.config.annotation.EnableWebSocket; 22 | import org.springframework.web.socket.config.annotation.WebSocketConfigurer; 23 | import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry; 24 | 25 | @Configuration 26 | @EnableWebSocket 27 | public class WebSocketConfig implements WebSocketConfigurer { 28 | 29 | @Autowired 30 | private ExecutedTradesBroadcaster executedTradesBroadcaster; 31 | 32 | @Override 33 | public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { 34 | registry.addHandler(executedTradesBroadcaster, "/eventbus") 35 | .withSockJS(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /external-listeners/src/main/java/org/axonframework/samples/trader/listener/config/ExternalListenersConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.listener.config; 18 | 19 | import org.axonframework.eventhandling.EventProcessor; 20 | import org.axonframework.eventhandling.SimpleEventHandlerInvoker; 21 | import org.axonframework.eventhandling.SubscribingEventProcessor; 22 | import org.axonframework.eventsourcing.eventstore.EventStore; 23 | import org.axonframework.samples.trader.listener.ExecutedTradesBroadcaster; 24 | import org.springframework.beans.factory.annotation.Autowired; 25 | import org.springframework.context.annotation.Bean; 26 | import org.springframework.context.annotation.ComponentScan; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.context.annotation.PropertySource; 29 | import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; 30 | 31 | @Configuration 32 | @ComponentScan("org.axonframework.samples.trader.listener") 33 | @PropertySource("classpath:external-config.properties") 34 | public class ExternalListenersConfig { 35 | 36 | @Autowired 37 | private EventStore eventStore; 38 | 39 | @Autowired 40 | private ExecutedTradesBroadcaster executedTradesBroadcaster; 41 | 42 | @Bean 43 | public EventProcessor externalListenersEventProcessor() { 44 | SubscribingEventProcessor eventProcessor = new SubscribingEventProcessor("externalListenersEventProcessor", 45 | new SimpleEventHandlerInvoker(executedTradesBroadcaster), 46 | eventStore); 47 | 48 | eventProcessor.start(); 49 | 50 | return eventProcessor; 51 | } 52 | 53 | @Bean 54 | public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() { 55 | PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); 56 | return configurer; 57 | } 58 | } -------------------------------------------------------------------------------- /external-listeners/src/main/resources/META-INF/spring/external-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /external-listeners/src/main/resources/external-config.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | serverUrlEventBus=http://localhost:8080/eventbus 17 | -------------------------------------------------------------------------------- /infrastructure/src/main/java/org/axonframework/samples/trader/infra/config/CQRSInfrastructureHSQLDBConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.infra.config; 18 | 19 | import org.axonframework.common.jdbc.ConnectionProvider; 20 | import org.axonframework.common.transaction.NoTransactionManager; 21 | import org.axonframework.eventhandling.saga.repository.SagaStore; 22 | import org.axonframework.eventhandling.saga.repository.jdbc.HsqlSagaSqlSchema; 23 | import org.axonframework.eventhandling.saga.repository.jdbc.JdbcSagaStore; 24 | import org.axonframework.eventhandling.saga.repository.jdbc.SagaSqlSchema; 25 | import org.axonframework.eventsourcing.eventstore.EmbeddedEventStore; 26 | import org.axonframework.eventsourcing.eventstore.EventStore; 27 | import org.axonframework.eventsourcing.eventstore.jdbc.EventSchema; 28 | import org.axonframework.eventsourcing.eventstore.jdbc.EventTableFactory; 29 | import org.axonframework.eventsourcing.eventstore.jdbc.HsqlEventTableFactory; 30 | import org.axonframework.eventsourcing.eventstore.jdbc.JdbcEventStorageEngine; 31 | import org.axonframework.spring.jdbc.SpringDataSourceConnectionProvider; 32 | import org.springframework.context.annotation.Bean; 33 | import org.springframework.context.annotation.Configuration; 34 | import org.springframework.context.annotation.Profile; 35 | 36 | import javax.sql.DataSource; 37 | 38 | @Configuration 39 | @Profile("hsqldb") 40 | public class CQRSInfrastructureHSQLDBConfig { 41 | 42 | @Bean 43 | public SpringDataSourceConnectionProvider springDataSourceConnectionProvider(DataSource dataSource) { 44 | return new SpringDataSourceConnectionProvider(dataSource); 45 | } 46 | 47 | @Bean 48 | public JdbcEventStorageEngine eventStorageEngine(ConnectionProvider connectionProvider) { 49 | return new JdbcEventStorageEngine(connectionProvider, NoTransactionManager.INSTANCE); 50 | } 51 | 52 | @Bean 53 | public EventStore eventStore(ConnectionProvider connectionProvider) { 54 | return new EmbeddedEventStore(eventStorageEngine(connectionProvider)); 55 | } 56 | 57 | @Bean 58 | public EventTableFactory eventSchemaFactory() { 59 | return HsqlEventTableFactory.INSTANCE; 60 | } 61 | 62 | @Bean 63 | public EventSchema eventSchema() { 64 | return new EventSchema(); 65 | } 66 | 67 | @Bean 68 | public SagaSqlSchema sagaSqlSchema() { 69 | return new HsqlSagaSqlSchema(); 70 | } 71 | 72 | @Bean 73 | public SagaStore sagaRepository(DataSource dataSource) { 74 | return new JdbcSagaStore(dataSource, sagaSqlSchema()); 75 | } 76 | } -------------------------------------------------------------------------------- /infrastructure/src/main/java/org/axonframework/samples/trader/infra/config/PersistenceInfrastructureConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.infra.config; 18 | 19 | import org.springframework.context.annotation.Bean; 20 | import org.springframework.context.annotation.Configuration; 21 | import org.springframework.context.annotation.Profile; 22 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean; 23 | import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; 24 | 25 | @Configuration 26 | public class PersistenceInfrastructureConfig { 27 | 28 | @Bean 29 | @Profile("hsqldb") 30 | public EmbeddedDatabaseFactoryBean dataSource() { 31 | EmbeddedDatabaseFactoryBean embeddedDatabaseFactoryBean = new EmbeddedDatabaseFactoryBean(); 32 | embeddedDatabaseFactoryBean.setDatabaseType(EmbeddedDatabaseType.HSQL); 33 | 34 | return embeddedDatabaseFactoryBean; 35 | } 36 | } -------------------------------------------------------------------------------- /infrastructure/src/main/resources/META-INF/spring/configuration-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /infrastructure/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 22 | 33 | 34 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /infrastructure/src/main/resources/trader.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | server1.host=localhost 17 | server1.port=27017 18 | server2.host=localhost 19 | server2.port=27018 20 | server3.host=localhost 21 | server3.port=27019 22 | 23 | 24 | -------------------------------------------------------------------------------- /orders/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 20 | 21 | org.axonframework.samples 22 | axon-trader 23 | 2.0-SNAPSHOT 24 | 25 | 4.0.0 26 | 27 | axon-trader-orders 28 | 29 | 30 | 31 | 32 | ${project.groupId} 33 | axon-trader-core-api 34 | ${project.version} 35 | 36 | 37 | ${project.groupId} 38 | axon-trader-users-query 39 | ${project.version} 40 | 41 | 42 | 43 | 44 | org.axonframework 45 | axon-core 46 | ${axon.version} 47 | 48 | 49 | 50 | 51 | org.axonframework 52 | axon-test 53 | ${axon.version} 54 | test 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /orders/src/main/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command; 18 | 19 | import org.axonframework.commandhandling.gateway.CommandGateway; 20 | import org.axonframework.config.ProcessingGroup; 21 | import org.axonframework.eventhandling.EventHandler; 22 | import org.axonframework.samples.trader.api.portfolio.CreatePortfolioCommand; 23 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 24 | import org.axonframework.samples.trader.api.users.UserCreatedEvent; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | import org.springframework.beans.factory.annotation.Autowired; 28 | import org.springframework.stereotype.Service; 29 | 30 | /** 31 | * Listener that is used to create a new portfolio for each new user that is created. 32 | * TODO #28 the Portfolio aggregate should be instantiated from the Company aggregate, as is possible since axon 3.3 33 | */ 34 | @Service 35 | @ProcessingGroup("commandPublishingEventHandlers") 36 | public class PortfolioManagementUserListener { 37 | 38 | private static final Logger logger = LoggerFactory.getLogger(PortfolioManagementUserListener.class); 39 | 40 | private final CommandGateway commandGateway; 41 | 42 | @Autowired 43 | public PortfolioManagementUserListener(CommandGateway commandGateway) { 44 | this.commandGateway = commandGateway; 45 | } 46 | 47 | @EventHandler 48 | public void on(UserCreatedEvent event) { 49 | logger.debug("About to dispatch a new command to create a Portfolio for the new user {}", event.getUserId()); 50 | commandGateway.send(new CreatePortfolioCommand(new PortfolioId(), event.getUserId())); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /orders/src/main/java/org/axonframework/samples/trader/orders/command/TradeManagerSaga.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command; 18 | 19 | import org.axonframework.commandhandling.gateway.CommandGateway; 20 | import org.axonframework.samples.trader.api.orders.OrderBookId; 21 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId; 22 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 23 | import org.springframework.beans.factory.annotation.Autowired; 24 | 25 | import java.io.Serializable; 26 | 27 | public abstract class TradeManagerSaga implements Serializable { 28 | 29 | transient CommandGateway commandGateway; 30 | 31 | TransactionId transactionId; 32 | OrderBookId orderBookId; 33 | PortfolioId portfolioId; 34 | long totalItems; 35 | long pricePerItem; 36 | 37 | @Autowired 38 | public void setCommandGateway(CommandGateway commandGateway) { 39 | this.commandGateway = commandGateway; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /orders/src/main/java/org/axonframework/samples/trader/orders/config/OrderConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.config; 18 | 19 | import org.axonframework.config.SagaConfiguration; 20 | import org.axonframework.samples.trader.orders.command.BuyTradeManagerSaga; 21 | import org.axonframework.samples.trader.orders.command.SellTradeManagerSaga; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | @Configuration 26 | public class OrderConfig { 27 | 28 | @Bean 29 | public SagaConfiguration buyTradeSagaConfiguration() { 30 | return SagaConfiguration.trackingSagaManager(BuyTradeManagerSaga.class); 31 | } 32 | 33 | @Bean 34 | public SagaConfiguration sellTradeSagaConfiguration() { 35 | return SagaConfiguration.trackingSagaManager(SellTradeManagerSaga.class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/PortfolioManagementUserListenerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command; 18 | 19 | import org.axonframework.commandhandling.gateway.CommandGateway; 20 | import org.axonframework.samples.trader.api.portfolio.CreatePortfolioCommand; 21 | import org.axonframework.samples.trader.api.users.UserCreatedEvent; 22 | import org.axonframework.samples.trader.api.users.UserId; 23 | import org.junit.Test; 24 | import org.mockito.ArgumentMatcher; 25 | 26 | import static org.mockito.Matchers.argThat; 27 | import static org.mockito.Mockito.mock; 28 | import static org.mockito.Mockito.verify; 29 | 30 | public class PortfolioManagementUserListenerTest { 31 | 32 | private final CommandGateway commandGateway = mock(CommandGateway.class); 33 | 34 | private final PortfolioManagementUserListener listener = new PortfolioManagementUserListener(commandGateway); 35 | 36 | @Test 37 | public void checkPortfolioCreationAfterUserCreated() { 38 | UserId userId = new UserId(); 39 | 40 | listener.on(new UserCreatedEvent(userId, "Test", "testuser", "testpassword")); 41 | 42 | verify(commandGateway).send(argThat(new CreatePortfolioCommandMatcher(userId))); 43 | } 44 | 45 | // TODO #28 replace this by a direct command equals call. This requires instantiating the aggregate ids ourselves 46 | private class CreatePortfolioCommandMatcher extends ArgumentMatcher { 47 | 48 | private UserId userId; 49 | 50 | private CreatePortfolioCommandMatcher(UserId userId) { 51 | this.userId = userId; 52 | } 53 | 54 | @Override 55 | public boolean matches(Object argument) { 56 | if (!(argument instanceof CreatePortfolioCommand)) { 57 | return false; 58 | } 59 | 60 | CreatePortfolioCommand createPortfolioCommand = (CreatePortfolioCommand) argument; 61 | return createPortfolioCommand.getUserId().equals(userId); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/AddItemsToPortfolioCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.OrderBookId; 20 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 21 | import org.axonframework.samples.trader.api.portfolio.stock.AddItemsToPortfolioCommand; 22 | import org.hamcrest.Description; 23 | import org.hamcrest.Matcher; 24 | 25 | public class AddItemsToPortfolioCommandMatcher extends BaseCommandMatcher { 26 | 27 | private OrderBookId orderBookIdentifier; 28 | private PortfolioId portfolioIdentifier; 29 | private long amountOfItemsToAdd; 30 | 31 | private AddItemsToPortfolioCommandMatcher(PortfolioId portfolioIdentifier, 32 | OrderBookId orderBookIdentifier, long amountOfItemsToAdd) { 33 | this.amountOfItemsToAdd = amountOfItemsToAdd; 34 | this.portfolioIdentifier = portfolioIdentifier; 35 | this.orderBookIdentifier = orderBookIdentifier; 36 | } 37 | 38 | public static Matcher newInstance(PortfolioId portfolioIdentifier, 39 | OrderBookId orderBookIdentifier, long amountOfItemsToAdd) { 40 | return new AddItemsToPortfolioCommandMatcher(portfolioIdentifier, orderBookIdentifier, amountOfItemsToAdd); 41 | } 42 | 43 | @Override 44 | protected boolean doMatches(AddItemsToPortfolioCommand command) { 45 | return command.getOrderBookId().equals(orderBookIdentifier) 46 | && command.getPortfolioId().equals(portfolioIdentifier) 47 | && command.getAmountOfItemsToAdd() == amountOfItemsToAdd; 48 | } 49 | 50 | @Override 51 | public void describeTo(Description description) { 52 | description.appendText("AddItemsToPortfolioCommand with amountOfItemsToAdd [") 53 | .appendValue(amountOfItemsToAdd) 54 | .appendText("] for OrderBook with identifier [") 55 | .appendValue(orderBookIdentifier) 56 | .appendText("] and for Portfolio with identifier [") 57 | .appendValue(portfolioIdentifier) 58 | .appendText("]"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/BaseCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.commandhandling.CommandMessage; 20 | import org.hamcrest.BaseMatcher; 21 | 22 | /** 23 | * @author Jettro Coenradie 24 | */ 25 | public abstract class BaseCommandMatcher extends BaseMatcher { 26 | @Override 27 | public final boolean matches(Object o) { 28 | if (!(o instanceof CommandMessage)) { 29 | return false; 30 | } 31 | CommandMessage message = (CommandMessage) o; 32 | 33 | return doMatches(message.getPayload()); 34 | } 35 | 36 | protected abstract boolean doMatches(T message); 37 | } 38 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelMoneyReservationFromPortfolioCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 20 | import org.axonframework.samples.trader.api.portfolio.cash.CancelCashReservationCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | public class CancelMoneyReservationFromPortfolioCommandMatcher 25 | extends BaseCommandMatcher { 26 | 27 | private CancelMoneyReservationFromPortfolioCommandMatcher(PortfolioId portfolioIdentifier, 28 | long amountOfMoneyToCancel) { 29 | this.portfolioIdentifier = portfolioIdentifier; 30 | this.amountOfMoneyToCancel = amountOfMoneyToCancel; 31 | } 32 | 33 | public static Matcher newInstance(PortfolioId portfolioIdentifier, long amountOfMoneyToCancel) { 34 | return new CancelMoneyReservationFromPortfolioCommandMatcher(portfolioIdentifier, amountOfMoneyToCancel); 35 | } 36 | 37 | private PortfolioId portfolioIdentifier; 38 | private long amountOfMoneyToCancel; 39 | 40 | @Override 41 | protected boolean doMatches(CancelCashReservationCommand command) { 42 | return command.getPortfolioId().equals(portfolioIdentifier) 43 | && command.getAmountOfMoneyToCancel() == amountOfMoneyToCancel; 44 | } 45 | 46 | @Override 47 | public void describeTo(Description description) { 48 | description.appendText("CancelCashReservationCommand with amountOfMoneyToCancel [") 49 | .appendValue(amountOfMoneyToCancel) 50 | .appendText("] for Portfolio with identifier [") 51 | .appendValue(portfolioIdentifier) 52 | .appendText("]"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CancelTransactionCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId; 20 | import org.axonframework.samples.trader.api.orders.transaction.CancelTransactionCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | /** 25 | * @author Jettro Coenradie 26 | */ 27 | public class CancelTransactionCommandMatcher extends BaseCommandMatcher { 28 | 29 | private TransactionId transactionIdentifier; 30 | 31 | private CancelTransactionCommandMatcher(TransactionId transactionIdentifier) { 32 | this.transactionIdentifier = transactionIdentifier; 33 | } 34 | 35 | public static Matcher newInstance(TransactionId transactionIdentifier) { 36 | return new CancelTransactionCommandMatcher(transactionIdentifier); 37 | } 38 | 39 | @Override 40 | protected boolean doMatches(CancelTransactionCommand command) { 41 | return command.getTransactionId().equals(transactionIdentifier); 42 | } 43 | 44 | @Override 45 | public void describeTo(Description description) { 46 | description.appendText("CancelTransactionCommand for Transaction with identifier [") 47 | .appendValue(transactionIdentifier) 48 | .appendText("]"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmItemReservationForPortfolioCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.OrderBookId; 20 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 21 | import org.axonframework.samples.trader.api.portfolio.stock.ConfirmItemReservationForPortfolioCommand; 22 | import org.hamcrest.Description; 23 | import org.hamcrest.Matcher; 24 | 25 | public class ConfirmItemReservationForPortfolioCommandMatcher 26 | extends BaseCommandMatcher { 27 | 28 | private OrderBookId orderbookIdentifier; 29 | private PortfolioId portfolioIdentifier; 30 | private int amountOfConfirmedItems; 31 | 32 | public ConfirmItemReservationForPortfolioCommandMatcher( 33 | OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, int amountOfConfirmedItems) { 34 | this.orderbookIdentifier = orderbookIdentifier; 35 | this.portfolioIdentifier = portfolioIdentifier; 36 | this.amountOfConfirmedItems = amountOfConfirmedItems; 37 | } 38 | 39 | public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, 40 | int amountOfConfirmedItems) { 41 | return new ConfirmItemReservationForPortfolioCommandMatcher(orderbookIdentifier, 42 | portfolioIdentifier, 43 | amountOfConfirmedItems); 44 | } 45 | 46 | @Override 47 | protected boolean doMatches(ConfirmItemReservationForPortfolioCommand command) { 48 | return command.getOrderBookId().equals(orderbookIdentifier) 49 | && command.getPortfolioId().equals(portfolioIdentifier) 50 | && amountOfConfirmedItems == command.getAmountOfItemsToConfirm(); 51 | } 52 | 53 | @Override 54 | public void describeTo(Description description) { 55 | description.appendText("ConfirmItemReservationForPortfolioCommand with amountOfConfirmedItems [") 56 | .appendValue(amountOfConfirmedItems) 57 | .appendText("] for OrderBook with identifier [") 58 | .appendValue(orderbookIdentifier) 59 | .appendText("] and for Portfolio with identifier [") 60 | .appendValue(portfolioIdentifier) 61 | .appendText("]"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmMoneyReservationFromPortfolionCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 20 | import org.axonframework.samples.trader.api.portfolio.cash.ConfirmCashReservationCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | public class ConfirmMoneyReservationFromPortfolionCommandMatcher 25 | extends BaseCommandMatcher { 26 | 27 | private PortfolioId portfolioIdentifier; 28 | private long amountOfMoneyToconfirm; 29 | 30 | private ConfirmMoneyReservationFromPortfolionCommandMatcher(PortfolioId portfolioIdentifier, 31 | long amountOfMoneyToConfirm) { 32 | this.portfolioIdentifier = portfolioIdentifier; 33 | this.amountOfMoneyToconfirm = amountOfMoneyToConfirm; 34 | } 35 | 36 | public static Matcher newInstance(PortfolioId portfolioIdentifier, long amountOfMoneyToConfirm) { 37 | return new ConfirmMoneyReservationFromPortfolionCommandMatcher(portfolioIdentifier, amountOfMoneyToConfirm); 38 | } 39 | 40 | @Override 41 | protected boolean doMatches(ConfirmCashReservationCommand command) { 42 | return command.getPortfolioId().equals(portfolioIdentifier) 43 | && command.getAmountOfMoneyToConfirmInCents() == amountOfMoneyToconfirm; 44 | } 45 | 46 | @Override 47 | public void describeTo(Description description) { 48 | description.appendText("ConfirmCashReservationCommand with amountOfMoneyToConfirm [") 49 | .appendValue(amountOfMoneyToconfirm) 50 | .appendText("] for Portfolio with identifier [") 51 | .appendValue(portfolioIdentifier) 52 | .appendText("]"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ConfirmTransactionCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId; 20 | import org.axonframework.samples.trader.api.orders.transaction.ConfirmTransactionCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | /** 25 | * @author Jettro Coenradie 26 | */ 27 | public class ConfirmTransactionCommandMatcher extends BaseCommandMatcher { 28 | 29 | private TransactionId transactionIdentifier; 30 | 31 | private ConfirmTransactionCommandMatcher(TransactionId transactionIdentifier) { 32 | this.transactionIdentifier = transactionIdentifier; 33 | } 34 | 35 | public static Matcher newInstance(TransactionId transactionIdentifier) { 36 | return new ConfirmTransactionCommandMatcher(transactionIdentifier); 37 | } 38 | 39 | @Override 40 | protected boolean doMatches(ConfirmTransactionCommand command) { 41 | return command.getTransactionId().equals(transactionIdentifier); 42 | } 43 | 44 | @Override 45 | public void describeTo(Description description) { 46 | description.appendText("CancelTransactionCommand for Transaction with identifier [") 47 | .appendValue(transactionIdentifier) 48 | .appendText("]"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateBuyOrderCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.OrderBookId; 20 | import org.axonframework.samples.trader.api.orders.trades.CreateBuyOrderCommand; 21 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 22 | import org.hamcrest.Description; 23 | import org.hamcrest.Matcher; 24 | 25 | public class CreateBuyOrderCommandMatcher extends BaseCommandMatcher { 26 | 27 | private OrderBookId orderbookIdentifier; 28 | private PortfolioId portfolioIdentifier; 29 | private long tradeCount; 30 | private long itemPrice; 31 | 32 | private CreateBuyOrderCommandMatcher(PortfolioId portfolioId, OrderBookId orderbookId, long tradeCount, 33 | long itemPrice) { 34 | this.portfolioIdentifier = portfolioId; 35 | this.orderbookIdentifier = orderbookId; 36 | this.tradeCount = tradeCount; 37 | this.itemPrice = itemPrice; 38 | } 39 | 40 | public static Matcher newInstance(PortfolioId portfolioIdentifier, OrderBookId orderbookIdentifier, long totalItems, 41 | long pricePerItem) { 42 | return new CreateBuyOrderCommandMatcher(portfolioIdentifier, orderbookIdentifier, totalItems, pricePerItem); 43 | } 44 | 45 | @Override 46 | protected boolean doMatches(CreateBuyOrderCommand command) { 47 | return command.getOrderBookId().equals(orderbookIdentifier) 48 | && command.getPortfolioId().equals(portfolioIdentifier) 49 | && tradeCount == command.getTradeCount() 50 | && itemPrice == command.getItemPrice(); 51 | } 52 | 53 | @Override 54 | public void describeTo(Description description) { 55 | description.appendText("CreateBuyOrderCommand with tradeCount [") 56 | .appendValue(tradeCount) 57 | .appendText("], itemPrice [") 58 | .appendValue(itemPrice) 59 | .appendText("] for OrderBook with identifier [") 60 | .appendValue(orderbookIdentifier) 61 | .appendText("] and for Portfolio with identifier [") 62 | .appendValue(portfolioIdentifier) 63 | .appendText("]"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/CreateSellOrderCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.OrderBookId; 20 | import org.axonframework.samples.trader.api.orders.trades.CreateSellOrderCommand; 21 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 22 | import org.hamcrest.Description; 23 | import org.hamcrest.Matcher; 24 | 25 | public class CreateSellOrderCommandMatcher extends BaseCommandMatcher { 26 | 27 | private OrderBookId orderbookIdentifier; 28 | private PortfolioId portfolioIdentifier; 29 | private long tradeCount; 30 | private int itemPrice; 31 | 32 | private CreateSellOrderCommandMatcher(PortfolioId portfolioId, OrderBookId orderbookId, long tradeCount, int itemPrice) { 33 | this.portfolioIdentifier = portfolioId; 34 | this.orderbookIdentifier = orderbookId; 35 | this.tradeCount = tradeCount; 36 | this.itemPrice = itemPrice; 37 | } 38 | 39 | public static Matcher newInstance(PortfolioId portfolioIdentifier, OrderBookId orderbookIdentifier, int tradeCount, int itemPrice) { 40 | return new CreateSellOrderCommandMatcher(portfolioIdentifier, orderbookIdentifier, tradeCount, itemPrice); 41 | } 42 | 43 | @Override 44 | protected boolean doMatches(CreateSellOrderCommand command) { 45 | return command.getOrderBookId().equals(orderbookIdentifier) 46 | && command.getPortfolioId().equals(portfolioIdentifier) 47 | && tradeCount == command.getTradeCount() 48 | && itemPrice == command.getItemPrice(); 49 | } 50 | 51 | @Override 52 | public void describeTo(Description description) { 53 | description.appendText("CreateSellOrderCommand with tradeCount [") 54 | .appendValue(tradeCount) 55 | .appendText("], itemPrice [") 56 | .appendValue(itemPrice) 57 | .appendText("] for OrderBook with identifier [") 58 | .appendValue(orderbookIdentifier) 59 | .appendText("] and for Portfolio with identifier [") 60 | .appendValue(portfolioIdentifier) 61 | .appendText("]"); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/DepositMoneyToPortfolioCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 20 | import org.axonframework.samples.trader.api.portfolio.cash.DepositCashCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | public class DepositMoneyToPortfolioCommandMatcher extends BaseCommandMatcher { 25 | 26 | private long moneyToAddInCents; 27 | private PortfolioId portfolioIdentifier; 28 | 29 | private DepositMoneyToPortfolioCommandMatcher(PortfolioId portfolioIdentifier, long moneyToAddInCents) { 30 | this.portfolioIdentifier = portfolioIdentifier; 31 | this.moneyToAddInCents = moneyToAddInCents; 32 | } 33 | 34 | public static Matcher newInstance(PortfolioId portfolioIdentifier, long moneyToAddInCents) { 35 | return new DepositMoneyToPortfolioCommandMatcher(portfolioIdentifier, moneyToAddInCents); 36 | } 37 | 38 | @Override 39 | protected boolean doMatches(DepositCashCommand command) { 40 | return moneyToAddInCents == command.getMoneyToAddInCents() 41 | && portfolioIdentifier.equals(command.getPortfolioId()); 42 | } 43 | 44 | @Override 45 | public void describeTo(Description description) { 46 | description.appendText("DepositCashCommand with moneyToAddInCents [") 47 | .appendValue(moneyToAddInCents) 48 | .appendText("] for Portfolio with identifier [") 49 | .appendValue(portfolioIdentifier) 50 | .appendText("]"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ExecutedTransactionCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId; 20 | import org.axonframework.samples.trader.api.orders.transaction.ExecutedTransactionCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | /** 25 | * @author Jettro Coenradie 26 | */ 27 | public class ExecutedTransactionCommandMatcher extends BaseCommandMatcher { 28 | 29 | private TransactionId transactionIdentifier; 30 | private long amountOfItems; 31 | private long itemPrice; 32 | 33 | private ExecutedTransactionCommandMatcher(long amountOfItems, long itemPrice, TransactionId transactionIdentifier) { 34 | this.amountOfItems = amountOfItems; 35 | this.itemPrice = itemPrice; 36 | this.transactionIdentifier = transactionIdentifier; 37 | } 38 | 39 | public static Matcher newInstance(long totalItems, int itemPrice, TransactionId transactionIdentifier) { 40 | return new ExecutedTransactionCommandMatcher(totalItems, itemPrice, transactionIdentifier); 41 | } 42 | 43 | @Override 44 | protected boolean doMatches(ExecutedTransactionCommand command) { 45 | return command.getTransactionId().equals(transactionIdentifier) 46 | && command.getAmountOfItems() == amountOfItems 47 | && command.getItemPrice() == itemPrice; 48 | } 49 | 50 | @Override 51 | public void describeTo(Description description) { 52 | description.appendText("ExecutedTransactionCommand with amountOfItems [") 53 | .appendValue(amountOfItems) 54 | .appendText("], itemPrice [") 55 | .appendValue(itemPrice) 56 | .appendText("] for Transaction with identifier [") 57 | .appendValue(transactionIdentifier) 58 | .appendText("]"); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReserveMoneyFromPortfolioCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 20 | import org.axonframework.samples.trader.api.portfolio.cash.ReserveCashCommand; 21 | import org.hamcrest.Description; 22 | import org.hamcrest.Matcher; 23 | 24 | public class ReserveMoneyFromPortfolioCommandMatcher extends BaseCommandMatcher { 25 | 26 | private PortfolioId portfolioIdentifier; 27 | private long amountOfMoneyToReserve; 28 | 29 | private ReserveMoneyFromPortfolioCommandMatcher(PortfolioId portfolioIdentifier, long amountOfMoneyToReserve) { 30 | this.amountOfMoneyToReserve = amountOfMoneyToReserve; 31 | this.portfolioIdentifier = portfolioIdentifier; 32 | } 33 | 34 | public static Matcher newInstance(PortfolioId portfolioIdentifier, long amountOfMoneyToReserve) { 35 | return new ReserveMoneyFromPortfolioCommandMatcher(portfolioIdentifier, amountOfMoneyToReserve); 36 | } 37 | 38 | @Override 39 | protected boolean doMatches(ReserveCashCommand command) { 40 | return command.getPortfolioId().equals(portfolioIdentifier) 41 | && command.getAmountOfMoneyToReserve() == amountOfMoneyToReserve; 42 | } 43 | 44 | @Override 45 | public void describeTo(Description description) { 46 | description.appendText("ReserveCashCommand with amountOfMoneyToReserve [") 47 | .appendValue(amountOfMoneyToReserve) 48 | .appendText("] for Portfolio with identifier [") 49 | .appendValue(portfolioIdentifier) 50 | .appendText("]"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /orders/src/test/java/org/axonframework/samples/trader/orders/command/matchers/ReservedItemsCommandMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.orders.command.matchers; 18 | 19 | import org.axonframework.samples.trader.api.orders.OrderBookId; 20 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 21 | import org.axonframework.samples.trader.api.portfolio.stock.ReserveItemsCommand; 22 | import org.hamcrest.Description; 23 | import org.hamcrest.Matcher; 24 | 25 | public class ReservedItemsCommandMatcher extends BaseCommandMatcher { 26 | 27 | private OrderBookId orderbookIdentifier; 28 | private PortfolioId portfolioIdentifier; 29 | private int amountOfReservedItems; 30 | 31 | private ReservedItemsCommandMatcher(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, 32 | int amountOfReservedItems) { 33 | this.orderbookIdentifier = orderbookIdentifier; 34 | this.portfolioIdentifier = portfolioIdentifier; 35 | this.amountOfReservedItems = amountOfReservedItems; 36 | } 37 | 38 | public static Matcher newInstance(OrderBookId orderbookIdentifier, PortfolioId portfolioIdentifier, 39 | int amountOfReservedItems) { 40 | return new ReservedItemsCommandMatcher(orderbookIdentifier, portfolioIdentifier, amountOfReservedItems); 41 | } 42 | 43 | @Override 44 | protected boolean doMatches(ReserveItemsCommand command) { 45 | return command.getOrderBookId().equals(orderbookIdentifier) 46 | && command.getPortfolioId().equals(portfolioIdentifier) 47 | && amountOfReservedItems == command.getAmountOfItemsToReserve(); 48 | } 49 | 50 | @Override 51 | public void describeTo(Description description) { 52 | description.appendText("ReserveItemsCommand with amountOfReservedItems [") 53 | .appendValue(amountOfReservedItems) 54 | .appendText("] for OrderBook with identifier [") 55 | .appendValue(orderbookIdentifier) 56 | .appendText("] and for Portfolio with identifier [") 57 | .appendValue(portfolioIdentifier) 58 | .appendText("]"); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /orders/src/test/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.rootLogger=WARN,Stdout 18 | 19 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender 20 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout 21 | log4j.appender.Stdout.layout.conversionPattern=%d [%t] %-5p %-30.30c{1} %x - %m%n 22 | 23 | log4j.logger.org.springframework=WARN 24 | log4j.logger.org.axonframework=WARN 25 | log4j.logger.org.axonframework.samples.trader=WARN 26 | -------------------------------------------------------------------------------- /query/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 4.0.0 22 | 23 | 24 | org.axonframework.samples 25 | axon-trader 26 | 2.0-SNAPSHOT 27 | 28 | 29 | axon-trader-query 30 | 31 | 32 | 33 | ${project.groupId} 34 | axon-trader-core-api 35 | ${project.version} 36 | 37 | 38 | ${project.groupId} 39 | axon-trader-users-query 40 | ${project.version} 41 | 42 | 43 | ${project.groupId} 44 | axon-trader-infrastructure 45 | ${project.version} 46 | 47 | 48 | org.axonframework 49 | axon-core 50 | ${axon.version} 51 | 52 | 53 | 54 | org.axonframework 55 | axon-test 56 | ${axon.version} 57 | test 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/company/CompanyEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.company; 18 | 19 | import org.axonframework.config.ProcessingGroup; 20 | import org.axonframework.eventhandling.EventHandler; 21 | import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.stereotype.Service; 24 | 25 | @Service 26 | @ProcessingGroup("queryModel") 27 | public class CompanyEventHandler { 28 | 29 | private final CompanyViewRepository companyRepository; 30 | 31 | @Autowired 32 | public CompanyEventHandler(CompanyViewRepository companyRepository) { 33 | this.companyRepository = companyRepository; 34 | } 35 | 36 | @EventHandler 37 | public void on(CompanyCreatedEvent event) { 38 | CompanyView companyView = new CompanyView(); 39 | 40 | companyView.setIdentifier(event.getCompanyId().getIdentifier()); 41 | companyView.setValue(event.getCompanyValue()); 42 | companyView.setAmountOfShares(event.getAmountOfShares()); 43 | companyView.setTradeStarted(true); 44 | companyView.setName(event.getCompanyName()); 45 | 46 | companyRepository.save(companyView); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/company/CompanyView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.company; 18 | 19 | import org.springframework.data.annotation.Id; 20 | 21 | import javax.persistence.Entity; 22 | 23 | @Entity 24 | public class CompanyView { 25 | 26 | @Id 27 | @javax.persistence.Id 28 | private String identifier; 29 | private String name; 30 | private long value; 31 | private long amountOfShares; 32 | private boolean tradeStarted; 33 | 34 | public long getAmountOfShares() { 35 | return amountOfShares; 36 | } 37 | 38 | public void setAmountOfShares(long amountOfShares) { 39 | this.amountOfShares = amountOfShares; 40 | } 41 | 42 | public String getIdentifier() { 43 | return identifier; 44 | } 45 | 46 | public void setIdentifier(String identifier) { 47 | this.identifier = identifier; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public void setName(String name) { 55 | this.name = name; 56 | } 57 | 58 | public boolean isTradeStarted() { 59 | return tradeStarted; 60 | } 61 | 62 | public void setTradeStarted(boolean tradeStarted) { 63 | this.tradeStarted = tradeStarted; 64 | } 65 | 66 | public long getValue() { 67 | return value; 68 | } 69 | 70 | public void setValue(long value) { 71 | this.value = value; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/company/CompanyViewRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.company; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | public interface CompanyViewRepository extends JpaRepository { 22 | 23 | } 24 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/config/HsqlDbConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.query.config; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.context.annotation.Profile; 6 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 7 | import org.springframework.orm.jpa.JpaTransactionManager; 8 | import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; 9 | import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; 10 | import org.springframework.transaction.PlatformTransactionManager; 11 | 12 | import java.util.Properties; 13 | import javax.persistence.EntityManagerFactory; 14 | import javax.sql.DataSource; 15 | 16 | @Configuration 17 | @Profile("hsqldb") 18 | @EnableJpaRepositories( 19 | basePackages = "org.axonframework.samples.trader.query.*", 20 | transactionManagerRef = "jpaTransactionManager", 21 | entityManagerFactoryRef = "entityManagerFactoryBean" 22 | ) 23 | public class HsqlDbConfiguration { 24 | 25 | @Bean(name = "entityManagerFactoryBean") 26 | public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean(DataSource dataSource) { 27 | final LocalContainerEntityManagerFactoryBean container = new LocalContainerEntityManagerFactoryBean(); 28 | container.setDataSource(dataSource); 29 | container.setPersistenceUnitName("trader"); 30 | 31 | HibernateJpaVendorAdapter adapter = new HibernateJpaVendorAdapter(); 32 | adapter.setGenerateDdl(true); 33 | container.setJpaVendorAdapter(adapter); 34 | 35 | container.setJpaProperties(jpaProps()); 36 | return container; 37 | } 38 | 39 | @Bean(name = "jpaTransactionManager") 40 | public PlatformTransactionManager jpaTransactionManager(EntityManagerFactory emf) { 41 | return new JpaTransactionManager(emf); 42 | } 43 | 44 | private Properties jpaProps() { 45 | final Properties p = new Properties(); 46 | p.setProperty("hibernate.show_sql", "true"); 47 | p.setProperty("hibernate.generate_statistics", "false"); 48 | p.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect"); 49 | return p; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.orderbook; 18 | 19 | import org.springframework.data.annotation.Id; 20 | 21 | import javax.persistence.*; 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * @author Jettro Coenradie 27 | */ 28 | @Entity 29 | public class OrderBookView { 30 | 31 | @Id 32 | @javax.persistence.Id 33 | private String identifier; 34 | private String companyIdentifier; 35 | private String companyName; 36 | @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) 37 | @JoinTable(name = "ORDERENTRY_SELL", joinColumns = @JoinColumn(name = "ORDERBOOK_ID"), inverseJoinColumns = @JoinColumn(name = "ORDER_ID")) 38 | private List sellOrders = new ArrayList<>(); 39 | @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL) 40 | @JoinTable(name = "ORDERENTRY_BUY", joinColumns = @JoinColumn(name = "ORDERBOOK_ID"), inverseJoinColumns = @JoinColumn(name = "ORDER_ID")) 41 | private List buyOrders = new ArrayList<>(); 42 | 43 | public List sellOrders() { 44 | return sellOrders; 45 | } 46 | 47 | public List buyOrders() { 48 | return buyOrders; 49 | } 50 | 51 | public String getIdentifier() { 52 | return identifier; 53 | } 54 | 55 | public void setIdentifier(String identifier) { 56 | this.identifier = identifier; 57 | } 58 | 59 | public String getCompanyIdentifier() { 60 | return companyIdentifier; 61 | } 62 | 63 | public void setCompanyIdentifier(String companyIdentifier) { 64 | this.companyIdentifier = companyIdentifier; 65 | } 66 | 67 | public String getCompanyName() { 68 | return companyName; 69 | } 70 | 71 | public void setCompanyName(String companyName) { 72 | this.companyName = companyName; 73 | } 74 | 75 | public List getBuyOrders() { 76 | return buyOrders; 77 | } 78 | 79 | public void setBuyOrders(List buyOrders) { 80 | this.buyOrders = buyOrders; 81 | } 82 | 83 | public List getSellOrders() { 84 | return sellOrders; 85 | } 86 | 87 | public void setSellOrders(List sellOrders) { 88 | this.sellOrders = sellOrders; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderBookViewRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.orderbook; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | import java.util.List; 22 | 23 | public interface OrderBookViewRepository extends JpaRepository { 24 | 25 | List findByCompanyIdentifier(String companyIdentifier); 26 | } 27 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/orderbook/OrderView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.orderbook; 18 | 19 | import javax.persistence.Entity; 20 | import javax.persistence.GeneratedValue; 21 | 22 | /** 23 | * @author Jettro Coenradie 24 | */ 25 | @Entity 26 | public class OrderView { 27 | 28 | @javax.persistence.Id 29 | @GeneratedValue 30 | private Long jpaId; 31 | 32 | private String identifier; 33 | 34 | private long tradeCount; 35 | private long itemPrice; 36 | private String userId; 37 | private long itemsRemaining; 38 | private String type; 39 | 40 | public String getIdentifier() { 41 | return identifier; 42 | } 43 | 44 | void setIdentifier(String identifier) { 45 | this.identifier = identifier; 46 | } 47 | 48 | public long getItemPrice() { 49 | return itemPrice; 50 | } 51 | 52 | void setItemPrice(long itemPrice) { 53 | this.itemPrice = itemPrice; 54 | } 55 | 56 | public long getItemsRemaining() { 57 | return itemsRemaining; 58 | } 59 | 60 | void setItemsRemaining(long itemsRemaining) { 61 | this.itemsRemaining = itemsRemaining; 62 | } 63 | 64 | public long getTradeCount() { 65 | return tradeCount; 66 | } 67 | 68 | void setTradeCount(long tradeCount) { 69 | this.tradeCount = tradeCount; 70 | } 71 | 72 | public String getUserId() { 73 | return userId; 74 | } 75 | 76 | void setUserId(String userId) { 77 | this.userId = userId; 78 | } 79 | 80 | public String getType() { 81 | return type; 82 | } 83 | 84 | void setType(String type) { 85 | this.type = type; 86 | } 87 | 88 | public Long getJpaId() { 89 | return jpaId; 90 | } 91 | 92 | public void setJpaId(Long jpaId) { 93 | this.jpaId = jpaId; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/portfolio/ItemEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.portfolio; 18 | 19 | import javax.persistence.Entity; 20 | import javax.persistence.GeneratedValue; 21 | 22 | @Entity 23 | public class ItemEntry { 24 | 25 | @javax.persistence.Id 26 | @GeneratedValue 27 | private Long generatedId; 28 | 29 | private String identifier; // OrderBook identifier 30 | private String companyIdentifier; 31 | private String companyName; 32 | private long amount; 33 | 34 | public long getAmount() { 35 | return amount; 36 | } 37 | 38 | public void setAmount(long amount) { 39 | this.amount = amount; 40 | } 41 | 42 | public String getCompanyIdentifier() { 43 | return companyIdentifier; 44 | } 45 | 46 | public void setCompanyIdentifier(String companyIdentifier) { 47 | this.companyIdentifier = companyIdentifier; 48 | } 49 | 50 | public String getCompanyName() { 51 | return companyName; 52 | } 53 | 54 | public void setCompanyName(String companyName) { 55 | this.companyName = companyName; 56 | } 57 | 58 | public String getIdentifier() { 59 | return identifier; 60 | } 61 | 62 | public void setIdentifier(String identifier) { 63 | this.identifier = identifier; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | return "ItemEntry{" + 69 | "amount=" + amount + 70 | ", identifier='" + identifier + '\'' + 71 | ", companyIdentifier='" + companyIdentifier + '\'' + 72 | ", companyName='" + companyName + '\'' + 73 | '}'; 74 | } 75 | 76 | public Long getGeneratedId() { 77 | return generatedId; 78 | } 79 | 80 | public void setGeneratedId(Long generatedId) { 81 | this.generatedId = generatedId; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/portfolio/PortfolioViewRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.portfolio; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | public interface PortfolioViewRepository extends JpaRepository { 22 | 23 | PortfolioView findByUserIdentifier(String userIdentifier); 24 | } 25 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/tradeexecuted/TradeExecutedQueryRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.tradeexecuted; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | import java.util.List; 22 | 23 | public interface TradeExecutedQueryRepository extends JpaRepository { 24 | 25 | List findByOrderBookId(String orderBookId); 26 | } 27 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/tradeexecuted/TradeExecutedView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.tradeexecuted; 18 | 19 | import javax.persistence.Entity; 20 | import javax.persistence.GeneratedValue; 21 | 22 | @Entity 23 | public class TradeExecutedView { 24 | 25 | @javax.persistence.Id 26 | @GeneratedValue 27 | private Long generatedId; 28 | 29 | private long tradeCount; 30 | private long tradePrice; 31 | private String companyName; 32 | private String orderBookId; 33 | 34 | public long getTradeCount() { 35 | return tradeCount; 36 | } 37 | 38 | public void setTradeCount(long tradeCount) { 39 | this.tradeCount = tradeCount; 40 | } 41 | 42 | public String getCompanyName() { 43 | return companyName; 44 | } 45 | 46 | public void setCompanyName(String companyName) { 47 | this.companyName = companyName; 48 | } 49 | 50 | public long getTradePrice() { 51 | return tradePrice; 52 | } 53 | 54 | public void setTradePrice(long tradePrice) { 55 | this.tradePrice = tradePrice; 56 | } 57 | 58 | public String getOrderBookId() { 59 | return orderBookId; 60 | } 61 | 62 | public void setOrderBookId(String orderBookId) { 63 | this.orderBookId = orderBookId; 64 | } 65 | 66 | public Long getGeneratedId() { 67 | return generatedId; 68 | } 69 | 70 | public void setGeneratedId(Long generatedId) { 71 | this.generatedId = generatedId; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/transaction/TransactionState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.transaction; 18 | 19 | public enum TransactionState { 20 | STARTED, CONFIRMED, CANCELLED, EXECUTED, PARTIALLY_EXECUTED 21 | } 22 | -------------------------------------------------------------------------------- /query/src/main/java/org/axonframework/samples/trader/query/transaction/TransactionViewRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.transaction; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | import java.util.List; 22 | 23 | public interface TransactionViewRepository extends JpaRepository { 24 | 25 | List findByPortfolioId(String portfolioId); 26 | } 27 | -------------------------------------------------------------------------------- /query/src/main/resources/META-INF/persistence.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | org.hibernate.jpa.HibernatePersistenceProvider 21 | org.axonframework.samples.trader.query.company.CompanyView 22 | org.axonframework.samples.trader.query.orderbook.OrderView 23 | org.axonframework.samples.trader.query.orderbook.OrderBookView 24 | org.axonframework.samples.trader.query.portfolio.PortfolioView 25 | org.axonframework.samples.trader.query.portfolio.ItemEntry 26 | org.axonframework.samples.trader.query.tradeexecuted.TradeExecutedView 27 | org.axonframework.samples.trader.query.transaction.TransactionView 28 | org.axonframework.samples.trader.query.users.UserView 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /query/src/test/java/org/axonframework/samples/trader/query/company/CompanyEventHandlerTest.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.query.company; 2 | 3 | import org.axonframework.samples.trader.api.company.CompanyCreatedEvent; 4 | import org.axonframework.samples.trader.api.company.CompanyId; 5 | import org.junit.*; 6 | import org.junit.runner.*; 7 | import org.mockito.*; 8 | import org.mockito.runners.*; 9 | 10 | import static org.junit.Assert.*; 11 | import static org.mockito.Mockito.*; 12 | 13 | 14 | @RunWith(MockitoJUnitRunner.class) 15 | public class CompanyEventHandlerTest { 16 | 17 | private final CompanyViewRepository companyViewRepository = mock(CompanyViewRepository.class); 18 | 19 | private CompanyEventHandler testSubject; 20 | 21 | @Before 22 | public void setUp() { 23 | testSubject = new CompanyEventHandler(companyViewRepository); 24 | } 25 | 26 | @Test 27 | public void testOnCompanyCreatedEventACompanyViewIsSaved() { 28 | CompanyId expectedCompanyId = new CompanyId(); 29 | String expectedCompanyName = "companyName"; 30 | int expectedCompanyValue = 1000; 31 | int expectedAmountOfShares = 500; 32 | 33 | CompanyCreatedEvent testEvent = new CompanyCreatedEvent( 34 | expectedCompanyId, expectedCompanyName, expectedCompanyValue, expectedAmountOfShares 35 | ); 36 | 37 | testSubject.on(testEvent); 38 | 39 | ArgumentCaptor companyViewCaptor = ArgumentCaptor.forClass(CompanyView.class); 40 | 41 | verify(companyViewRepository).save(companyViewCaptor.capture()); 42 | 43 | CompanyView result = companyViewCaptor.getValue(); 44 | assertNotNull(result); 45 | assertEquals(expectedCompanyId.getIdentifier(), result.getIdentifier()); 46 | assertEquals(expectedCompanyName, result.getName()); 47 | assertEquals(expectedCompanyValue, result.getValue()); 48 | assertEquals(expectedAmountOfShares, result.getAmountOfShares()); 49 | } 50 | } -------------------------------------------------------------------------------- /query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioEntryMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.portfolio; 18 | 19 | import org.hamcrest.Description; 20 | import org.mockito.*; 21 | 22 | public class PortfolioEntryMatcher extends ArgumentMatcher { 23 | 24 | private final int itemsInPossession; 25 | private final String itemIdentifier; 26 | private final int amountOfItemInPossession; 27 | private final int itemsInReservation; 28 | private final int amountOfItemInReservation; 29 | 30 | public PortfolioEntryMatcher(String itemIdentifier, 31 | int itemsInPossession, 32 | int amountOfItemInPossession, 33 | int itemsInReservation, 34 | int amountOfItemInReservation) { 35 | this.itemsInPossession = itemsInPossession; 36 | this.itemIdentifier = itemIdentifier; 37 | this.amountOfItemInPossession = amountOfItemInPossession; 38 | this.itemsInReservation = itemsInReservation; 39 | this.amountOfItemInReservation = amountOfItemInReservation; 40 | } 41 | 42 | @Override 43 | public boolean matches(Object argument) { 44 | if (!(argument instanceof PortfolioView)) { 45 | return false; 46 | } 47 | PortfolioView portfolioView = (PortfolioView) argument; 48 | 49 | return portfolioView.getItemsInPossession().size() == itemsInPossession 50 | && amountOfItemInPossession == portfolioView.findItemInPossession(itemIdentifier).getAmount() 51 | && portfolioView.getItemsReserved().size() == itemsInReservation 52 | && !(itemsInReservation != 0 && (amountOfItemInReservation != portfolioView 53 | .findReservedItemByIdentifier(itemIdentifier).getAmount())); 54 | } 55 | 56 | @Override 57 | public void describeTo(Description description) { 58 | description.appendText("PortfolioView with itemsInPossession [") 59 | .appendValue(itemsInPossession) 60 | .appendText("] and amountOfItemsInPossession [") 61 | .appendValue(amountOfItemInPossession) 62 | .appendText("] and amountOfItemsInReservation [") 63 | .appendValue(amountOfItemInReservation) 64 | .appendText("] and itemsInReservation [") 65 | .appendValue(itemsInReservation) 66 | .appendText("]"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /query/src/test/java/org/axonframework/samples/trader/query/portfolio/PortfolioViewTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.portfolio; 18 | 19 | import org.junit.*; 20 | 21 | import static org.junit.Assert.*; 22 | 23 | public class PortfolioViewTest { 24 | 25 | private static final long AMOUNT_ITEMS = 100; 26 | private static final long AMOUNT_RESERVED = 40; 27 | private static final int AMOUNT_SELL = 10; 28 | private static final String ORDER_BOOK_ID = "item1"; 29 | private static final int AMOUNT_OF_MONEY = 1000; 30 | private static final int RESERVED_AMOUNT_OF_MONEY = 200; 31 | 32 | @Test 33 | public void testRemovingItems() { 34 | PortfolioView portfolio = createDefaultPortfolio(); 35 | 36 | portfolio.removeReservedItem(ORDER_BOOK_ID, AMOUNT_SELL); 37 | portfolio.removeItemsInPossession(ORDER_BOOK_ID, AMOUNT_SELL); 38 | 39 | assertEquals(AMOUNT_RESERVED - AMOUNT_SELL, portfolio.findReservedItemByIdentifier(ORDER_BOOK_ID).getAmount()); 40 | assertEquals(AMOUNT_ITEMS - AMOUNT_SELL, portfolio.findItemInPossession(ORDER_BOOK_ID).getAmount()); 41 | } 42 | 43 | @Test 44 | public void testObtainAvailableItems() { 45 | PortfolioView portfolio = createDefaultPortfolio(); 46 | 47 | assertEquals(AMOUNT_ITEMS - AMOUNT_RESERVED, portfolio.obtainAmountOfAvailableItemsFor(ORDER_BOOK_ID)); 48 | } 49 | 50 | @Test 51 | public void testObtainBudget() { 52 | PortfolioView portfolio = createDefaultPortfolio(); 53 | assertEquals(AMOUNT_OF_MONEY - RESERVED_AMOUNT_OF_MONEY, portfolio.obtainMoneyToSpend()); 54 | } 55 | 56 | private PortfolioView createDefaultPortfolio() { 57 | PortfolioView portfolio = new PortfolioView(); 58 | 59 | portfolio.addItemInPossession(createItem(AMOUNT_ITEMS)); 60 | portfolio.addReservedItem(createItem(AMOUNT_RESERVED)); 61 | portfolio.setAmountOfMoney(AMOUNT_OF_MONEY); 62 | portfolio.setReservedAmountOfMoney(RESERVED_AMOUNT_OF_MONEY); 63 | return portfolio; 64 | } 65 | 66 | private ItemEntry createItem(long amount) { 67 | ItemEntry item1InPossession = new ItemEntry(); 68 | item1InPossession.setIdentifier("item1"); 69 | item1InPossession.setAmount(amount); 70 | item1InPossession.setCompanyIdentifier("company1"); 71 | item1InPossession.setCompanyName("Company One"); 72 | return item1InPossession; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /trade-engine/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 22 | axon-trader 23 | org.axonframework.samples 24 | 2.0-SNAPSHOT 25 | 26 | 4.0.0 27 | 28 | axon-trader-trade-engine 29 | 30 | 31 | 32 | 33 | ${project.groupId} 34 | axon-trader-core-api 35 | ${project.version} 36 | 37 | 38 | 39 | 40 | org.springframework 41 | spring-beans 42 | 43 | 44 | org.springframework 45 | spring-context 46 | 47 | 48 | 49 | org.axonframework 50 | axon-core 51 | ${axon.version} 52 | 53 | 54 | 55 | 56 | org.axonframework 57 | axon-test 58 | ${axon.version} 59 | test 60 | 61 | 62 | -------------------------------------------------------------------------------- /trade-engine/src/main/java/org/axonframework/samples/trader/tradeengine/command/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.tradeengine.command; 18 | 19 | import org.axonframework.commandhandling.model.EntityId; 20 | import org.axonframework.eventsourcing.EventSourcingHandler; 21 | import org.axonframework.samples.trader.api.orders.OrderId; 22 | import org.axonframework.samples.trader.api.orders.trades.TradeExecutedEvent; 23 | import org.axonframework.samples.trader.api.orders.transaction.TransactionId; 24 | import org.axonframework.samples.trader.api.portfolio.PortfolioId; 25 | 26 | public class Order { 27 | 28 | @EntityId 29 | private OrderId orderId; 30 | private TransactionId transactionId; 31 | private final long itemPrice; 32 | private final long tradeCount; 33 | private final PortfolioId portfolioId; 34 | private long itemsRemaining; 35 | 36 | public Order(OrderId orderId, TransactionId transactionId, long itemPrice, long tradeCount, PortfolioId portfolioId) { 37 | this.orderId = orderId; 38 | this.transactionId = transactionId; 39 | this.itemPrice = itemPrice; 40 | this.tradeCount = tradeCount; 41 | this.itemsRemaining = tradeCount; 42 | this.portfolioId = portfolioId; 43 | } 44 | 45 | public long getItemPrice() { 46 | return itemPrice; 47 | } 48 | 49 | public long getTradeCount() { 50 | return tradeCount; 51 | } 52 | 53 | public PortfolioId getPortfolioId() { 54 | return portfolioId; 55 | } 56 | 57 | public long getItemsRemaining() { 58 | return itemsRemaining; 59 | } 60 | 61 | public OrderId getOrderId() { 62 | return orderId; 63 | } 64 | 65 | public TransactionId getTransactionId() { 66 | return transactionId; 67 | } 68 | 69 | @EventSourcingHandler 70 | protected void onTradeExecuted(TradeExecutedEvent event) { 71 | if (orderId.equals(event.getBuyOrderId()) || orderId.equals(event.getSellOrderId())) { 72 | recordTraded(event.getTradeCount()); 73 | } 74 | } 75 | 76 | private void recordTraded(long tradeCount) { 77 | this.itemsRemaining -= tradeCount; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /users-query/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 4.0.0 22 | 23 | 24 | org.axonframework.samples 25 | axon-trader 26 | 2.0-SNAPSHOT 27 | 28 | 29 | axon-trader-users-query 30 | 31 | 32 | 33 | 34 | ${project.groupId} 35 | axon-trader-core-api 36 | ${project.version} 37 | 38 | 39 | 40 | 41 | org.springframework 42 | spring-beans 43 | 44 | 45 | 46 | org.springframework.data 47 | spring-data-jpa 48 | ${springdata.jpa.version} 49 | 50 | 51 | 52 | org.hibernate 53 | hibernate-entitymanager 54 | ${hibernate.em.version} 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /users-query/src/main/java/org/axonframework/samples/trader/query/users/UserEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.users; 18 | 19 | import org.axonframework.config.ProcessingGroup; 20 | import org.axonframework.eventhandling.EventHandler; 21 | import org.axonframework.samples.trader.api.users.UserCreatedEvent; 22 | import org.springframework.beans.factory.annotation.Autowired; 23 | import org.springframework.stereotype.Service; 24 | 25 | @Service 26 | @ProcessingGroup("userQueryModel") 27 | public class UserEventHandler { 28 | 29 | private final UserViewRepository userRepository; 30 | 31 | @Autowired 32 | public UserEventHandler(UserViewRepository userRepository) { 33 | this.userRepository = userRepository; 34 | } 35 | 36 | @EventHandler 37 | public void on(UserCreatedEvent event) { 38 | UserView userView = new UserView(); 39 | 40 | userView.setIdentifier(event.getUserId().getIdentifier()); 41 | userView.setName(event.getName()); 42 | userView.setUsername(event.getUsername()); 43 | userView.setPassword(event.getPassword()); 44 | 45 | userRepository.save(userView); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /users-query/src/main/java/org/axonframework/samples/trader/query/users/UserView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.users; 18 | 19 | import org.axonframework.samples.trader.api.users.UserAccount; 20 | import org.springframework.data.annotation.Id; 21 | 22 | import java.io.Serializable; 23 | import javax.persistence.Entity; 24 | 25 | @Entity 26 | public class UserView implements UserAccount, Serializable { 27 | 28 | @Id 29 | @javax.persistence.Id 30 | private String identifier; 31 | private String name; 32 | private String username; 33 | private String password; 34 | 35 | public String getIdentifier() { 36 | return identifier; 37 | } 38 | 39 | public void setIdentifier(String identifier) { 40 | this.identifier = identifier; 41 | } 42 | 43 | public String getName() { 44 | return name; 45 | } 46 | 47 | public void setName(String name) { 48 | this.name = name; 49 | } 50 | 51 | public String getUsername() { 52 | return username; 53 | } 54 | 55 | public void setUsername(String username) { 56 | this.username = username; 57 | } 58 | 59 | @Override 60 | public String getUserId() { 61 | return this.identifier; 62 | } 63 | 64 | @Override 65 | public String getUserName() { 66 | return this.username; 67 | } 68 | 69 | @Override 70 | public String getFullName() { 71 | return this.name; 72 | } 73 | 74 | public void setPassword(String password) { 75 | this.password = password; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /users-query/src/main/java/org/axonframework/samples/trader/query/users/UserViewRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.query.users; 18 | 19 | import org.springframework.data.jpa.repository.JpaRepository; 20 | 21 | public interface UserViewRepository extends JpaRepository { 22 | 23 | UserView findByUsername(String username); 24 | 25 | UserView findByIdentifier(String identifier); 26 | } 27 | -------------------------------------------------------------------------------- /users-query/src/test/java/org/axonframework/samples/trader/query/users/UserEventHandlerTest.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.query.users; 2 | 3 | import org.axonframework.samples.trader.api.users.UserCreatedEvent; 4 | import org.axonframework.samples.trader.api.users.UserId; 5 | import org.junit.*; 6 | import org.junit.runner.*; 7 | import org.mockito.*; 8 | import org.mockito.runners.*; 9 | 10 | import static org.junit.Assert.*; 11 | import static org.mockito.Mockito.*; 12 | 13 | @RunWith(MockitoJUnitRunner.class) 14 | public class UserEventHandlerTest { 15 | 16 | private final UserViewRepository userViewRepository = mock(UserViewRepository.class); 17 | 18 | private UserEventHandler testSubject; 19 | 20 | @Before 21 | public void setUp() { 22 | testSubject = new UserEventHandler(userViewRepository); 23 | } 24 | 25 | @Test 26 | public void testOnUserCreatedEventAnUserViewIsSaved() { 27 | UserId expectedUserId = new UserId(); 28 | String expectedName = "name"; 29 | String expectedUserName = "userName"; 30 | 31 | UserCreatedEvent testEvent = new UserCreatedEvent(expectedUserId, expectedName, expectedUserName, "password"); 32 | 33 | testSubject.on(testEvent); 34 | 35 | ArgumentCaptor userViewCaptor = ArgumentCaptor.forClass(UserView.class); 36 | 37 | verify(userViewRepository).save(userViewCaptor.capture()); 38 | 39 | UserView result = userViewCaptor.getValue(); 40 | assertNotNull(result); 41 | assertEquals(expectedUserId.getIdentifier(), result.getUserId()); 42 | assertEquals(expectedName, result.getName()); 43 | assertEquals(expectedUserName, result.getUserName()); 44 | } 45 | } -------------------------------------------------------------------------------- /users/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 21 | 4.0.0 22 | 23 | 24 | org.axonframework.samples 25 | axon-trader 26 | 2.0-SNAPSHOT 27 | 28 | 29 | axon-trader-users 30 | 31 | 32 | 33 | 34 | ${project.groupId} 35 | axon-trader-core-api 36 | ${project.version} 37 | 38 | 39 | ${project.groupId} 40 | axon-trader-users-query 41 | ${project.version} 42 | 43 | 44 | 45 | 46 | org.springframework 47 | spring-beans 48 | 49 | 50 | 51 | 52 | org.axonframework 53 | axon-test 54 | ${axon.version} 55 | test 56 | 57 | 58 | -------------------------------------------------------------------------------- /users/src/main/java/org/axonframework/samples/trader/users/command/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.users.command; 18 | 19 | import org.axonframework.commandhandling.CommandHandler; 20 | import org.axonframework.commandhandling.model.AggregateIdentifier; 21 | import org.axonframework.eventsourcing.EventSourcingHandler; 22 | import org.axonframework.samples.trader.api.users.*; 23 | import org.axonframework.samples.trader.users.util.DigestUtils; 24 | import org.axonframework.spring.stereotype.Aggregate; 25 | 26 | import static org.axonframework.commandhandling.model.AggregateLifecycle.apply; 27 | 28 | @Aggregate 29 | public class User { 30 | 31 | @AggregateIdentifier 32 | private UserId userId; 33 | private String passwordHash; 34 | 35 | public User() { 36 | // Required by Axon Framework 37 | } 38 | 39 | @CommandHandler 40 | public User(CreateUserCommand cmd) { 41 | apply(new UserCreatedEvent(cmd.getUserId(), 42 | cmd.getName(), 43 | cmd.getUsername(), 44 | hashOf(cmd.getPassword().toCharArray()))); 45 | } 46 | 47 | @CommandHandler 48 | public boolean handle(AuthenticateUserCommand cmd) { 49 | boolean success = this.passwordHash.equals(hashOf(cmd.getPassword())); 50 | if (success) { 51 | apply(new UserAuthenticatedEvent(userId)); 52 | } 53 | return success; 54 | } 55 | 56 | @EventSourcingHandler 57 | public void on(UserCreatedEvent event) { 58 | this.userId = event.getUserId(); 59 | this.passwordHash = event.getPassword(); 60 | } 61 | 62 | private String hashOf(char[] password) { 63 | return DigestUtils.sha1(String.valueOf(password)); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /users/src/test/java/org/axonframework/samples/trader/app/command/user/UserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.app.command.user; 18 | 19 | import org.axonframework.samples.trader.api.users.*; 20 | import org.axonframework.samples.trader.users.command.User; 21 | import org.axonframework.samples.trader.users.util.DigestUtils; 22 | import org.axonframework.test.aggregate.AggregateTestFixture; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | 26 | public class UserTest { 27 | 28 | private AggregateTestFixture fixture; 29 | 30 | private UserId userId = new UserId(); 31 | 32 | private UserCreatedEvent userCreatedEvent; 33 | 34 | @Before 35 | public void setUp() { 36 | fixture = new AggregateTestFixture<>(User.class); 37 | 38 | userCreatedEvent = new UserCreatedEvent(userId, "Buyer 1", "buyer1", DigestUtils.sha1("buyer1")); 39 | } 40 | 41 | @Test 42 | public void testHandleCreateUser() { 43 | fixture.givenNoPriorActivity() 44 | .when(new CreateUserCommand(userId, "Buyer 1", "buyer1", "buyer1")) 45 | .expectEvents(userCreatedEvent); 46 | } 47 | 48 | @Test 49 | public void testHandleAuthenticateUser() { 50 | fixture.given(userCreatedEvent) 51 | .when(new AuthenticateUserCommand(userId, "buyer1", "buyer1".toCharArray())) 52 | .expectEvents(new UserAuthenticatedEvent(userId)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/config/AppConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2016. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.config; 18 | 19 | import org.axonframework.samples.trader.infra.config.CQRSInfrastructureConfig; 20 | import org.axonframework.samples.trader.infra.config.PersistenceInfrastructureConfig; 21 | import org.axonframework.samples.trader.listener.config.ExternalListenersConfig; 22 | import org.axonframework.samples.trader.orders.config.OrderConfig; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.context.annotation.Import; 25 | import org.springframework.context.annotation.ImportResource; 26 | 27 | @Configuration 28 | @Import({ 29 | CQRSInfrastructureConfig.class, 30 | PersistenceInfrastructureConfig.class, 31 | OrderConfig.class, 32 | ExternalListenersConfig.class 33 | }) 34 | @ImportResource("classpath:META-INF/spring/security-context.xml") 35 | public class AppConfig { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.init; 18 | 19 | import java.util.Set; 20 | 21 | /** 22 | *

Initializes the repository with a number of users, companiess and order books

23 | * 24 | * @author Jettro Coenradie 25 | */ 26 | public interface DBInit { 27 | 28 | void createItems(); 29 | 30 | void depositMoneyToPortfolio(String portfolioIdentifier, long amountOfMoney); 31 | 32 | Set obtainCollectionNames(); 33 | 34 | DataResults obtainCollection(String collectionName, int numItems, int start); 35 | 36 | void createItemsIfNoUsersExist(); 37 | } 38 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInitException.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.webui.init; 2 | 3 | /** 4 | * Exception thrown when having a problem during data initialization 5 | */ 6 | public class DBInitException extends RuntimeException { 7 | public DBInitException(String message) { 8 | super(message); 9 | } 10 | 11 | public DBInitException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DataResults.java: -------------------------------------------------------------------------------- 1 | package org.axonframework.samples.trader.webui.init; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | /** 7 | * Created by jettrocoenradie on 19/08/14. 8 | */ 9 | public class DataResults { 10 | private int totalItems; 11 | private List items; 12 | 13 | public DataResults(int totalItems, List items) { 14 | this.totalItems = totalItems; 15 | this.items = items; 16 | } 17 | 18 | public int getTotalItems() { 19 | return totalItems; 20 | } 21 | 22 | public List getItems() { 23 | return items; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/init/RunDBInitializerWhenNeeded.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.init; 18 | 19 | import org.springframework.context.ApplicationListener; 20 | import org.springframework.context.event.ContextRefreshedEvent; 21 | import org.springframework.stereotype.Component; 22 | 23 | /** 24 | *

Special class used to initialize the database when starting the container. The database is only initialized 25 | * when the collection "UserView" is not yet available.

26 | *

We need to check for the display name of the application context since we by default have two using spring-mvc 27 | * the way we do.

28 | * 29 | * @author Jettro Coenradie 30 | */ 31 | @Component 32 | public class RunDBInitializerWhenNeeded implements ApplicationListener { 33 | @Override 34 | public void onApplicationEvent(ContextRefreshedEvent event) { 35 | DBInit init = event.getApplicationContext().getBean(DBInit.class); 36 | 37 | if ("Root WebApplicationContext".equals(event.getApplicationContext().getDisplayName())) { 38 | init.createItemsIfNoUsersExist(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/order/AbstractOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.order; 18 | 19 | import javax.validation.constraints.Min; 20 | 21 | /** 22 | * @author Jettro Coenradie 23 | */ 24 | public class AbstractOrder { 25 | 26 | private String companyId; 27 | private String companyName; 28 | 29 | @Min(1) 30 | private long tradeCount; 31 | 32 | @Min(0) 33 | private int itemPrice; 34 | 35 | public AbstractOrder() { 36 | } 37 | 38 | public AbstractOrder(int itemPrice, long tradeCount, String companyId, String companyName) { 39 | this.itemPrice = itemPrice; 40 | this.tradeCount = tradeCount; 41 | this.companyId = companyId; 42 | this.companyName = companyName; 43 | } 44 | 45 | public int getItemPrice() { 46 | return itemPrice; 47 | } 48 | 49 | public void setItemPrice(int itemPrice) { 50 | this.itemPrice = itemPrice; 51 | } 52 | 53 | public long getTradeCount() { 54 | return tradeCount; 55 | } 56 | 57 | public void setTradeCount(long tradeCount) { 58 | this.tradeCount = tradeCount; 59 | } 60 | 61 | public String getCompanyId() { 62 | return companyId; 63 | } 64 | 65 | public void setCompanyId(String companyId) { 66 | this.companyId = companyId; 67 | } 68 | 69 | public String getCompanyName() { 70 | return companyName; 71 | } 72 | 73 | public void setCompanyName(String companyName) { 74 | this.companyName = companyName; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/order/BuyOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.order; 18 | 19 | /** 20 | * @author Jettro Coenradie 21 | */ 22 | public class BuyOrder extends AbstractOrder { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/order/CreateOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.order; 18 | 19 | /** 20 | * @author Jettro Coenradie 21 | */ 22 | public class CreateOrder extends AbstractOrder { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/order/OrderBookController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.order; 18 | 19 | import org.axonframework.samples.trader.query.orderbook.OrderBookView; 20 | import org.axonframework.samples.trader.query.orderbook.OrderBookViewRepository; 21 | import org.springframework.beans.factory.annotation.Autowired; 22 | import org.springframework.beans.factory.annotation.Value; 23 | import org.springframework.stereotype.Controller; 24 | import org.springframework.ui.Model; 25 | import org.springframework.ui.ModelMap; 26 | import org.springframework.web.bind.annotation.PathVariable; 27 | import org.springframework.web.bind.annotation.RequestMapping; 28 | import org.springframework.web.bind.annotation.RequestMethod; 29 | 30 | /** 31 | * @author Jettro Coenradie 32 | */ 33 | @Controller 34 | @RequestMapping("/orderbook") 35 | public class OrderBookController { 36 | 37 | private OrderBookViewRepository repository; 38 | private String externalServerUrl; 39 | 40 | @Autowired 41 | public OrderBookController(OrderBookViewRepository repository) { 42 | this.repository = repository; 43 | } 44 | 45 | @RequestMapping(method = RequestMethod.GET) 46 | public String get(Model model) { 47 | model.addAttribute("items", repository.findAll()); 48 | return "orderbook/list"; 49 | } 50 | 51 | @RequestMapping(value = "socket", method = RequestMethod.GET) 52 | public String getSocket(ModelMap modelMap) { 53 | modelMap.addAttribute("externalServerurl", externalServerUrl); 54 | return "orderbook/socket"; 55 | } 56 | 57 | @RequestMapping(value = "/{identifier}", method = RequestMethod.GET) 58 | public String getOrders(@PathVariable String identifier, Model model) { 59 | OrderBookView orderBook = repository.findOne(identifier); 60 | model.addAttribute("orderBook", orderBook); 61 | return "orderbook/orders"; 62 | } 63 | 64 | @Value("${serverUrlEventBus}") 65 | public void setExternalServerUrl(String externalServerUrl) { 66 | this.externalServerUrl = externalServerUrl; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/order/SellOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.order; 18 | 19 | /** 20 | * @author Jettro Coenradie 21 | */ 22 | public class SellOrder extends AbstractOrder { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/security/UserController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.security; 18 | 19 | import org.axonframework.samples.trader.query.users.UserViewRepository; 20 | import org.springframework.beans.factory.annotation.Autowired; 21 | import org.springframework.stereotype.Controller; 22 | import org.springframework.ui.Model; 23 | import org.springframework.web.bind.annotation.PathVariable; 24 | import org.springframework.web.bind.annotation.RequestMapping; 25 | import org.springframework.web.bind.annotation.RequestMethod; 26 | 27 | /** 28 | * @author Jettro Coenradie 29 | */ 30 | @Controller 31 | @RequestMapping("/user") 32 | public class UserController { 33 | 34 | private UserViewRepository userRepository; 35 | 36 | @Autowired 37 | public UserController(UserViewRepository userRepository) { 38 | this.userRepository = userRepository; 39 | } 40 | 41 | @RequestMapping(method = RequestMethod.GET) 42 | public String showUsers(Model model) { 43 | model.addAttribute("items", userRepository.findAll()); 44 | return "user/list"; 45 | } 46 | 47 | @RequestMapping(value = "/{identifier}", method = RequestMethod.GET) 48 | public String detail(@PathVariable("identifier") String userIdentifier, Model model) { 49 | model.addAttribute("item", userRepository.findByIdentifier(userIdentifier)); 50 | return "user/detail"; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /web-ui/src/main/java/org/axonframework/samples/trader/webui/util/SecurityUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package org.axonframework.samples.trader.webui.util; 18 | 19 | import org.axonframework.samples.trader.api.users.UserAccount; 20 | import org.springframework.security.core.context.SecurityContextHolder; 21 | 22 | /** 23 | * @author Jettro Coenradie 24 | */ 25 | public class SecurityUtil { 26 | 27 | public static String obtainLoggedinUsername() { 28 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 29 | if (principal instanceof UserAccount) { 30 | return ((UserAccount) principal).getUserName(); 31 | } else { 32 | throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal"); 33 | } 34 | } 35 | 36 | public static String obtainLoggedinUserIdentifier() { 37 | Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); 38 | if (principal instanceof UserAccount) { 39 | return ((UserAccount) principal).getUserId(); 40 | } else { 41 | throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal"); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /web-ui/src/main/resources/META-INF/spring/security-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /web-ui/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | 17 | log4j.appender.Stdout=org.apache.log4j.ConsoleAppender 18 | log4j.appender.Stdout.layout=org.apache.log4j.PatternLayout 19 | log4j.appender.Stdout.layout.conversionPattern=%-5p - %-10.10t - %-26.26c{1} - %m\n 20 | 21 | log4j.rootLogger=WARN,Stdout 22 | 23 | log4j.logger.org.axonframework=WARN 24 | log4j.logger.org.axonframework.samples=INFO 25 | log4j.logger.org.axonframework.saga=INFO 26 | log4j.logger.org.axonframework.samples.trader.app.command.trading=DEBUG 27 | 28 | log4j.logger.org.springframework=WARN 29 | log4j.logger.org.springframework.security=WARN 30 | log4j.logger.org.springframework.web.filter=WARN 31 | log4j.logger.org.springframework.validation.Validator=WARN 32 | log4j.logger.org.springframework.validation=WARN -------------------------------------------------------------------------------- /web-ui/src/main/resources/messages.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | order.tradeCount=Amount of items to Trade 17 | tradeCount=Amount of items to Trade 18 | 19 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/decorators.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 | 20 | 21 | /* 22 | 23 | 24 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/dispatcher-servlet.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | /WEB-INF/messages/validation 51 | /WEB-INF/messages/fields 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/admin/portfolio/detail.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Users 21 | 22 | 23 | 24 | Profile detail : 25 | Here you can add money and items to the portfolio. 26 |

Money

27 | 28 |
29 |
30 |
31 |
Available
32 |
33 |
34 |
35 |
Reserved
36 |
37 |
38 |
39 |
40 |
/money/"> 41 | 42 | 43 |
44 |
45 |
46 |

Items

47 | 48 |
49 |
50 |

In possession

51 |
    52 | 53 |
  • 54 |
    55 |
56 |

Reserved

57 |
    58 | 59 |
  • 60 |
    61 |
62 |
63 |
64 |
/item/"> 65 | 71 | 72 | 73 |
74 |
75 |
76 | 77 | 78 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/admin/portfolio/list.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Users 21 | 22 | 29 | 30 | 31 | All portfolios 32 | Choose the portfolio to watch the details for 33 |

You can sort the table by clicking on the headers.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 53 | 54 | 55 | 56 | 57 |
NameMoney availableItems available 
49 | 50 |   51 | 52 | details
58 | 59 | 60 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/company/buy.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@include file="../include.jsp" %> 5 | <%-- 6 | ~ Copyright (c) 2010-2012. Axon Framework 7 | ~ 8 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 9 | ~ you may not use this file except in compliance with the License. 10 | ~ You may obtain a copy of the License at 11 | ~ 12 | ~ http://www.apache.org/licenses/LICENSE-2.0 13 | ~ 14 | ~ Unless required by applicable law or agreed to in writing, software 15 | ~ distributed under the License is distributed on an "AS IS" BASIS, 16 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ~ See the License for the specific language governing permissions and 18 | ~ limitations under the License. 19 | --%> 20 | Buy order for : 21 | Enter items to buy and for how much 22 | 23 | 30 | 31 |
32 |
33 |
34 |

Cents available of which cents 35 | reserved.

36 |
37 |
38 |
39 | 40 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/company/form-include.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 4 | <%@include file="../include.jsp" %> 5 | <%-- 6 | ~ Copyright (c) 2010-2012. Axon Framework 7 | ~ 8 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 9 | ~ you may not use this file except in compliance with the License. 10 | ~ You may obtain a copy of the License at 11 | ~ 12 | ~ http://www.apache.org/licenses/LICENSE-2.0 13 | ~ 14 | ~ Unless required by applicable law or agreed to in writing, software 15 | ~ distributed under the License is distributed on an "AS IS" BASIS, 16 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | ~ See the License for the specific language governing permissions and 18 | ~ limitations under the License. 19 | --%> 20 |
21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 44 | 45 |
:
:
40 | 41 | 42 | Cancel 43 |
46 |
47 |
48 |
-------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/company/list.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Companies 21 | 22 | 29 | 30 | 31 | All stock items 32 | Choose the stock to start trading with 33 | 34 | 38 | 39 | 40 |

You can sort the table by clicking on the headers.

41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 |
NameValue# Shares 
details
61 | 62 | 63 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/company/sell.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 3 | <%@include file="../include.jsp" %> 4 | <%-- 5 | ~ Copyright (c) 2010-2012. Axon Framework 6 | ~ 7 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 8 | ~ you may not use this file except in compliance with the License. 9 | ~ You may obtain a copy of the License at 10 | ~ 11 | ~ http://www.apache.org/licenses/LICENSE-2.0 12 | ~ 13 | ~ Unless required by applicable law or agreed to in writing, software 14 | ~ distributed under the License is distributed on an "AS IS" BASIS, 15 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | ~ See the License for the specific language governing permissions and 17 | ~ limitations under the License. 18 | --%> 19 | 20 | Sell order for : 21 | Enter items to sell and for how much 22 | 23 | 30 | 31 |
32 |
33 |
34 |

Items available of which 35 | reserved.

36 |
37 |
38 |
39 | 40 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/data/collections.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | MongoDB collections 21 | 22 | 23 | MongoDB collections 24 | Available collections in this Mongo instance. 25 | 26 | 30 | 31 | 32 |

The collections

33 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/data/info.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Initialize MongoDB 21 | 22 | 23 | MongoDB information 24 | Here you see informative messages. 25 |

26 | 27 | 28 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/include.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | 3 | <%-- 4 | ~ Copyright (c) 2010-2012. Axon Framework 5 | ~ 6 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 7 | ~ you may not use this file except in compliance with the License. 8 | ~ You may obtain a copy of the License at 9 | ~ 10 | ~ http://www.apache.org/licenses/LICENSE-2.0 11 | ~ 12 | ~ Unless required by applicable law or agreed to in writing, software 13 | ~ distributed under the License is distributed on an "AS IS" BASIS, 14 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | ~ See the License for the specific language governing permissions and 16 | ~ limitations under the License. 17 | --%> 18 | 19 | 20 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Welcome to the axon trader 21 | 22 | 23 | Welcome 24 | Have fun playing with the trader 25 | 26 |
27 |

The trader

28 | 29 |

Welcome to the proof of concept of Axon Trader. This sample is created to showcase axon capabilities. Next to 30 | that we wanted to create a cool app with a nice front-end that we can really use as a showcase.

31 | 32 |

If you are logged in, you can go to your dashboard.

33 | 34 |

Dashboard »

35 |
36 |
37 | 38 |

There are a few things implemented. You can choose the company to trade stock items for. Before you can 39 | use them you need to login.

40 | 41 |
42 |
43 |

Available Credentials

44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
UserPassword
buyer1buyer1
buyer2buyer2
buyer3buyer3
buyer4buyer4
buyer5buyer5
buyer6buyer6
78 |
79 |
80 |

Check the stocks

81 | 82 |

If you have logged in, you can go to the companies

83 | 84 |

To the items »

85 |
86 |
87 |

Executed trades

88 | 89 |

Trace all executed trades using the sockjs connection.

90 | 91 |

Executed trades »

92 |
93 |
94 | 95 | 96 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/orderbook/list.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | 3 | <%-- 4 | ~ Copyright (c) 2010-2012. Axon Framework 5 | ~ 6 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 7 | ~ you may not use this file except in compliance with the License. 8 | ~ You may obtain a copy of the License at 9 | ~ 10 | ~ http://www.apache.org/licenses/LICENSE-2.0 11 | ~ 12 | ~ Unless required by applicable law or agreed to in writing, software 13 | ~ distributed under the License is distributed on an "AS IS" BASIS, 14 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | ~ See the License for the specific language governing permissions and 16 | ~ limitations under the License. 17 | --%> 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |
Nameactions
orders
-------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/orderbook/orders.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | 3 | <%-- 4 | ~ Copyright (c) 2010-2012. Axon Framework 5 | ~ 6 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 7 | ~ you may not use this file except in compliance with the License. 8 | ~ You may obtain a copy of the License at 9 | ~ 10 | ~ http://www.apache.org/licenses/LICENSE-2.0 11 | ~ 12 | ~ Unless required by applicable law or agreed to in writing, software 13 | ~ distributed under the License is distributed on an "AS IS" BASIS, 14 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | ~ See the License for the specific language governing permissions and 16 | ~ limitations under the License. 17 | --%> 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
TypeCountPriceRemainingUser
-------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/orderbook/socket.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | <%-- 3 | ~ Copyright (c) 2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 |
29 |
30 | Connection Status:  31 |
Not connected
32 |
33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
Company#itemsPrice
45 |
46 | 47 | <%-- The script for sockjs --%> 48 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/user/detail.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Users 21 | 22 | 29 | 30 | 31 | Users detail : 32 | Here you can add money and items to the portfolio. 33 | 34 | 35 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/jsp/user/list.jsp: -------------------------------------------------------------------------------- 1 | <%@include file="../include.jsp" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 | 19 | 20 | Users 21 | 22 | 29 | 30 | 31 | All users 32 | Choose the user to watch the details for 33 |

You can sort the table by clicking on the headers.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 |
Nameusername 
details
52 | 53 | 54 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/messages/fields.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | order.tradeCount=Amount of items to Trade 17 | order.price=Price to trade 18 | 19 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/WEB-INF/messages/validation.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2010-2012. Axon Framework 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | javax.validation.constraints.Min.message=must be greater than or equal to {value} 17 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AxonFramework/Axon-trader/149c80498aef30baa45000fa241362e2fc0e2001/web-ui/src/main/webapp/favicon.ico -------------------------------------------------------------------------------- /web-ui/src/main/webapp/index.html: -------------------------------------------------------------------------------- 1 | 16 | seems to be necessary but should not show up 17 | 18 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %> 2 | <%-- 3 | ~ Copyright (c) 2010-2012. Axon Framework 4 | ~ 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); 6 | ~ you may not use this file except in compliance with the License. 7 | ~ You may obtain a copy of the License at 8 | ~ 9 | ~ http://www.apache.org/licenses/LICENSE-2.0 10 | ~ 11 | ~ Unless required by applicable law or agreed to in writing, software 12 | ~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~ See the License for the specific language governing permissions and 15 | ~ limitations under the License. 16 | --%> 17 | 18 |

You need to login to access this part of the site. Please provided your username and password

19 | 20 | 21 |
22 |

23 | Your login attempt was not successful, try again. 24 |

25 | 26 |

27 | Reason: . 28 |

29 |
30 |
31 | 32 |
33 |
34 | Login to get access 35 |
36 | 37 | 38 |
39 | 41 |
42 |
43 |
44 | 45 | 46 |
47 | 48 |
49 |
50 |
51 | 55 |
56 |
57 | 58 | 59 |
60 |
61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | -------------------------------------------------------------------------------- /web-ui/src/main/webapp/style/main.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010-2012. Axon Framework 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Override some defaults */ 18 | html, body { 19 | background-color: #eee; 20 | } 21 | 22 | body { 23 | padding-top: 40px; /* 40px to make the container go all the way to the bottom of the topbar */ 24 | } 25 | 26 | .container > footer p { 27 | text-align: center; /* center align it with the container */ 28 | } 29 | 30 | .container { 31 | width: 820px; /* downsize our container to make the content feel a bit tighter and more cohesive. NOTE: this removes two full columns from the grid, meaning you only go to 14 columns and not 16. */ 32 | } 33 | 34 | /* The white background content wrapper */ 35 | .content { 36 | background-color: #fff; 37 | padding: 20px; 38 | margin: 0 -20px; /* negative indent the amount of the padding to maintain the grid system */ 39 | -webkit-border-radius: 0 0 6px 6px; 40 | -moz-border-radius: 0 0 6px 6px; 41 | border-radius: 0 0 6px 6px; 42 | -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, .15); 43 | -moz-box-shadow: 0 1px 2px rgba(0, 0, 0, .15); 44 | box-shadow: 0 1px 2px rgba(0, 0, 0, .15); 45 | } 46 | 47 | /* Page header tweaks */ 48 | .page-header { 49 | background-color: #f5f5f5; 50 | padding: 20px 20px 10px; 51 | margin: -20px -20px 20px; 52 | } 53 | 54 | p.credentials { 55 | color: #f5f5f5; 56 | } 57 | 58 | .topbar .btn { 59 | border: 0; 60 | } --------------------------------------------------------------------------------