Permalink
Browse files

Initial part in showing the dashboard for a user

  • Loading branch information...
jettro committed Nov 11, 2011
1 parent 36ecb6c commit 883f1195c3fcf8c60460b0c337df4671198a8b68
Showing with 473 additions and 60 deletions.
  1. +6 −0 app/pom.xml
  2. +46 −0 ...in/java/org/axonframework/samples/trader/app/command/trading/PortfolioManagementUserListener.java
  3. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/command/user/UserCommandHandler.java
  4. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyListener.java
  5. +1 −1 ...ples/trader/app/query/company/repositories/{CompanyRepository.java → CompanyQueryRepository.java}
  6. +9 −9 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListener.java
  7. +1 −1 ...rader/app/query/orderbook/repositories/{OrderBookRepository.java → OrderBookQueryRepository.java}
  8. +61 −0 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioEntry.java
  9. +79 −0 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioListener.java
  10. +26 −0 ...a/org/axonframework/samples/trader/app/query/portfolio/repositories/PortfolioQueryRepository.java
  11. +1 −1 ...ery/tradeexecuted/repositories/{TradeExecutedRepository.java → TradeExecutedQueryRepository.java}
  12. +3 −3 app/src/main/java/org/axonframework/samples/trader/app/query/user/UserListener.java
  13. +1 −1 ...ework/samples/trader/app/query/user/repositories/{UserRepository.java → UserQueryRepository.java}
  14. +67 −0 ...ava/org/axonframework/samples/trader/app/command/trading/PortfolioManagementUserListenerTest.java
  15. +3 −3 app/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java
  16. +1 −1 ...axonframework/samples/trader/app/query/company/repositories/CompanyRepositoryIntegrationTest.java
  17. +6 −6 ...t/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListenerIntegrationTest.java
  18. 0 app/src/{main → test}/resources/log4j.properties
  19. +1 −1 pom.xml
  20. +12 −12 web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java
  21. +51 −0 web-ui/src/main/java/org/axonframework/samples/trader/webui/dashboard/DashboardController.java
  22. +1 −0 ...src/main/java/org/axonframework/samples/trader/webui/init/CloudApplicationContextInitializer.java
  23. +15 −3 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java
  24. +9 −0 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/MongoController.java
  25. +3 −3 web-ui/src/main/java/org/axonframework/samples/trader/webui/order/OrderBookController.java
  26. +3 −3 web-ui/src/main/java/org/axonframework/samples/trader/webui/security/UserController.java
  27. +10 −1 web-ui/src/main/java/org/axonframework/samples/trader/webui/util/SecurityUtil.java
  28. +2 −2 web-ui/src/main/resources/log4j.properties
  29. +46 −0 web-ui/src/main/webapp/WEB-INF/jsp/dashboard/index.jsp
  30. +3 −3 web-ui/src/main/webapp/WEB-INF/jsp/index.jsp
