Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored the query side of mongo to use the spring data stuff

  • Loading branch information...
commit 704a76bc987f2a96db5c4757cea863ff13d62e90 1 parent 47eef8c
@jettro jettro authored
Showing with 370 additions and 477 deletions.
  1. +1 −6 README
  2. +4 −0 app/src/main/java/org/axonframework/samples/trader/app/api/order/AbstractOrderPlacedEvent.java
  3. +2 −2 app/src/main/java/org/axonframework/samples/trader/app/api/order/CreateBuyOrderCommand.java
  4. +1 −1  app/src/main/java/org/axonframework/samples/trader/app/command/user/UserCommandHandler.java
  5. +7 −12 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyEntry.java
  6. +12 −14 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyListener.java
  7. +0 −83 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyRepositoryMongo.java
  8. +5 −8 .../main/java/org/axonframework/samples/trader/app/query/company/{ → repositories}/CompanyRepository.java
  9. +3 −0  app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookEntry.java
  10. +55 −73 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListener.java
  11. +0 −100 app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookRepositoryMongo.java
  12. +7 −10 ...n/java/org/axonframework/samples/trader/app/query/orderbook/{ → repositories}/OrderBookRepository.java
  13. +0 −61 app/src/main/java/org/axonframework/samples/trader/app/query/tradeexecuted/TradeExecutedRepositoryMongo.java
  14. +7 −4 ...rg/axonframework/samples/trader/app/query/tradeexecuted/{ → repositories}/TradeExecutedRepository.java
  15. +0 −69 app/src/main/java/org/axonframework/samples/trader/app/query/user/UserRepositoryMongo.java
  16. +5 −6 app/src/main/java/org/axonframework/samples/trader/app/query/user/{ → repositories}/UserRepository.java
  17. +2 −0  app/src/main/resources/META-INF/spring/persistence-infrastructure-context.xml
  18. +5 −5 app/src/test/java/org/axonframework/samples/trader/app/command/user/UserCommandHandlerTest.java
  19. +46 −0 .../java/org/axonframework/samples/trader/app/query/company/repositories/CompanyRepositoryIntegrationTest.java
  20. +186 −0 app/src/test/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListenerIntegrationTest.java
  21. +15 −15 web-ui/src/main/java/org/axonframework/samples/trader/webui/companies/CompanyController.java
  22. +2 −3 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java
  23. +3 −3 web-ui/src/main/java/org/axonframework/samples/trader/webui/order/OrderBookController.java
  24. +2 −2 web-ui/src/main/java/org/axonframework/samples/trader/webui/security/UserController.java
