Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial part in showing the dashboard for a user

  • Loading branch information...
commit 883f1195c3fcf8c60460b0c337df4671198a8b68 1 parent 36ecb6c
@jettro jettro authored
Showing with 473 additions and 60 deletions.
  1. +6 −0 app/pom.xml
  2. +46 −0 app/src/main/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  ...k/samples/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  ...les/trader/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 ...c/main/java/org/axonframework/samples/trader/app/query/portfolio/repositories/PortfolioQueryRepository.java
  11. +1 −1  ...pp/query/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  ...nframework/samples/trader/app/query/user/repositories/{UserRepository.java → UserQueryRepository.java}
  14. +67 −0 ...src/test/java/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  .../java/org/axonframework/samples/trader/app/query/company/repositories/CompanyRepositoryIntegrationTest.java
  17. +6 −6 app/src/test/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  web-ui/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
6 app/pom.xml
@@ -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>
View
46 app/src/main/java/org/axonframework/samples/trader/app/command/trading/PortfolioManagementUserListener.java
@@ -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;
+ }
+}
View
6 app/src/main/java/org/axonframework/samples/trader/app/command/user/UserCommandHandler.java
@@ -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;
}
}
View
6 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyListener.java
@@ -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;
}
}
View
2  ...query/company/repositories/CompanyRepository.java → .../company/repositories/CompanyQueryRepository.java
@@ -21,6 +21,6 @@
/**
* @author Jettro Coenradie
*/
-public interface CompanyRepository extends PagingAndSortingRepository<CompanyEntry, String> {
+public interface CompanyQueryRepository extends PagingAndSortingRepository<CompanyEntry, String> {
}
View
18 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListener.java
@@ -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;
}
}
View
2  ...y/orderbook/repositories/OrderBookRepository.java → ...erbook/repositories/OrderBookQueryRepository.java
@@ -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);
}
View
61 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioEntry.java
@@ -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;
+ }
+}
View
79 app/src/main/java/org/axonframework/samples/trader/app/query/portfolio/PortfolioListener.java
@@ -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;
+ }
+}
View
26 ...ain/java/org/axonframework/samples/trader/app/query/portfolio/repositories/PortfolioQueryRepository.java
@@ -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);
+}
View
2  ...xecuted/repositories/TradeExecutedRepository.java → ...ed/repositories/TradeExecutedQueryRepository.java
@@ -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);
}
View
6 app/src/main/java/org/axonframework/samples/trader/app/query/user/UserListener.java
@@ -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;
}
}
View
2  ...r/app/query/user/repositories/UserRepository.java → .../query/user/repositories/UserQueryRepository.java
@@ -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);
}
View
67 .../test/java/org/axonframework/samples/trader/app/command/trading/PortfolioManagementUserListenerTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.domain.AggregateIdentifier;
+import org.axonframework.domain.UUIDAggregateIdentifier;
+import org.axonframework.samples.trader.app.api.portfolio.CreatePortfolioCommand;
+import org.axonframework.samples.trader.app.api.user.UserCreatedEvent;
+import org.axonframework.test.utils.DomainEventUtils;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+/**
+ * @author Jettro Coenradie
+ */
+public class PortfolioManagementUserListenerTest {
+
+ @Test
+ public void checkPortfolioCreationAfterUserCreated() {
+ CommandBus commandBus = mock(CommandBus.class);
+ PortfolioManagementUserListener listener = new PortfolioManagementUserListener();
+ listener.setCommandBus(commandBus);
+
+ UserCreatedEvent event = new UserCreatedEvent("Test", "testuser", "testpassword");
+ AggregateIdentifier userIdentifier = new UUIDAggregateIdentifier();
+ DomainEventUtils.setAggregateIdentifier(event, userIdentifier);
+
+ listener.createNewPortfolioWhenUserIsCreated(event);
+
+ verify(commandBus).dispatch(argThat(new UserIdentifierMatcher(userIdentifier.asString())));
+ }
+
+ private class UserIdentifierMatcher extends ArgumentMatcher {
+ private String identifier;
+
+ private UserIdentifierMatcher(String identifier) {
+ this.identifier = identifier;
+ }
+
+ @Override
+ public boolean matches(Object argument) {
+ if (!(argument instanceof CreatePortfolioCommand)) {
+ return false;
+ }
+ CreatePortfolioCommand createPortfolioCommand = (CreatePortfolioCommand) argument;
+ return createPortfolioCommand.getUserIdentifier().asString().equals(identifier);
+ }
+ }
+}
View
6 app/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java
@@ -20,7 +20,7 @@
import org.axonframework.samples.trader.app.api.user.UserAuthenticatedEvent;
import org.axonframework.samples.trader.app.api.user.UserCreatedEvent;
import org.axonframework.samples.trader.app.query.user.UserEntry;
-import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserQueryRepository;
import org.axonframework.test.FixtureConfiguration;
import org.axonframework.test.Fixtures;
import org.junit.Before;
@@ -36,11 +36,11 @@
public class UserCommandHandlerTest {
private FixtureConfiguration fixture;
- private UserRepository userQueryRepository;
+ private UserQueryRepository userQueryRepository;
@Before
public void setUp() {
- userQueryRepository = mock(UserRepository.class);
+ userQueryRepository = mock(UserQueryRepository.class);
fixture = Fixtures.newGivenWhenThenFixture();
UserCommandHandler commandHandler = new UserCommandHandler();
View
2  ...va/org/axonframework/samples/trader/app/query/company/repositories/CompanyRepositoryIntegrationTest.java
@@ -30,7 +30,7 @@
@ContextConfiguration({"classpath:META-INF/spring/persistence-infrastructure-context.xml"})
public class CompanyRepositoryIntegrationTest {
@Autowired
- private CompanyRepository companyRepository;
+ private CompanyQueryRepository companyRepository;
@Test
public void storeCompanyInRepository() {
View
12 ...src/test/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListenerIntegrationTest.java
@@ -22,10 +22,10 @@
import org.axonframework.samples.trader.app.api.order.SellOrderPlacedEvent;
import org.axonframework.samples.trader.app.api.order.TradeExecutedEvent;
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.axonframework.test.utils.DomainEventUtils;
import org.junit.Before;
import org.junit.Test;
@@ -47,12 +47,12 @@
private OrderBookListener orderBookListener;
@Autowired
- private OrderBookRepository orderBookRepository;
+ private OrderBookQueryRepository orderBookRepository;
@Autowired
- private TradeExecutedRepository tradeExecutedRepository;
+ private TradeExecutedQueryRepository tradeExecutedRepository;
@Autowired
- private CompanyRepository companyRepository;
+ private CompanyQueryRepository companyRepository;
@Autowired
private MongoTemplate mongoTemplate;
View
0  app/src/main/resources/log4j.properties → app/src/test/resources/log4j.properties
File renamed without changes
View
2  pom.xml
@@ -27,7 +27,7 @@
<properties>
<slf4j.version>1.6.1</slf4j.version>
- <spring.version>3.1.0.M2</spring.version>
+ <spring.version>3.1.0.RC1</spring.version>
<spring.security.version>3.1.0.RC3</spring.security.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<axon.version>2.0-SNAPSHOT</axon.version>
View
24 web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java
@@ -21,13 +21,13 @@
import org.axonframework.samples.trader.app.api.order.CreateBuyOrderCommand;
import org.axonframework.samples.trader.app.api.order.CreateSellOrderCommand;
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.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.app.query.orderbook.OrderBookEntry;
-import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookRepository;
+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.axonframework.samples.trader.app.query.user.UserEntry;
-import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserQueryRepository;
import org.axonframework.samples.trader.webui.order.AbstractOrder;
import org.axonframework.samples.trader.webui.order.BuyOrder;
import org.axonframework.samples.trader.webui.order.SellOrder;
@@ -51,18 +51,18 @@
@RequestMapping("/company")
public class CompanyController {
- private CompanyRepository companyRepository;
- private OrderBookRepository orderBookRepository;
- private UserRepository userRepository;
- private TradeExecutedRepository tradeExecutedRepository;
+ private CompanyQueryRepository companyRepository;
+ private OrderBookQueryRepository orderBookRepository;
+ private UserQueryRepository userRepository;
+ private TradeExecutedQueryRepository tradeExecutedRepository;
private CommandBus commandBus;
@Autowired
- public CompanyController(CompanyRepository companyRepository,
+ public CompanyController(CompanyQueryRepository companyRepository,
CommandBus commandBus,
- UserRepository userRepository,
- OrderBookRepository orderBookRepository,
- TradeExecutedRepository tradeExecutedRepository) {
+ UserQueryRepository userRepository,
+ OrderBookQueryRepository orderBookRepository,
+ TradeExecutedQueryRepository tradeExecutedRepository) {
this.companyRepository = companyRepository;
this.commandBus = commandBus;
this.userRepository = userRepository;
View
51 web-ui/src/main/java/org/axonframework/samples/trader/webui/dashboard/DashboardController.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2011. Gridshore
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.axonframework.samples.trader.webui.dashboard;
+
+import org.axonframework.samples.trader.app.query.portfolio.PortfolioEntry;
+import org.axonframework.samples.trader.app.query.portfolio.repositories.PortfolioQueryRepository;
+import org.axonframework.samples.trader.webui.util.SecurityUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * @author Jettro Coenradie
+ */
+@Controller
+@RequestMapping("/dashboard")
+public class DashboardController {
+ private final static Logger logger = LoggerFactory.getLogger(DashboardController.class);
+ private PortfolioQueryRepository portfolioRepository;
+
+ @RequestMapping(method = RequestMethod.GET)
+ public String show(Model model) {
+ String identifier = SecurityUtil.obtainLoggedinUserIdentifier();
+ logger.debug("Requested to obtain the portfolio for the user: {}", identifier);
+ PortfolioEntry portfolio = portfolioRepository.findByUserIdentifier(identifier);
+ model.addAttribute("portfolio", portfolio);
+ return "dashboard/index";
+ }
+
+ @Autowired
+ public void setPortfolioRepository(PortfolioQueryRepository portfolioRepository) {
+ this.portfolioRepository = portfolioRepository;
+ }
+}
View
1  web-ui/src/main/java/org/axonframework/samples/trader/webui/init/CloudApplicationContextInitializer.java
@@ -40,6 +40,7 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
logger.info("Cloud API: {}", env.getCloudApiUri());
applicationContext.getEnvironment().setActiveProfiles("cloud");
} else {
+ logger.info("Activating the default profile within the application context.");
applicationContext.getEnvironment().setActiveProfiles("default");
}
}
View
18 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java
@@ -20,14 +20,17 @@
import org.axonframework.commandhandling.callbacks.NoOpCallback;
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.domain.StringAggregateIdentifier;
+import org.axonframework.domain.UUIDAggregateIdentifier;
import org.axonframework.eventstore.mongo.MongoEventStore;
import org.axonframework.samples.trader.app.api.company.CreateCompanyCommand;
import org.axonframework.samples.trader.app.api.order.CreateOrderBookCommand;
+import org.axonframework.samples.trader.app.api.portfolio.money.AddMoneyToPortfolioCommand;
import org.axonframework.samples.trader.app.api.user.CreateUserCommand;
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.company.repositories.CompanyQueryRepository;
import org.axonframework.samples.trader.app.query.orderbook.OrderBookEntry;
import org.axonframework.samples.trader.app.query.orderbook.OrderEntry;
+import org.axonframework.samples.trader.app.query.portfolio.PortfolioEntry;
import org.axonframework.samples.trader.app.query.tradeexecuted.TradeExecutedEntry;
import org.axonframework.samples.trader.app.query.user.UserEntry;
import org.springframework.beans.factory.annotation.Autowired;
@@ -44,14 +47,14 @@
public class DBInit {
private CommandBus commandBus;
- private CompanyRepository companyRepository;
+ private CompanyQueryRepository companyRepository;
private org.axonframework.eventstore.mongo.MongoTemplate systemAxonMongo;
private MongoEventStore eventStore;
private org.springframework.data.mongodb.core.MongoTemplate mongoTemplate;
@Autowired
public DBInit(CommandBus commandBus,
- CompanyRepository companyRepository,
+ CompanyQueryRepository companyRepository,
org.axonframework.eventstore.mongo.MongoTemplate systemMongo,
MongoEventStore eventStore,
org.springframework.data.mongodb.core.MongoTemplate mongoTemplate) {
@@ -80,6 +83,8 @@ public void createItems() {
mongoTemplate.dropCollection(OrderEntry.class);
mongoTemplate.dropCollection(CompanyEntry.class);
mongoTemplate.dropCollection(TradeExecutedEntry.class);
+ mongoTemplate.dropCollection(PortfolioEntry.class);
+// mongoTemplate.dropCollection(TransactionEntry.class);
AggregateIdentifier userIdentifier = createuser("Buyer One", "buyer1");
createuser("Buyer two", "buyer2");
@@ -91,6 +96,13 @@ public void createItems() {
eventStore.ensureIndexes();
}
+ public void addMoneyToPortfolio(String portfolioIdentifier, long amountOfMoney) {
+ AddMoneyToPortfolioCommand command =
+ new AddMoneyToPortfolioCommand(new UUIDAggregateIdentifier(portfolioIdentifier), amountOfMoney);
+ commandBus.dispatch(command);
+ }
+
+
private void createCompanies(AggregateIdentifier userIdentifier) {
CreateCompanyCommand command = new CreateCompanyCommand(userIdentifier, "Philips", 1000, 10000);
commandBus.dispatch(command);
View
9 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/MongoController.java
@@ -84,4 +84,13 @@ public String initializeMongo(Model model) {
model.addAttribute("info", "Mongo database is initialized.");
return "data/info";
}
+
+ @RequestMapping(value = "/portfolio/money/{identifier}/{amount}")
+ public String addMoneyToPortfolio(@PathVariable("identifier") String portfolioIdentifier,
+ @PathVariable("amount") long amount,
+ Model model) {
+ dbInit.addMoneyToPortfolio(portfolioIdentifier, amount);
+ model.addAttribute("info", "Added money to the portfolio.");
+ return "data/info";
+ }
}
View
6 web-ui/src/main/java/org/axonframework/samples/trader/webui/order/OrderBookController.java
@@ -16,7 +16,7 @@
package org.axonframework.samples.trader.webui.order;
import org.axonframework.samples.trader.app.query.orderbook.OrderBookEntry;
-import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookRepository;
+import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookQueryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -30,10 +30,10 @@
@Controller
@RequestMapping("/orderbook")
public class OrderBookController {
- private OrderBookRepository repository;
+ private OrderBookQueryRepository repository;
@Autowired
- public OrderBookController(OrderBookRepository repository) {
+ public OrderBookController(OrderBookQueryRepository repository) {
this.repository = repository;
}
View
6 web-ui/src/main/java/org/axonframework/samples/trader/webui/security/UserController.java
@@ -15,7 +15,7 @@
package org.axonframework.samples.trader.webui.security;
-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.Controller;
import org.springframework.ui.Model;
@@ -28,10 +28,10 @@
@Controller
@RequestMapping("/user")
public class UserController {
- private UserRepository userRepository;
+ private UserQueryRepository userRepository;
@Autowired
- public UserController(UserRepository userRepository) {
+ public UserController(UserQueryRepository userRepository) {
this.userRepository = userRepository;
}
View
11 web-ui/src/main/java/org/axonframework/samples/trader/webui/util/SecurityUtil.java
@@ -17,7 +17,6 @@
import org.axonframework.samples.trader.app.api.user.UserAccount;
import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
/**
* @author Jettro Coenradie
@@ -31,4 +30,14 @@ public static String obtainLoggedinUsername() {
throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal");
}
}
+
+ public static String obtainLoggedinUserIdentifier() {
+ Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
+ if (principal instanceof UserAccount) {
+ return ((UserAccount) principal).getUserId();
+ } else {
+ throw new IllegalStateException("Wrong security implementation, expecting a UserAccount as principal");
+ }
+ }
+
}
View
4 web-ui/src/main/resources/log4j.properties
@@ -21,10 +21,10 @@ log4j.rootLogger=WARN,Stdout
log4j.logger.org.axonframework=WARN
log4j.logger.org.axonframework.examples=DEBUG
-log4j.logger.org.axonframework.sample=DEBUG
+log4j.logger.org.axonframework.samples=DEBUG
+
log4j.logger.org.springframework=INFO
log4j.logger.org.springframework.security=INFO
log4j.logger.org.springframework.web.filter=INFO
-
log4j.logger.org.springframework.validation.Validator=DEBUG
log4j.logger.org.springframework.validation=DEBUG
View
46 web-ui/src/main/webapp/WEB-INF/jsp/dashboard/index.jsp
@@ -0,0 +1,46 @@
+<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
+<%--
+~ 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.
+--%>
+<html>
+<head>
+ <title>This is your dashboard</title>
+</head>
+<body>
+<content tag="title">Dashboard</content>
+<content tag="tagline">Your overview of everything you have and want to know</content>
+<div class="row">
+ <div class="span7">
+ <h2>Portfolio</h2>
+
+ <p>Here you see what you have and what is reserved.</p>
+
+ <div class="row">
+ <div class="span3">Amount of money</div>
+ <div class="span4"><c:out value="${portfolio.amountOfMoney}"/></div>
+ </div>
+ <div class="row">
+ <div class="span3">Reserved money</div>
+ <div class="span4"><c:out value="${portfolio.reservedAmountOfMoney}"/></div>
+ </div>
+ </div>
+ <div class="span7">
+ <h2>Transactions</h2>
+
+ <p>Here you see your current transactions.</p>
+ </div>
+</div>
+
+</body>
+</html>
View
6 web-ui/src/main/webapp/WEB-INF/jsp/index.jsp
@@ -25,11 +25,11 @@
<h1>The trader</h1>
<p>Welcome to the proof of concept of Axon Trader. This sample is created to showcase axon capabilities. Next to
- that
- we wanted to create a cool app with a nice front-end that we can really use as a showcase.</p>
+ that we wanted to create a cool app with a nice front-end that we can really use as a showcase.</p>
+ <p>If you are logged in, you can go to your dashboard.</p>
- <p><a class="btn primary large" href="${ctx}/company">Learn more &raquo;</a></p>
+ <p><a class="btn primary large" href="${ctx}/dashboard">Dashboard &raquo;</a></p>
</div>
</content>
Please sign in to comment.
Something went wrong with that request. Please try again.