View
@@ -119,6 +119,12 @@
<version>1.8.5</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-all</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.command.trading;
+
+import org.axonframework.commandhandling.CommandBus;
+import org.axonframework.eventhandling.annotation.EventHandler;
+import org.axonframework.samples.trader.app.api.portfolio.CreatePortfolioCommand;
+import org.axonframework.samples.trader.app.api.user.UserCreatedEvent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Jettro Coenradie
+ */
+@Component
+public class PortfolioManagementUserListener {
+ private final static Logger logger = LoggerFactory.getLogger(PortfolioManagementUserListener.class);
+ private CommandBus commandBus;
+
+ @EventHandler
+ public void createNewPortfolioWhenUserIsCreated(UserCreatedEvent event) {
+ logger.debug("About to dispatch a new command to create a Portfolio for the new user {}", event.getUserIdentifier());
+ CreatePortfolioCommand command = new CreatePortfolioCommand(event.getUserIdentifier());
+ commandBus.dispatch(command);
+ }
+
+ @Autowired
+ public void setCommandBus(CommandBus commandBus) {
+ this.commandBus = commandBus;
+ }
+}
@@ -23,7 +23,7 @@
import org.axonframework.samples.trader.app.api.user.AuthenticateUserCommand;
import org.axonframework.samples.trader.app.api.user.CreateUserCommand;
import org.axonframework.samples.trader.app.api.user.UserAccount;
-import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
@@ -35,7 +35,7 @@
public class UserCommandHandler {
private Repository<User> repository;
- private UserRepository userQueryRepository;
+ private UserQueryRepository userQueryRepository;
@CommandHandler
public AggregateIdentifier handleCreateUser(CreateUserCommand command) {
@@ -68,7 +68,7 @@ public void setRepository(Repository<User> userRepository) {
}
@Autowired
- public void setUserRepository(UserRepository userRepository) {
+ public void setUserRepository(UserQueryRepository userRepository) {
this.userQueryRepository = userRepository;
}
}
@@ -17,7 +17,7 @@
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.samples.trader.app.api.company.CompanyCreatedEvent;
-import org.axonframework.samples.trader.app.query.company.repositories.CompanyRepository;
+import org.axonframework.samples.trader.app.query.company.repositories.CompanyQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -27,7 +27,7 @@
@Component
public class CompanyListener {
- private CompanyRepository companyRepository;
+ private CompanyQueryRepository companyRepository;
@EventHandler
public void handleCompanyCreatedEvent(CompanyCreatedEvent event) {
@@ -42,7 +42,7 @@ public void handleCompanyCreatedEvent(CompanyCreatedEvent event) {
}
@Autowired
- public void setCompanyRepository(CompanyRepository companyRepository) {
+ public void setCompanyRepository(CompanyQueryRepository companyRepository) {
this.companyRepository = companyRepository;
}
}
@@ -21,6 +21,6 @@
/**
* @author Jettro Coenradie
*/
-public interface CompanyRepository extends PagingAndSortingRepository<CompanyEntry, String> {
+public interface CompanyQueryRepository extends PagingAndSortingRepository<CompanyEntry, String> {
}
@@ -19,10 +19,10 @@
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.samples.trader.app.api.order.*;
import org.axonframework.samples.trader.app.query.company.CompanyEntry;
-import org.axonframework.samples.trader.app.query.company.repositories.CompanyRepository;
-import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookRepository;
+import org.axonframework.samples.trader.app.query.company.repositories.CompanyQueryRepository;
+import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookQueryRepository;
import org.axonframework.samples.trader.app.query.tradeexecuted.TradeExecutedEntry;
-import org.axonframework.samples.trader.app.query.tradeexecuted.repositories.TradeExecutedRepository;
+import org.axonframework.samples.trader.app.query.tradeexecuted.repositories.TradeExecutedQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -34,9 +34,9 @@
private static final String BUY = "Buy";
private static final String SELL = "Sell";
- private OrderBookRepository orderBookRepository;
- private CompanyRepository companyRepository;
- private TradeExecutedRepository tradeExecutedRepository;
+ private OrderBookQueryRepository orderBookRepository;
+ private CompanyQueryRepository companyRepository;
+ private TradeExecutedQueryRepository tradeExecutedRepository;
@EventHandler
@@ -117,17 +117,17 @@ private OrderEntry createPlacedOrder(AbstractOrderPlacedEvent event, String type
}
@Autowired
- public void setOrderBookRepository(OrderBookRepository orderBookRepository) {
+ public void setOrderBookRepository(OrderBookQueryRepository orderBookRepository) {
this.orderBookRepository = orderBookRepository;
}
@Autowired
- public void setCompanyRepository(CompanyRepository companyRepository) {
+ public void setCompanyRepository(CompanyQueryRepository companyRepository) {
this.companyRepository = companyRepository;
}
@Autowired
- public void setTradeExecutedRepository(TradeExecutedRepository tradeExecutedRepository) {
+ public void setTradeExecutedRepository(TradeExecutedQueryRepository tradeExecutedRepository) {
this.tradeExecutedRepository = tradeExecutedRepository;
}
}
@@ -23,6 +23,6 @@
/**
* @author Jettro Coenradie
*/
-public interface OrderBookRepository extends PagingAndSortingRepository<OrderBookEntry, String> {
+public interface OrderBookQueryRepository extends PagingAndSortingRepository<OrderBookEntry, String> {
List<OrderBookEntry> findByCompanyIdentifier(String companyIdentifier);
}
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.query.portfolio;
+
+import org.springframework.data.annotation.Id;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class PortfolioEntry {
+ @Id
+ private String identifier;
+ private String userIdentifier;
+ private long amountOfMoney;
+ private long reservedAmountOfMoney;
+
+ public String getUserIdentifier() {
+ return userIdentifier;
+ }
+
+ public void setUserIdentifier(String userIdentifier) {
+ this.userIdentifier = userIdentifier;
+ }
+
+ public long getAmountOfMoney() {
+ return amountOfMoney;
+ }
+
+ public void setAmountOfMoney(long amountOfMoney) {
+ this.amountOfMoney = amountOfMoney;
+ }
+
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ public void setIdentifier(String identifier) {
+ this.identifier = identifier;
+ }
+
+ public long getReservedAmountOfMoney() {
+ return reservedAmountOfMoney;
+ }
+
+ public void setReservedAmountOfMoney(long reservedAmountOfMoney) {
+ this.reservedAmountOfMoney = reservedAmountOfMoney;
+ }
+}
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.query.portfolio;
+
+import org.axonframework.eventhandling.annotation.EventHandler;
+import org.axonframework.samples.trader.app.api.portfolio.PortfolioCreatedEvent;
+import org.axonframework.samples.trader.app.api.portfolio.money.MoneyAddedToPortfolioEvent;
+import org.axonframework.samples.trader.app.api.portfolio.money.MoneyReservedFromPortfolioEvent;
+import org.axonframework.samples.trader.app.api.portfolio.money.PaymentMadeFromPortfolioEvent;
+import org.axonframework.samples.trader.app.query.portfolio.repositories.PortfolioQueryRepository;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author Jettro Coenradie
+ */
+@Component
+public class PortfolioListener {
+ private final static Logger logger = LoggerFactory.getLogger(PortfolioListener.class);
+
+ private PortfolioQueryRepository portfolioRepository;
+
+ @EventHandler
+ public void handleEvent(PortfolioCreatedEvent event) {
+ logger.debug("About to handle the PortfolioCreatedEvent for user with identifier {}",
+ event.getUserIdentifier().asString());
+
+ PortfolioEntry portfolioEntry = new PortfolioEntry();
+ portfolioEntry.setIdentifier(event.getPortfolioIdentifier().asString());
+ portfolioEntry.setUserIdentifier(event.getUserIdentifier().asString());
+ portfolioEntry.setAmountOfMoney(0);
+ portfolioEntry.setReservedAmountOfMoney(0);
+
+ portfolioRepository.save(portfolioEntry);
+ }
+
+ @EventHandler
+ public void handleEvent(MoneyAddedToPortfolioEvent event) {
+ PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString());
+ portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() + event.getMoneyAddedInCents());
+ portfolioRepository.save(portfolioEntry);
+ }
+
+ @EventHandler
+ public void handleEvent(PaymentMadeFromPortfolioEvent event) {
+ PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString());
+ portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() - event.getAmountPaidInCents());
+ portfolioRepository.save(portfolioEntry);
+ }
+
+ @EventHandler
+ public void handleEvent(MoneyReservedFromPortfolioEvent event) {
+ PortfolioEntry portfolioEntry = portfolioRepository.findOne(event.getPortfolioIdentifier().asString());
+ portfolioEntry.setReservedAmountOfMoney(portfolioEntry.getReservedAmountOfMoney() + event.getAmountToReserve());
+ portfolioEntry.setAmountOfMoney(portfolioEntry.getAmountOfMoney() - event.getAmountToReserve());
+ portfolioRepository.save(portfolioEntry);
+ }
+
+
+ @Autowired
+ public void setPortfolioRepository(PortfolioQueryRepository portfolioRepository) {
+ this.portfolioRepository = portfolioRepository;
+ }
+}
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.app.query.portfolio.repositories;
+
+import org.axonframework.samples.trader.app.query.portfolio.PortfolioEntry;
+import org.springframework.data.repository.PagingAndSortingRepository;
+
+/**
+ * @author Jettro Coenradie
+ */
+public interface PortfolioQueryRepository extends PagingAndSortingRepository<PortfolioEntry, String> {
+ PortfolioEntry findByUserIdentifier(String userIdentifier);
+}
@@ -23,6 +23,6 @@
/**
* @author Jettro Coenradie
*/
-public interface TradeExecutedRepository extends PagingAndSortingRepository<TradeExecutedEntry, String> {
+public interface TradeExecutedQueryRepository extends PagingAndSortingRepository<TradeExecutedEntry, String> {
List<TradeExecutedEntry> findByOrderBookIdentifier(String orderBookIdentifier);
}
@@ -17,7 +17,7 @@
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.samples.trader.app.api.user.UserCreatedEvent;
-import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -26,7 +26,7 @@
*/
@Component
public class UserListener {
- private UserRepository userRepository;
+ private UserQueryRepository userRepository;
@EventHandler
public void handleUserCreated(UserCreatedEvent event) {
@@ -40,7 +40,7 @@ public void handleUserCreated(UserCreatedEvent event) {
}
@Autowired
- public void setUserRepository(UserRepository userRepository) {
+ public void setUserRepository(UserQueryRepository userRepository) {
this.userRepository = userRepository;
}
}
@@ -21,6 +21,6 @@
/**
* @author Jettro Coenradie
*/
-public interface UserRepository extends PagingAndSortingRepository<UserEntry, String> {
+public interface UserQueryRepository extends PagingAndSortingRepository<UserEntry, String> {
UserEntry findByUsername(String username);
}
Oops, something went wrong.

0 comments on commit 883f119

Please sign in to comment.