View
7 README
@@ -1,5 +1,5 @@
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, mongodb and maven or gradle.
+have chosen to create a Trader application. All you need to run it is java, mongodb and maven.
Initial setup
-------------
@@ -27,11 +27,6 @@ Running the sample
> mvn jetty:run-war
- Browse to : http://localhost:8080/
-* gradle
-- Make sure you have your mongo instance running
-- Step into the main folder of the project
-> gradle jettyRun
-
Advanced configuration
----------------------
To write when done :-)
View
4 ...rc/main/java/org/axonframework/samples/trader/app/api/order/AbstractOrderPlacedEvent.java
@@ -35,6 +35,10 @@ protected AbstractOrderPlacedEvent(AggregateIdentifier orderId, long tradeCount,
this.userId = userId;
}
+ public AggregateIdentifier orderBookIdentifier() {
+ return getAggregateIdentifier();
+ }
+
public AggregateIdentifier getOrderId() {
return orderId;
}
View
4 app/src/main/java/org/axonframework/samples/trader/app/api/order/CreateBuyOrderCommand.java
@@ -22,7 +22,7 @@
*/
public class CreateBuyOrderCommand extends AbstractOrderCommand {
- public CreateBuyOrderCommand(AggregateIdentifier userId, AggregateIdentifier companyId, long tradeCount, int itemPrice) {
- super(userId, companyId, tradeCount, itemPrice);
+ public CreateBuyOrderCommand(AggregateIdentifier userId, AggregateIdentifier orderBookId, long tradeCount, int itemPrice) {
+ super(userId, orderBookId, tradeCount, itemPrice);
}
}
View
2  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.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
View
19 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyEntry.java
@@ -15,12 +15,14 @@
package org.axonframework.samples.trader.app.query.company;
+import org.springframework.data.annotation.Id;
+
/**
* @author Jettro Coenradie
*/
public class CompanyEntry {
+ @Id
private String identifier;
- private String orderBookIdentifier;
private String name;
private long value;
private long amountOfShares;
@@ -30,7 +32,7 @@ public long getAmountOfShares() {
return amountOfShares;
}
- void setAmountOfShares(long amountOfShares) {
+ public void setAmountOfShares(long amountOfShares) {
this.amountOfShares = amountOfShares;
}
@@ -38,7 +40,7 @@ public String getIdentifier() {
return identifier;
}
- void setIdentifier(String identifier) {
+ public void setIdentifier(String identifier) {
this.identifier = identifier;
}
@@ -46,7 +48,7 @@ public String getName() {
return name;
}
- void setName(String name) {
+ public void setName(String name) {
this.name = name;
}
@@ -54,7 +56,7 @@ public boolean isTradeStarted() {
return tradeStarted;
}
- void setTradeStarted(boolean tradeStarted) {
+ public void setTradeStarted(boolean tradeStarted) {
this.tradeStarted = tradeStarted;
}
@@ -66,11 +68,4 @@ public void setValue(long value) {
this.value = value;
}
- public String getOrderBookIdentifier() {
- return orderBookIdentifier;
- }
-
- void setOrderBookIdentifier(String orderBookIdentifier) {
- this.orderBookIdentifier = orderBookIdentifier;
- }
}
View
26 app/src/main/java/org/axonframework/samples/trader/app/query/company/CompanyListener.java
@@ -15,11 +15,9 @@
package org.axonframework.samples.trader.app.query.company;
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBObject;
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.samples.trader.app.api.company.CompanyCreatedEvent;
-import org.axonframework.samples.trader.app.query.MongoHelper;
+import org.axonframework.samples.trader.app.query.company.repositories.CompanyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -28,23 +26,23 @@
*/
@Component
public class CompanyListener {
- private MongoHelper mongo;
+ private CompanyRepository companyRepository;
@EventHandler
public void handleCompanyCreatedEvent(CompanyCreatedEvent event) {
- DBObject companyEntry = BasicDBObjectBuilder.start()
- .add("identifier", event.getCompanyIdentifier().asString())
- .add("name", event.getCompanyName())
- .add("value", event.getCompanyValue())
- .add("amountOfShares", event.getAmountOfShares())
- .add("tradeStarted", true)
- .get();
- mongo.companies().insert(companyEntry);
+ CompanyEntry companyEntry = new CompanyEntry();
+ companyEntry.setIdentifier(event.getCompanyIdentifier().asString());
+ companyEntry.setValue(event.getCompanyValue());
+ companyEntry.setAmountOfShares(event.getAmountOfShares());
+ companyEntry.setTradeStarted(true);
+ companyEntry.setName(event.getCompanyName());
+
+ companyRepository.save(companyEntry);
}
@Autowired
- public void setMongoHelper(MongoHelper mongoHelper) {
- this.mongo = mongoHelper;
+ public void setCompanyRepository(CompanyRepository companyRepository) {
+ this.companyRepository = companyRepository;
}
}
View
83 .../main/java/org/axonframework/samples/trader/app/query/company/CompanyRepositoryMongo.java
@@ -1,83 +0,0 @@
-/*
- * Copyright (c) 2010. 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.company;
-
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import org.axonframework.samples.trader.app.query.MongoHelper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Jettro Coenradie
- */
-@Component
-public class CompanyRepositoryMongo implements CompanyRepository {
- private MongoHelper mongo;
-
- @Override
- public List<CompanyEntry> listAllCompanies() {
- DBCursor companiesCursor = mongo.companies().find();
- List<CompanyEntry> companies = new ArrayList<CompanyEntry>();
- while (companiesCursor.hasNext()) {
- DBObject nextCompany = companiesCursor.next();
- CompanyEntry companyEntry = mapCompanyFromMongo(nextCompany);
- companies.add(companyEntry);
- }
- return companies;
- }
-
- @Override
- public CompanyEntry findCompanyByIdentifier(String companyIdentifier) {
- DBObject query = BasicDBObjectBuilder.start().add("identifier", companyIdentifier).get();
- return mapCompanyFromMongo(mongo.companies().findOne(query));
- }
-
- @Override
- public CompanyEntry findCompanyByOrderBookIdentifier(String orderBookIdentifier) {
- DBObject query = BasicDBObjectBuilder.start().add("orderBookIdentifier", orderBookIdentifier).get();
- return mapCompanyFromMongo(mongo.companies().findOne(query));
- }
-
- /**
- * Used to create a CompanyEntry object based on a mongo DBObject
- *
- * @param mongoCompanyObject The mongo object to create a CompanyEntry
- * @return CompanyEntry created from te mongo object
- */
- private CompanyEntry mapCompanyFromMongo(DBObject mongoCompanyObject) {
- CompanyEntry companyEntry = new CompanyEntry();
- companyEntry.setIdentifier((String) mongoCompanyObject.get("identifier"));
- companyEntry.setName((String) mongoCompanyObject.get("name"));
- companyEntry.setValue((Long) mongoCompanyObject.get("value"));
- companyEntry.setAmountOfShares((Long) mongoCompanyObject.get("amountOfShares"));
- companyEntry.setTradeStarted((Boolean) mongoCompanyObject.get("tradeStarted"));
- if (mongoCompanyObject.containsField("orderBookIdentifier")) {
- String orderBookIdentifier = (String) mongoCompanyObject.get("orderBookIdentifier");
- companyEntry.setOrderBookIdentifier(orderBookIdentifier);
- }
- return companyEntry;
- }
-
- @Autowired
- public void setMongo(MongoHelper mongo) {
- this.mongo = mongo;
- }
-}
View
13 .../app/query/company/CompanyRepository.java → ...mpany/repositories/CompanyRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010. Gridshore
+ * 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
@@ -13,17 +13,14 @@
* limitations under the License.
*/
-package org.axonframework.samples.trader.app.query.company;
+package org.axonframework.samples.trader.app.query.company.repositories;
-import java.util.List;
+import org.axonframework.samples.trader.app.query.company.CompanyEntry;
+import org.springframework.data.repository.PagingAndSortingRepository;
/**
* @author Jettro Coenradie
*/
-public interface CompanyRepository {
- List<CompanyEntry> listAllCompanies();
+public interface CompanyRepository extends PagingAndSortingRepository<CompanyEntry, String> {
- CompanyEntry findCompanyByIdentifier(String companyIdentifier);
-
- CompanyEntry findCompanyByOrderBookIdentifier(String orderBookIdentifier);
}
View
3  app/src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookEntry.java
@@ -15,6 +15,8 @@
package org.axonframework.samples.trader.app.query.orderbook;
+import org.springframework.data.annotation.Id;
+
import java.util.ArrayList;
import java.util.List;
@@ -22,6 +24,7 @@
* @author Jettro Coenradie
*/
public class OrderBookEntry {
+ @Id
private String identifier;
private String companyIdentifier;
private String companyName;
View
128 ...src/main/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookListener.java
@@ -15,20 +15,17 @@
package org.axonframework.samples.trader.app.query.orderbook;
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBObject;
import org.axonframework.domain.AggregateIdentifier;
import org.axonframework.eventhandling.annotation.EventHandler;
import org.axonframework.samples.trader.app.api.order.*;
-import org.axonframework.samples.trader.app.query.MongoHelper;
import org.axonframework.samples.trader.app.query.company.CompanyEntry;
-import org.axonframework.samples.trader.app.query.company.CompanyRepository;
+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.tradeexecuted.TradeExecutedEntry;
+import org.axonframework.samples.trader.app.query.tradeexecuted.repositories.TradeExecutedRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.ArrayList;
-import java.util.List;
-
/**
* @author Jettro Coenradie
*/
@@ -36,54 +33,40 @@
public class OrderBookListener {
private static final String BUY = "Buy";
private static final String SELL = "Sell";
- private MongoHelper mongo;
+ private OrderBookRepository orderBookRepository;
private CompanyRepository companyRepository;
+ private TradeExecutedRepository tradeExecutedRepository;
+
@EventHandler
public void handleOrderBookCreatedEvent(OrderBookCreatedEvent event) {
- DBObject query = BasicDBObjectBuilder.start().add("identifier", event.getCompanyIdentifier().asString()).get();
- DBObject company = mongo.companies().findOne(query);
- company.put("orderBookIdentifier", event.getOrderBookIdentifier().toString());
- mongo.companies().update(query, company);
-
- DBObject orderBook = BasicDBObjectBuilder.start()
- .add("identifier", event.getOrderBookIdentifier().toString())
- .add("companyIdentifier", event.getCompanyIdentifier().toString())
- .add("companyName", company.get("name")).get();
- mongo.orderBooks().insert(orderBook);
+ CompanyEntry companyEntry = companyRepository.findOne(event.getCompanyIdentifier().asString());
+ OrderBookEntry orderBookEntry = new OrderBookEntry();
+ orderBookEntry.setCompanyIdentifier(event.getCompanyIdentifier().asString());
+ orderBookEntry.setCompanyName(companyEntry.getName());
+ orderBookEntry.setIdentifier(event.getOrderBookIdentifier().asString());
+ orderBookRepository.save(orderBookEntry);
}
@EventHandler
public void handleBuyOrderPlaced(BuyOrderPlacedEvent event) {
- DBObject query = BasicDBObjectBuilder.start().add("identifier", event.getAggregateIdentifier().asString()).get();
- DBObject orderBook = mongo.orderBooks().findOne(query);
+ OrderBookEntry orderBook = orderBookRepository.findOne(event.orderBookIdentifier().asString());
- DBObject buyOrder = createPlacedOrder(event, BUY);
-
- if (!orderBook.containsField("buyOrders")) {
- orderBook.put("buyOrders", new ArrayList());
- }
+ OrderEntry buyOrder = createPlacedOrder(event, BUY);
+ orderBook.buyOrders().add(buyOrder);
- ((List) orderBook.get("buyOrders")).add(buyOrder);
-
- mongo.orderBooks().update(query, orderBook);
+ orderBookRepository.save(orderBook);
}
@EventHandler
public void handleSellOrderPlaced(SellOrderPlacedEvent event) {
- DBObject query = BasicDBObjectBuilder.start().add("identifier", event.getAggregateIdentifier().asString()).get();
- DBObject orderBook = mongo.orderBooks().findOne(query);
-
- DBObject buyOrder = createPlacedOrder(event, SELL);
+ OrderBookEntry orderBook = orderBookRepository.findOne(event.orderBookIdentifier().asString());
- if (!orderBook.containsField("sellOrders")) {
- orderBook.put("sellOrders", new ArrayList());
- }
+ OrderEntry sellOrder = createPlacedOrder(event, SELL);
+ orderBook.sellOrders().add(sellOrder);
- ((List) orderBook.get("sellOrders")).add(buyOrder);
-
- mongo.orderBooks().update(query, orderBook);
+ orderBookRepository.save(orderBook);
}
@EventHandler
@@ -92,51 +75,50 @@ public void handleTradeExecuted(TradeExecutedEvent event) {
AggregateIdentifier sellOrderId = event.getSellOrderId();
AggregateIdentifier orderBookIdentifier = event.getOrderBookIdentifier();
- CompanyEntry company = companyRepository.findCompanyByOrderBookIdentifier(orderBookIdentifier.asString());
- DBObject tradeExecutedMongo = BasicDBObjectBuilder.start()
- .add("count", event.getTradeCount())
- .add("price", event.getTradePrice())
- .add("name", company.getName())
- .add("orderBookIdentifier", orderBookIdentifier.asString())
- .get();
+ OrderBookEntry orderBookEntry = orderBookRepository.findOne(orderBookIdentifier.asString());
+
+ TradeExecutedEntry tradeExecutedEntry = new TradeExecutedEntry();
+ tradeExecutedEntry.setCompanyName(orderBookEntry.getCompanyName());
+ tradeExecutedEntry.setOrderBookIdentifier(orderBookEntry.getIdentifier());
+ tradeExecutedEntry.setTradeCount(event.getTradeCount());
+ tradeExecutedEntry.setTradePrice(event.getTradePrice());
- mongo.tradesExecuted().insert(tradeExecutedMongo);
+ tradeExecutedRepository.save(tradeExecutedEntry);
// TODO find a better solution or maybe pull them apart
- DBObject query = BasicDBObjectBuilder.start()
- .add("identifier", event.getAggregateIdentifier().asString())
- .get();
- DBObject orderBook = mongo.orderBooks().findOne(query);
- List buyOrders = (List) orderBook.get("buyOrders");
- for (Object orderObj : buyOrders) {
- DBObject order = (DBObject) orderObj;
- if (((String) order.get("identifier")).equals(buyOrderId.asString())) {
- long itemsRemaining = (Long) order.get("itemsRemaining");
- order.put("itemsRemaining", itemsRemaining - event.getTradeCount());
+ for (OrderEntry order : orderBookEntry.buyOrders()) {
+ if (order.getIdentifier().equals(buyOrderId.asString())) {
+ long itemsRemaining = order.getItemsRemaining();
+ order.setItemsRemaining(itemsRemaining - event.getTradeCount());
break;
}
}
- List sellOrders = (List) orderBook.get("sellOrders");
- for (Object orderObj : sellOrders) {
- DBObject order = (DBObject) orderObj;
- if (((String) order.get("identifier")).equals(sellOrderId.asString())) {
- long itemsRemaining = (Long) order.get("itemsRemaining");
- order.put("itemsRemaining", itemsRemaining - event.getTradeCount());
+ for (OrderEntry order : orderBookEntry.sellOrders()) {
+ if (order.getIdentifier().equals(sellOrderId.asString())) {
+ long itemsRemaining = order.getItemsRemaining();
+ order.setItemsRemaining(itemsRemaining - event.getTradeCount());
break;
}
}
- mongo.orderBooks().update(query, orderBook);
+ orderBookRepository.save(orderBookEntry);
+ }
+
+ private OrderEntry createPlacedOrder(AbstractOrderPlacedEvent event, String type) {
+ OrderEntry entry = new OrderEntry();
+ entry.setIdentifier(event.getOrderId().asString());
+ entry.setItemsRemaining(event.getTradeCount());
+ entry.setTradeCount(event.getTradeCount());
+ entry.setUserId(event.getUserId().asString());
+ entry.setType(type);
+ entry.setItemPrice(event.getItemPrice());
+
+ return entry;
}
- private DBObject createPlacedOrder(AbstractOrderPlacedEvent event, String type) {
- return BasicDBObjectBuilder.start()
- .add("identifier", event.getOrderId().asString())
- .add("itemPrice", event.getItemPrice())
- .add("itemsRemaining", event.getTradeCount())
- .add("tradeCount", event.getTradeCount())
- .add("userId", event.getUserId().asString())
- .add("type", type).get();
+ @Autowired
+ public void setOrderBookRepository(OrderBookRepository orderBookRepository) {
+ this.orderBookRepository = orderBookRepository;
}
@Autowired
@@ -145,7 +127,7 @@ public void setCompanyRepository(CompanyRepository companyRepository) {
}
@Autowired
- public void setMongo(MongoHelper mongo) {
- this.mongo = mongo;
+ public void setTradeExecutedRepository(TradeExecutedRepository tradeExecutedRepository) {
+ this.tradeExecutedRepository = tradeExecutedRepository;
}
}
View
100 ...n/java/org/axonframework/samples/trader/app/query/orderbook/OrderBookRepositoryMongo.java
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2010. 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.orderbook;
-
-import com.mongodb.BasicDBObject;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import org.axonframework.samples.trader.app.query.MongoHelper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Jettro Coenradie
- */
-@Repository
-public class OrderBookRepositoryMongo implements OrderBookRepository {
- private MongoHelper mongo;
-
- @Override
- public List<OrderBookEntry> listAllOrderBooks() {
- DBCursor dbCursor = mongo.orderBooks().find();
-
- List<OrderBookEntry> entries = new ArrayList<OrderBookEntry>();
- while (dbCursor.hasNext()) {
- DBObject next = dbCursor.next();
- OrderBookEntry entry = mapOrderBookEntryFromMongo(next);
- entries.add(entry);
- }
- return entries;
- }
-
- @Override
- public OrderBookEntry findByIdentifier(String aggregateIdentifier) {
- DBObject one = mongo.orderBooks().findOne(new BasicDBObject("identifier", aggregateIdentifier));
- return mapOrderBookEntryFromMongo(one);
- }
-
- @Override
- public OrderBookEntry findByCompany(String companyIdentifier) {
- DBObject one = mongo.orderBooks().findOne(new BasicDBObject("companyIdentifier", companyIdentifier));
- return mapOrderBookEntryFromMongo(one);
- }
-
- @Override
- public OrderEntry findByOrderIdentifier(String orderIdentifier) {
- throw new UnsupportedOperationException();
- }
-
- private OrderBookEntry mapOrderBookEntryFromMongo(DBObject next) {
- OrderBookEntry entry = new OrderBookEntry();
- entry.setCompanyName((String) next.get("companyName"));
- entry.setIdentifier((String) next.get("identifier"));
- entry.setCompanyIdentifier((String) next.get("companyIdentifier"));
- if (next.containsField("sellOrders")) {
- List<DBObject> sellOrderObjects = (List<DBObject>) next.get("sellOrders");
- for (DBObject sellOrderObject : sellOrderObjects) {
- entry.sellOrders().add(mapOrderEntryFromMongo(sellOrderObject));
- }
- }
- if (next.containsField("buyOrders")) {
- List<DBObject> buyOrderObjects = (List<DBObject>) next.get("buyOrders");
- for (DBObject buyOrderObject : buyOrderObjects) {
- entry.buyOrders().add(mapOrderEntryFromMongo(buyOrderObject));
- }
- }
- return entry;
- }
-
- private OrderEntry mapOrderEntryFromMongo(DBObject orderObject) {
- OrderEntry orderEntry = new OrderEntry();
- orderEntry.setType((String) orderObject.get("type"));
- orderEntry.setItemsRemaining((Long) orderObject.get("itemsRemaining"));
- orderEntry.setTradeCount((Long) orderObject.get("tradeCount"));
- orderEntry.setUserId((String) orderObject.get("userId"));
- orderEntry.setIdentifier((String) orderObject.get("identifier"));
- orderEntry.setItemPrice((Integer) orderObject.get("itemPrice"));
- return orderEntry;
- }
-
- @Autowired
- public void setMongo(MongoHelper mongo) {
- this.mongo = mongo;
- }
-}
View
17 .../query/orderbook/OrderBookRepository.java → ...ook/repositories/OrderBookRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010. Gridshore
+ * 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
@@ -13,19 +13,16 @@
* limitations under the License.
*/
-package org.axonframework.samples.trader.app.query.orderbook;
+package org.axonframework.samples.trader.app.query.orderbook.repositories;
+
+import org.axonframework.samples.trader.app.query.orderbook.OrderBookEntry;
+import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
* @author Jettro Coenradie
*/
-public interface OrderBookRepository {
- List<OrderBookEntry> listAllOrderBooks();
-
- OrderBookEntry findByIdentifier(String aggregateIdentifier);
-
- OrderBookEntry findByCompany(String companyIdentifier);
-
- OrderEntry findByOrderIdentifier(String orderIdentifier);
+public interface OrderBookRepository extends PagingAndSortingRepository<OrderBookEntry, String> {
+ List<OrderBookEntry> findByCompanyIdentifier(String companyIdentifier);
}
View
61 ...rg/axonframework/samples/trader/app/query/tradeexecuted/TradeExecutedRepositoryMongo.java
@@ -1,61 +0,0 @@
-/*
- * Copyright (c) 2010. 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.tradeexecuted;
-
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import org.axonframework.samples.trader.app.query.MongoHelper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Jettro Coenradie
- */
-@Repository
-public class TradeExecutedRepositoryMongo implements TradeExecutedRepository {
- private MongoHelper mongo;
-
- @Override
- public List<TradeExecutedEntry> findExecutedTradesForOrderBook(String orderBookIdentifier) {
- DBObject query = BasicDBObjectBuilder.start().add("orderBookIdentifier", orderBookIdentifier).get();
- DBCursor tradesExecutedCursor = mongo.tradesExecuted().find(query);
- List<TradeExecutedEntry> tradesExecuted = new ArrayList<TradeExecutedEntry>();
- while (tradesExecutedCursor.hasNext()) {
- DBObject tradeExecutedMongo = tradesExecutedCursor.next();
- tradesExecuted.add(mapFromMongoToTradeExecutedEntry(tradeExecutedMongo));
- }
- return tradesExecuted;
- }
-
- private TradeExecutedEntry mapFromMongoToTradeExecutedEntry(DBObject tradeExecutedMongo) {
- TradeExecutedEntry entry = new TradeExecutedEntry();
- entry.setOrderBookIdentifier((String) tradeExecutedMongo.get("orderBookIdentifier"));
- entry.setTradeCount((Long) tradeExecutedMongo.get("count"));
- entry.setCompanyName((String) tradeExecutedMongo.get("name"));
- entry.setTradePrice((Integer) tradeExecutedMongo.get("price"));
- return entry;
- }
-
-
- @Autowired
- public void setMongo(MongoHelper mongo) {
- this.mongo = mongo;
- }
-}
View
11 ...radeexecuted/TradeExecutedRepository.java → ...repositories/TradeExecutedRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010. Gridshore
+ * 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
@@ -13,13 +13,16 @@
* limitations under the License.
*/
-package org.axonframework.samples.trader.app.query.tradeexecuted;
+package org.axonframework.samples.trader.app.query.tradeexecuted.repositories;
+
+import org.axonframework.samples.trader.app.query.tradeexecuted.TradeExecutedEntry;
+import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
* @author Jettro Coenradie
*/
-public interface TradeExecutedRepository {
- List<TradeExecutedEntry> findExecutedTradesForOrderBook(String orderBookIdentifier);
+public interface TradeExecutedRepository extends PagingAndSortingRepository<TradeExecutedEntry, String> {
+ List<TradeExecutedEntry> findByOrderBookIdentifier(String orderBookIdentifier);
}
View
69 app/src/main/java/org/axonframework/samples/trader/app/query/user/UserRepositoryMongo.java
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2010. 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.user;
-
-import com.mongodb.BasicDBObjectBuilder;
-import com.mongodb.DBCursor;
-import com.mongodb.DBObject;
-import org.axonframework.samples.trader.app.query.MongoHelper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Repository;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Jettro Coenradie
- */
-@Repository
-public class UserRepositoryMongo implements UserRepository {
- private MongoHelper mongo;
-
- @Override
- public UserEntry findByUsername(String username) {
- DBObject query = BasicDBObjectBuilder.start("username", username).get();
- DBObject one = mongo.users().findOne(query);
-
- if (null == one) {
- return null;
- }
-
- return mapToUserEntry(one);
- }
-
- @Override
- public List<UserEntry> obtainAllUsers() {
- DBCursor dbCursor = mongo.users().find();
- List<UserEntry> users = new ArrayList<UserEntry>(dbCursor.size());
- while (dbCursor.hasNext()) {
- users.add(mapToUserEntry(dbCursor.next()));
- }
- return users;
- }
-
- private UserEntry mapToUserEntry(DBObject one) {
- UserEntry entry = new UserEntry();
- entry.setIdentifier((String) one.get("identifier"));
- entry.setName((String) one.get("name"));
- entry.setUsername((String) one.get("username"));
- return entry;
- }
-
- @Autowired
- public void setMongohelper(MongoHelper mongoHelper) {
- this.mongo = mongoHelper;
- }
-}
View
11 ...trader/app/query/user/UserRepository.java → ...ery/user/repositories/UserRepository.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010. Gridshore
+ * 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
@@ -13,15 +13,14 @@
* limitations under the License.
*/
-package org.axonframework.samples.trader.app.query.user;
+package org.axonframework.samples.trader.app.query.user.repositories;
-import java.util.List;
+import org.axonframework.samples.trader.app.query.user.UserEntry;
+import org.springframework.data.repository.PagingAndSortingRepository;
/**
* @author Jettro Coenradie
*/
-public interface UserRepository {
+public interface UserRepository extends PagingAndSortingRepository<UserEntry, String> {
UserEntry findByUsername(String username);
-
- List<UserEntry> obtainAllUsers();
}
View
2  app/src/main/resources/META-INF/spring/persistence-infrastructure-context.xml
@@ -23,6 +23,8 @@
http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
+ <mongo:repositories base-package="org.axonframework.samples.trader.app.query.*.repositories"
+ mongo-template-ref="mongoSpringTemplate"/>
<bean id="mongoSpringTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg ref="mongoDbFactory"/>
View
10 ...c/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.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
import org.axonframework.test.FixtureConfiguration;
import org.axonframework.test.Fixtures;
import org.junit.Before;
@@ -53,8 +53,8 @@ public void setUp() {
@Test
public void testHandleCreateUser() throws Exception {
fixture.given()
- .when(new CreateUserCommand("Buyer 1", "buyer1", "buyer1"))
- .expectEvents(new UserCreatedEvent("Buyer 1", "buyer1", sha1("buyer1")));
+ .when(new CreateUserCommand("Buyer 1", "buyer1", "buyer1"))
+ .expectEvents(new UserCreatedEvent("Buyer 1", "buyer1", sha1("buyer1")));
}
@Test
@@ -66,7 +66,7 @@ public void testHandleAuthenticateUser() throws Exception {
when(userQueryRepository.findByUsername("buyer1")).thenReturn(userEntry);
fixture.given(new UserCreatedEvent("Buyer 1", "buyer1", sha1("buyer1")))
- .when(new AuthenticateUserCommand("buyer1", "buyer1".toCharArray()))
- .expectEvents(new UserAuthenticatedEvent());
+ .when(new AuthenticateUserCommand("buyer1", "buyer1".toCharArray()))
+ .expectEvents(new UserAuthenticatedEvent());
}
}
View
46 ...ework/samples/trader/app/query/company/repositories/CompanyRepositoryIntegrationTest.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.query.company.repositories;
+
+import org.axonframework.domain.UUIDAggregateIdentifier;
+import org.axonframework.samples.trader.app.query.company.CompanyEntry;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * @author Jettro Coenradie
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration({"classpath:META-INF/spring/persistence-infrastructure-context.xml"})
+public class CompanyRepositoryIntegrationTest {
+ @Autowired
+ private CompanyRepository companyRepository;
+
+ @Test
+ public void storeCompanyInRepository() {
+ CompanyEntry companyEntry = new CompanyEntry();
+ companyEntry.setIdentifier(new UUIDAggregateIdentifier().asString());
+ companyEntry.setValue(100000);
+ companyEntry.setAmountOfShares(1000);
+ companyEntry.setTradeStarted(true);
+
+ companyRepository.save(companyEntry);
+
+ }
+}
View
186 ...rg/axonframework/samples/trader/app/query/orderbook/OrderBookListenerIntegrationTest.java
@@ -0,0 +1,186 @@
+/*
+ * 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.orderbook;
+
+import org.axonframework.domain.AggregateIdentifier;
+import org.axonframework.domain.UUIDAggregateIdentifier;
+import org.axonframework.samples.trader.app.api.order.BuyOrderPlacedEvent;
+import org.axonframework.samples.trader.app.api.order.OrderBookCreatedEvent;
+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.tradeexecuted.TradeExecutedEntry;
+import org.axonframework.samples.trader.app.query.tradeexecuted.repositories.TradeExecutedRepository;
+import org.axonframework.test.utils.DomainEventUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import static org.junit.Assert.*;
+
+/**
+ * @author Jettro Coenradie
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration({"classpath:META-INF/spring/persistence-infrastructure-context.xml"})
+public class OrderBookListenerIntegrationTest {
+
+ private OrderBookListener orderBookListener;
+
+ @Autowired
+ private OrderBookRepository orderBookRepository;
+
+ @Autowired
+ private TradeExecutedRepository tradeExecutedRepository;
+ @Autowired
+ private CompanyRepository companyRepository;
+
+ @Autowired
+ private MongoTemplate mongoTemplate;
+
+
+ @Before
+ public void setUp() throws Exception {
+ mongoTemplate.dropCollection(OrderBookEntry.class);
+ mongoTemplate.dropCollection(CompanyEntry.class);
+ mongoTemplate.dropCollection(TradeExecutedEntry.class);
+
+ orderBookListener = new OrderBookListener();
+ orderBookListener.setCompanyRepository(companyRepository);
+ orderBookListener.setOrderBookRepository(orderBookRepository);
+ orderBookListener.setTradeExecutedRepository(tradeExecutedRepository);
+ }
+
+ @Test
+ public void testHandleOrderBookCreatedEvent() throws Exception {
+ CompanyEntry company = createCompany();
+
+ AggregateIdentifier orderBookIdentifier = new UUIDAggregateIdentifier();
+ OrderBookCreatedEvent event = new OrderBookCreatedEvent(new UUIDAggregateIdentifier(company.getIdentifier()));
+ DomainEventUtils.setAggregateIdentifier(event, orderBookIdentifier);
+
+ orderBookListener.handleOrderBookCreatedEvent(event);
+ Iterable<OrderBookEntry> all = orderBookRepository.findAll();
+ OrderBookEntry orderBookEntry = all.iterator().next();
+ assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry);
+ assertEquals("Test Company", orderBookEntry.getCompanyName());
+ }
+
+ @Test
+ public void testHandleBuyOrderPlaced() throws Exception {
+ CompanyEntry company = createCompany();
+ OrderBookEntry orderBook = createOrderBook(company);
+
+ AggregateIdentifier userIdentifier = new UUIDAggregateIdentifier();
+ AggregateIdentifier orderId = new UUIDAggregateIdentifier();
+ BuyOrderPlacedEvent event = new BuyOrderPlacedEvent(orderId, 300, 100, userIdentifier);
+ DomainEventUtils.setAggregateIdentifier(event, new UUIDAggregateIdentifier(orderBook.getIdentifier()));
+
+ orderBookListener.handleBuyOrderPlaced(event);
+ Iterable<OrderBookEntry> all = orderBookRepository.findAll();
+ OrderBookEntry orderBookEntry = all.iterator().next();
+ assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry);
+ assertEquals("Test Company", orderBookEntry.getCompanyName());
+ assertEquals(1, orderBookEntry.buyOrders().size());
+ assertEquals(300, orderBookEntry.buyOrders().get(0).getTradeCount());
+ }
+
+ @Test
+ public void testHandleSellOrderPlaced() throws Exception {
+ CompanyEntry company = createCompany();
+ OrderBookEntry orderBook = createOrderBook(company);
+
+ AggregateIdentifier userIdentifier = new UUIDAggregateIdentifier();
+ AggregateIdentifier orderId = new UUIDAggregateIdentifier();
+ SellOrderPlacedEvent event = new SellOrderPlacedEvent(orderId, 300, 100, userIdentifier);
+ DomainEventUtils.setAggregateIdentifier(event, new UUIDAggregateIdentifier(orderBook.getIdentifier()));
+
+ orderBookListener.handleSellOrderPlaced(event);
+ Iterable<OrderBookEntry> all = orderBookRepository.findAll();
+ OrderBookEntry orderBookEntry = all.iterator().next();
+ assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry);
+ assertEquals("Test Company", orderBookEntry.getCompanyName());
+ assertEquals(1, orderBookEntry.sellOrders().size());
+ assertEquals(300, orderBookEntry.sellOrders().get(0).getTradeCount());
+ }
+
+ @Test
+ public void testHandleTradeExecuted() throws Exception {
+ CompanyEntry company = createCompany();
+ OrderBookEntry orderBook = createOrderBook(company);
+
+ AggregateIdentifier userIdentifier = new UUIDAggregateIdentifier();
+ AggregateIdentifier sellOrderId = new UUIDAggregateIdentifier();
+ SellOrderPlacedEvent sellOrderPlacedEvent = new SellOrderPlacedEvent(sellOrderId, 300, 100, userIdentifier);
+ DomainEventUtils.setAggregateIdentifier(sellOrderPlacedEvent, new UUIDAggregateIdentifier(orderBook.getIdentifier()));
+
+ orderBookListener.handleSellOrderPlaced(sellOrderPlacedEvent);
+
+ AggregateIdentifier buyOrderId = new UUIDAggregateIdentifier();
+ BuyOrderPlacedEvent buyOrderPlacedEvent = new BuyOrderPlacedEvent(buyOrderId, 300, 150, userIdentifier);
+ DomainEventUtils.setAggregateIdentifier(buyOrderPlacedEvent, new UUIDAggregateIdentifier(orderBook.getIdentifier()));
+
+ orderBookListener.handleBuyOrderPlaced(buyOrderPlacedEvent);
+
+ Iterable<OrderBookEntry> all = orderBookRepository.findAll();
+ OrderBookEntry orderBookEntry = all.iterator().next();
+ assertNotNull("The first item of the iterator for orderbooks should not be null", orderBookEntry);
+ assertEquals("Test Company", orderBookEntry.getCompanyName());
+ assertEquals(1, orderBookEntry.sellOrders().size());
+ assertEquals(1, orderBookEntry.buyOrders().size());
+
+
+ TradeExecutedEvent event = new TradeExecutedEvent(300, 125, buyOrderId, sellOrderId);
+ DomainEventUtils.setAggregateIdentifier(event, new UUIDAggregateIdentifier(orderBook.getIdentifier()));
+ orderBookListener.handleTradeExecuted(event);
+
+ Iterable<TradeExecutedEntry> tradeExecutedEntries = tradeExecutedRepository.findAll();
+ assertTrue(tradeExecutedEntries.iterator().hasNext());
+ TradeExecutedEntry tradeExecutedEntry = tradeExecutedEntries.iterator().next();
+ assertEquals("Test Company", tradeExecutedEntry.getCompanyName());
+ assertEquals(300, tradeExecutedEntry.getTradeCount());
+ assertEquals(125, tradeExecutedEntry.getTradePrice());
+ }
+
+
+ private OrderBookEntry createOrderBook(CompanyEntry company) {
+ AggregateIdentifier orderBookIdentifier = new UUIDAggregateIdentifier();
+ OrderBookEntry orderBookEntry = new OrderBookEntry();
+ orderBookEntry.setIdentifier(orderBookIdentifier.asString());
+ orderBookEntry.setCompanyIdentifier(company.getIdentifier());
+ orderBookEntry.setCompanyName(company.getName());
+ orderBookRepository.save(orderBookEntry);
+ return orderBookEntry;
+ }
+
+ private CompanyEntry createCompany() {
+ AggregateIdentifier companyIdentifier = new UUIDAggregateIdentifier();
+ CompanyEntry companyEntry = new CompanyEntry();
+ companyEntry.setIdentifier(companyIdentifier.asString());
+ companyEntry.setName("Test Company");
+ companyEntry.setAmountOfShares(100000);
+ companyEntry.setTradeStarted(true);
+ companyEntry.setValue(1000);
+ companyRepository.save(companyEntry);
+ return companyEntry;
+ }
+}
View
30 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.CompanyRepository;
+import org.axonframework.samples.trader.app.query.company.repositories.CompanyRepository;
import org.axonframework.samples.trader.app.query.orderbook.OrderBookEntry;
-import org.axonframework.samples.trader.app.query.orderbook.OrderBookRepository;
+import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookRepository;
import org.axonframework.samples.trader.app.query.tradeexecuted.TradeExecutedEntry;
-import org.axonframework.samples.trader.app.query.tradeexecuted.TradeExecutedRepository;
+import org.axonframework.samples.trader.app.query.tradeexecuted.repositories.TradeExecutedRepository;
import org.axonframework.samples.trader.app.query.user.UserEntry;
-import org.axonframework.samples.trader.app.query.user.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
import org.axonframework.samples.trader.webui.order.AbstractOrder;
import org.axonframework.samples.trader.webui.order.BuyOrder;
import org.axonframework.samples.trader.webui.order.SellOrder;
@@ -72,15 +72,15 @@ public CompanyController(CompanyRepository companyRepository,
@RequestMapping(method = RequestMethod.GET)
public String get(Model model) {
- model.addAttribute("items", companyRepository.listAllCompanies());
+ model.addAttribute("items", companyRepository.findAll());
return "company/list";
}
@RequestMapping(value = "/{identifier}", method = RequestMethod.GET)
public String details(@PathVariable String identifier, Model model) {
- CompanyEntry company = companyRepository.findCompanyByIdentifier(identifier);
- OrderBookEntry bookEntry = orderBookRepository.findByCompany(company.getIdentifier());
- List<TradeExecutedEntry> executedTrades = tradeExecutedRepository.findExecutedTradesForOrderBook(bookEntry.getIdentifier());
+ CompanyEntry company = companyRepository.findOne(identifier);
+ OrderBookEntry bookEntry = orderBookRepository.findByCompanyIdentifier(company.getIdentifier()).get(0);
+ List<TradeExecutedEntry> executedTrades = tradeExecutedRepository.findByOrderBookIdentifier(bookEntry.getIdentifier());
model.addAttribute("company", company);
model.addAttribute("sellOrders", bookEntry.sellOrders());
model.addAttribute("buyOrders", bookEntry.buyOrders());
@@ -110,12 +110,12 @@ public String sell(@ModelAttribute("order") @Valid SellOrder order, BindingResul
if (!bindingResult.hasErrors()) {
UserEntry username = userRepository.findByUsername(SecurityUtil.obtainLoggedinUsername());
- String companyId = order.getCompanyId();
- CompanyEntry companyByIdentifier = companyRepository.findCompanyByIdentifier(companyId);
+ // TODO: make this work for multiple orderbooks per company
+ OrderBookEntry bookEntry = orderBookRepository.findByCompanyIdentifier(order.getCompanyId()).get(0);
CreateSellOrderCommand command = new CreateSellOrderCommand(
new StringAggregateIdentifier(username.getIdentifier()),
- new StringAggregateIdentifier(companyByIdentifier.getOrderBookIdentifier()),
+ new StringAggregateIdentifier(bookEntry.getIdentifier()),
order.getTradeCount(),
order.getItemPrice());
@@ -131,12 +131,12 @@ public String buy(@ModelAttribute("order") @Valid BuyOrder order, BindingResult
if (!bindingResult.hasErrors()) {
UserEntry username = userRepository.findByUsername(SecurityUtil.obtainLoggedinUsername());
- String companyId = order.getCompanyId();
- CompanyEntry companyByIdentifier = companyRepository.findCompanyByIdentifier(companyId);
+ // TODO: make this work for multiple orderbooks per company
+ OrderBookEntry bookEntry = orderBookRepository.findByCompanyIdentifier(order.getCompanyId()).get(0);
CreateBuyOrderCommand command = new CreateBuyOrderCommand(
new StringAggregateIdentifier(username.getIdentifier()),
- new StringAggregateIdentifier(companyByIdentifier.getOrderBookIdentifier()),
+ new StringAggregateIdentifier(bookEntry.getIdentifier()),
order.getTradeCount(),
order.getItemPrice());
commandBus.dispatch(command, NoOpCallback.INSTANCE);
@@ -147,7 +147,7 @@ public String buy(@ModelAttribute("order") @Valid BuyOrder order, BindingResult
}
private void prepareInitialOrder(String identifier, AbstractOrder order) {
- CompanyEntry company = companyRepository.findCompanyByIdentifier(identifier);
+ CompanyEntry company = companyRepository.findOne(identifier);
order.setCompanyId(identifier);
order.setCompanyName(company.getName());
}
View
5 web-ui/src/main/java/org/axonframework/samples/trader/webui/init/DBInit.java
@@ -27,11 +27,10 @@
import org.axonframework.samples.trader.app.api.user.CreateUserCommand;
import org.axonframework.samples.trader.app.query.MongoHelper;
import org.axonframework.samples.trader.app.query.company.CompanyEntry;
-import org.axonframework.samples.trader.app.query.company.CompanyRepository;
+import org.axonframework.samples.trader.app.query.company.repositories.CompanyRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
-import java.util.List;
import java.util.Set;
/**
@@ -110,7 +109,7 @@ private void createCompanies(AggregateIdentifier userIdentifier) {
}
private void createOrderBooks() {
- List<CompanyEntry> companyEntries = companyRepository.listAllCompanies();
+ Iterable<CompanyEntry> companyEntries = companyRepository.findAll();
for (CompanyEntry companyEntry : companyEntries) {
CreateOrderBookCommand command = new CreateOrderBookCommand(
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.OrderBookRepository;
+import org.axonframework.samples.trader.app.query.orderbook.repositories.OrderBookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -39,13 +39,13 @@ public OrderBookController(OrderBookRepository repository) {
@RequestMapping(method = RequestMethod.GET)
public String get(Model model) {
- model.addAttribute("items", repository.listAllOrderBooks());
+ model.addAttribute("items", repository.findAll());
return "orderbook/list";
}
@RequestMapping(value = "/{identifier}", method = RequestMethod.GET)
public String getOrders(@PathVariable String identifier, Model model) {
- OrderBookEntry orderBook = repository.findByIdentifier(identifier);
+ OrderBookEntry orderBook = repository.findOne(identifier);
model.addAttribute("orderBook", orderBook);
return "orderbook/orders";
}
View
4 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.UserRepository;
+import org.axonframework.samples.trader.app.query.user.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -37,7 +37,7 @@ public UserController(UserRepository userRepository) {
@RequestMapping(method = RequestMethod.GET)
public String showUsers(Model model) {
- model.addAttribute("items", userRepository.obtainAllUsers());
+ model.addAttribute("items", userRepository.findAll());
return "user/list";
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.