Merge remote-tracking branch 'remotes/upstream/wip-eventuate-client-java' into wip-customer
This commit is contained in:
@@ -3,12 +3,12 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
|
||||
compile project(":common-backend")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.EventUtil;
|
||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
||||
import io.eventuate.Event;
|
||||
import io.eventuate.EventUtil;
|
||||
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Command;
|
||||
|
||||
import io.eventuate.Command;
|
||||
|
||||
interface AccountCommand extends Command {
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class AccountConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -22,7 +22,7 @@ public class AccountConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AggregateRepository<Account, AccountCommand> accountRepository(EventStore eventStore) {
|
||||
public AggregateRepository<Account, AccountCommand> accountRepository(EventuateAggregateStore eventStore) {
|
||||
return new AggregateRepository<Account, AccountCommand>(Account.class, eventStore);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class AccountService {
|
||||
|
||||
@@ -14,7 +15,7 @@ public class AccountService {
|
||||
this.accountRepository = accountRepository;
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Account>> openAccount(String customerId, String title, BigDecimal initialBalance, String description) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<Account>> openAccount(String customerId, String title, BigDecimal initialBalance, String description) {
|
||||
return accountRepository.save(new OpenAccountCommand(customerId, title, initialBalance, description));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EventHandlerContext;
|
||||
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EventHandlerContext;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.DebitRecordedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.*;
|
||||
import rx.Observable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@EventSubscriber(id="accountEventHandlers")
|
||||
public class AccountWorkflow implements CompoundEventHandler {
|
||||
public class AccountWorkflow {
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<Account>> debitAccount(EventHandlerContext<MoneyTransferCreatedEvent> ctx) {
|
||||
MoneyTransferCreatedEvent event = ctx.getEvent();
|
||||
BigDecimal amount = event.getDetails().getAmount();
|
||||
EntityIdentifier transactionId = ctx.getEntityIdentifier();
|
||||
String transactionId = ctx.getEntityId();
|
||||
|
||||
EntityIdentifier fromAccountId = event.getDetails().getFromAccountId();
|
||||
String fromAccountId = event.getDetails().getFromAccountId();
|
||||
|
||||
return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId));
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<Account>> creditAccount(EventHandlerContext<DebitRecordedEvent> ctx) {
|
||||
DebitRecordedEvent event = ctx.getEvent();
|
||||
BigDecimal amount = event.getDetails().getAmount();
|
||||
EntityIdentifier fromAccountId = event.getDetails().getToAccountId();
|
||||
EntityIdentifier transactionId = ctx.getEntityIdentifier();
|
||||
String fromAccountId = event.getDetails().getToAccountId();
|
||||
String transactionId = ctx.getEntityId();
|
||||
|
||||
return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import io.eventuate.Aggregate;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class CreditAccountCommand implements AccountCommand {
|
||||
private final BigDecimal amount;
|
||||
private final EntityIdentifier transactionId;
|
||||
private final String transactionId;
|
||||
|
||||
public CreditAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
|
||||
public CreditAccountCommand(BigDecimal amount, String transactionId) {
|
||||
|
||||
this.amount = amount;
|
||||
this.transactionId = transactionId;
|
||||
@@ -19,7 +19,7 @@ public class CreditAccountCommand implements AccountCommand {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public EntityIdentifier getTransactionId() {
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class DebitAccountCommand implements AccountCommand {
|
||||
private final BigDecimal amount;
|
||||
private final EntityIdentifier transactionId;
|
||||
private final String transactionId;
|
||||
|
||||
public DebitAccountCommand(BigDecimal amount, EntityIdentifier transactionId) {
|
||||
public DebitAccountCommand(BigDecimal amount, String transactionId) {
|
||||
|
||||
this.amount = amount;
|
||||
this.transactionId = transactionId;
|
||||
@@ -19,7 +16,7 @@ public class DebitAccountCommand implements AccountCommand {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public EntityIdentifier getTransactionId() {
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.CommandProcessingAggregates;
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@@ -17,7 +16,8 @@ public class AccountTest {
|
||||
String title = "My Account";
|
||||
String customerId = "00000000-00000000";
|
||||
BigDecimal initialBalance = new BigDecimal(512);
|
||||
List<Event> events = CommandProcessingAggregates.processToList(account, (AccountCommand)new OpenAccountCommand(customerId, title, initialBalance, ""));
|
||||
|
||||
List<Event> events = account.process(new OpenAccountCommand(customerId, title, initialBalance, ""));
|
||||
|
||||
Assert.assertEquals(1, events.size());
|
||||
Assert.assertEquals(AccountOpenedEvent.class, events.get(0).getClass());
|
||||
|
||||
@@ -11,7 +11,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import io.eventuate.javaclient.spring.httpstomp.EventuateHttpStompClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
@Import({CommandSideWebAccountsConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({CommandSideWebAccountsConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class AccountsCommandSideServiceConfiguration {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
|
||||
dependencies {
|
||||
compile project(":accounts-command-side-backend")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,8 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/accounts")
|
||||
@@ -21,8 +22,8 @@ public class AccountController {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public Observable<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
|
||||
public CompletableFuture<CreateAccountResponse> createAccount(@Validated @RequestBody CreateAccountRequest request) {
|
||||
return accountService.openAccount(request.getCustomerId(), request.getTitle(), request.getInitialBalance(), request.getDescription())
|
||||
.map(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityIdentifier().getId()));
|
||||
.thenApply(entityAndEventInfo -> new CreateAccountResponse(entityAndEventInfo.getEntityId()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,16 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
@Configuration
|
||||
@Import({AccountConfiguration.class})
|
||||
@ComponentScan
|
||||
public class CommandSideWebAccountsConfiguration extends WebMvcConfigurerAdapter {
|
||||
@EnableAutoConfiguration
|
||||
public class CommandSideWebAccountsConfiguration {
|
||||
|
||||
class FakeThing {}
|
||||
|
||||
@Bean
|
||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
||||
// https://jira.spring.io/browse/SPR-13083
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
||||
handlers.add(0, new ObservableReturnValueHandler());
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
return new FakeThing();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import({CommandSideWebAccountsConfiguration.class, JdbcEventStoreConfiguration.class})
|
||||
@Import({CommandSideWebAccountsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||
public class AccountControllerIntegrationTestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@@ -3,17 +3,13 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
compile project(":common-backend")
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"
|
||||
|
||||
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
|
||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
|
||||
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import rx.Observable;
|
||||
import io.eventuate.CompletableFutureUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class AccountQueryService {
|
||||
|
||||
@@ -13,15 +13,15 @@ public class AccountQueryService {
|
||||
this.accountInfoRepository = accountInfoRepository;
|
||||
}
|
||||
|
||||
public Observable<AccountInfo> findByAccountId(EntityIdentifier accountId) {
|
||||
AccountInfo account = accountInfoRepository.findOne(accountId.getId());
|
||||
public CompletableFuture<AccountInfo> findByAccountId(String accountId) {
|
||||
AccountInfo account = accountInfoRepository.findOne(accountId);
|
||||
if (account == null)
|
||||
return Observable.error(new AccountNotFoundException(accountId.getId()));
|
||||
return CompletableFutureUtil.failedFuture(new AccountNotFoundException(accountId));
|
||||
else
|
||||
return Observable.just(account);
|
||||
return CompletableFuture.completedFuture(account);
|
||||
}
|
||||
|
||||
public Observable<List<AccountInfo>> findByCustomerId(String customerId) {
|
||||
return Observable.just(accountInfoRepository.findByCustomerId(customerId));
|
||||
public CompletableFuture<List<AccountInfo>> findByCustomerId(String customerId) {
|
||||
return CompletableFuture.completedFuture(accountInfoRepository.findByCustomerId(customerId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import io.eventuate.DispatchedEvent;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountChangedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.MoneyTransferCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
||||
import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
||||
import rx.Observable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -19,9 +15,9 @@ import java.math.BigDecimal;
|
||||
|
||||
import static net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.MoneyUtil.toIntegerRepr;
|
||||
|
||||
@EventSubscriber(id="accountQuerySideEventHandlers")
|
||||
public class AccountQueryWorkflow implements CompoundEventHandler {
|
||||
|
||||
@EventSubscriber(id="querySideEventHandlers")
|
||||
public class AccountQueryWorkflow {
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private AccountInfoUpdateService accountInfoUpdateService;
|
||||
@@ -31,67 +27,60 @@ public class AccountQueryWorkflow implements CompoundEventHandler {
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> create(DispatchedEvent<AccountOpenedEvent> de) {
|
||||
AccountOpenedEvent event = de.event();
|
||||
String id = de.getEntityIdentifier().getId();
|
||||
String eventId = de.eventId().asString();
|
||||
public void create(DispatchedEvent<AccountOpenedEvent> de) {
|
||||
AccountOpenedEvent event = de.getEvent();
|
||||
String id = de.getEntityId();
|
||||
String eventId = de.getEventId().asString();
|
||||
logger.info("**************** account version=" + id + ", " + eventId);
|
||||
BigDecimal initialBalance = event.getInitialBalance();
|
||||
|
||||
String customerId = event.getCustomerId();
|
||||
String title = event.getTitle();
|
||||
String description = event.getDescription();
|
||||
accountInfoUpdateService.create(id, customerId, title, initialBalance, description, eventId);
|
||||
return Observable.just(null);
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
|
||||
String eventId = de.eventId().asString();
|
||||
String moneyTransferId = de.getEntityIdentifier().getId();
|
||||
String fromAccountId = de.event().getDetails().getFromAccountId().getId();
|
||||
String toAccountId = de.event().getDetails().getToAccountId().getId();
|
||||
logger.info("**************** account version=" + fromAccountId + ", " + de.eventId().asString());
|
||||
logger.info("**************** account version=" + toAccountId + ", " + de.eventId().asString());
|
||||
public void recordTransfer(DispatchedEvent<MoneyTransferCreatedEvent> de) {
|
||||
String eventId = de.getEventId().asString();
|
||||
String moneyTransferId = de.getEntityId();
|
||||
String fromAccountId = de.getEvent().getDetails().getFromAccountId();
|
||||
String toAccountId = de.getEvent().getDetails().getToAccountId();
|
||||
logger.info("**************** account version=" + fromAccountId + ", " + de.getEventId().asString());
|
||||
logger.info("**************** account version=" + toAccountId + ", " + de.getEventId().asString());
|
||||
|
||||
AccountTransactionInfo ti = new AccountTransactionInfo(moneyTransferId,
|
||||
fromAccountId,
|
||||
toAccountId,
|
||||
toIntegerRepr(de.event().getDetails().getAmount()),
|
||||
de.event().getDetails().getDate(),
|
||||
de.event().getDetails().getDescription());
|
||||
|
||||
toIntegerRepr(de.getEvent().getDetails().getAmount()),
|
||||
de.getEvent().getDetails().getDate(),
|
||||
de.getEvent().getDetails().getDescription());
|
||||
|
||||
accountInfoUpdateService.addTransaction(eventId, fromAccountId, ti);
|
||||
accountInfoUpdateService.addTransaction(eventId, toAccountId, ti);
|
||||
|
||||
return Observable.just(null);
|
||||
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
|
||||
return saveChange(de, -1);
|
||||
public void recordDebit(DispatchedEvent<AccountDebitedEvent> de) {
|
||||
saveChange(de, -1);
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
|
||||
return saveChange(de, +1);
|
||||
public void recordCredit(DispatchedEvent<AccountCreditedEvent> de) {
|
||||
saveChange(de, +1);
|
||||
}
|
||||
|
||||
public <T extends AccountChangedEvent> Observable<Object> saveChange(DispatchedEvent<T> de, int delta) {
|
||||
String changeId = de.eventId().asString();
|
||||
String transactionId = de.event().getTransactionId().getId();
|
||||
long amount = toIntegerRepr(de.event().getAmount());
|
||||
public <T extends AccountChangedEvent> void saveChange(DispatchedEvent<T> de, int delta) {
|
||||
String changeId = de.getEventId().asString();
|
||||
String transactionId = de.getEvent().getTransactionId();
|
||||
long amount = toIntegerRepr(de.getEvent().getAmount());
|
||||
|
||||
long balanceDelta = amount * delta;
|
||||
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.event().getClass().getSimpleName(), amount, balanceDelta);
|
||||
String accountId = de.getEntityIdentifier().getId();
|
||||
logger.info("**************** account version=" + accountId + ", " + de.eventId().asString());
|
||||
AccountChangeInfo ci = new AccountChangeInfo(changeId, transactionId, de.getEvent().getClass().getSimpleName(), amount, balanceDelta);
|
||||
String accountId = de.getEntityId();
|
||||
logger.info("**************** account version=" + accountId + ", " + de.getEventId().asString());
|
||||
|
||||
accountInfoUpdateService.updateBalance(accountId, changeId, balanceDelta, ci);
|
||||
|
||||
return Observable.just(null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
@@ -9,7 +9,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class QuerySideAccountConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.ac
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -22,17 +20,7 @@ public class QuerySideDependencyChecker {
|
||||
try {
|
||||
logger.info("Checking mongodb connectivity {}", System.getenv("SPRING_DATA_MONGODB_URI"));
|
||||
|
||||
Observable.<Object>create(new Observable.OnSubscribe<Object>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super Object> subscriber) {
|
||||
try {
|
||||
subscriber.onNext(mongoTemplate.getDb().getCollectionNames());
|
||||
subscriber.onCompleted();
|
||||
} catch (Throwable t) {
|
||||
subscriber.onError(t);
|
||||
}
|
||||
}
|
||||
}).timeout(5, TimeUnit.SECONDS).toBlocking().first();
|
||||
mongoTemplate.getDb().getCollectionNames();
|
||||
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Error connecting to Mongo - have you set SPRING_DATA_MONGODB_URI or --spring.data.mongodb_uri?", e);
|
||||
|
||||
@@ -10,7 +10,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import io.eventuate.javaclient.spring.httpstomp.EventuateHttpStompClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
@Import({QuerySideWebConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({QuerySideWebConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class AccountsQuerySideServiceConfiguration {
|
||||
|
||||
@@ -13,10 +13,10 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import rx.Observable;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
|
||||
@@ -51,8 +51,8 @@ public class AccountsQuerySideServiceIntegrationTest {
|
||||
eventually(
|
||||
new Producer<GetAccountResponse>() {
|
||||
@Override
|
||||
public Observable<GetAccountResponse> produce() {
|
||||
return Observable.just(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
||||
public CompletableFuture<GetAccountResponse> produce() {
|
||||
return CompletableFuture.completedFuture(restTemplate.getForEntity(baseUrl("/accounts/" + fromAccountId), GetAccountResponse.class).getBody());
|
||||
}
|
||||
},
|
||||
new Verifier<GetAccountResponse>() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
|
||||
dependencies {
|
||||
compile project(":accounts-query-side-backend")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
|
||||
|
||||
@@ -1,36 +1,14 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.QuerySideAccountConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
@Configuration
|
||||
@Import({QuerySideAccountConfiguration.class})
|
||||
@ComponentScan
|
||||
public class QuerySideWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
public class QuerySideWebConfiguration {
|
||||
|
||||
class FakeThing {}
|
||||
|
||||
@Bean
|
||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
||||
// https://jira.spring.io/browse/SPR-13083
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
||||
handlers.add(0, new ObservableReturnValueHandler());
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
return new FakeThing();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountInfo;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountNotFoundException;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountQueryService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.AccountTransactionInfo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import rx.Observable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@@ -25,28 +25,25 @@ public class AccountQueryController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/accounts/{accountId}", method = RequestMethod.GET)
|
||||
public Observable<GetAccountResponse> get(@PathVariable String accountId) {
|
||||
return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId))
|
||||
.map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription()));
|
||||
public CompletableFuture<GetAccountResponse> get(@PathVariable String accountId) {
|
||||
return accountInfoQueryService.findByAccountId(accountId)
|
||||
.thenApply(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription()));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/accounts", method = RequestMethod.GET)
|
||||
public Observable<List<GetAccountResponse>> getAccountsForCustomer(@RequestParam("customerId") String customerId) {
|
||||
public CompletableFuture<List<GetAccountResponse>> getAccountsForCustomer(@RequestParam("customerId") String customerId) {
|
||||
return accountInfoQueryService.findByCustomerId(customerId)
|
||||
.map(accountInfoList -> accountInfoList.stream().map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription())).collect(Collectors.toList()));
|
||||
.thenApply(accountInfoList -> accountInfoList.stream().map(accountInfo -> new GetAccountResponse(accountInfo.getId(), new BigDecimal(accountInfo.getBalance()), accountInfo.getTitle(), accountInfo.getDescription())).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/accounts/{accountId}/history", method = RequestMethod.GET)
|
||||
public Observable<List<AccountTransactionInfo>> getTransactionsHistory(@PathVariable String accountId) {
|
||||
return accountInfoQueryService.findByAccountId(new EntityIdentifier(accountId))
|
||||
.map(AccountInfo::getTransactions);
|
||||
public CompletableFuture<List<AccountTransactionInfo>> getTransactionsHistory(@PathVariable String accountId) {
|
||||
return accountInfoQueryService.findByAccountId(accountId)
|
||||
.thenApply(AccountInfo::getTransactions);
|
||||
}
|
||||
|
||||
@ResponseStatus(value= HttpStatus.NOT_FOUND, reason="account not found")
|
||||
@ExceptionHandler(AccountNotFoundException.class)
|
||||
public void accountNotFound() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,13 +3,12 @@ apply plugin: 'spring-boot'
|
||||
|
||||
dependencies {
|
||||
compile project(":common-auth-web")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.apache.httpcomponents:httpclient:4.5"
|
||||
compile "org.apache.httpcomponents:fluent-hc:4.5.1"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.apigateway;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import io.eventuate.javaclient.spring.httpstomp.EventuateHttpStompClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
@@ -27,7 +27,7 @@ import java.util.Collections;
|
||||
@Configuration
|
||||
@ComponentScan
|
||||
@EnableAutoConfiguration
|
||||
@Import({EventStoreHttpClientConfiguration.class, AuthConfiguration.class})
|
||||
@Import({EventuateHttpStompClientConfiguration.class, AuthConfiguration.class})
|
||||
@EnableConfigurationProperties({ApiGatewayProperties.class})
|
||||
public class ApiGatewayServiceConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
|
||||
@@ -10,6 +10,6 @@ dependencies {
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
|
||||
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
||||
import net.chrisrichardson.utils.config.MetricRegistryConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class})
|
||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
|
||||
public class BankingTestConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.EntityWithMetadata;
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.TransferState;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -16,12 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import rx.Observable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
|
||||
@@ -38,7 +34,7 @@ public class MoneyTransferIntegrationTest {
|
||||
private MoneyTransferService moneyTransferService;
|
||||
|
||||
@Autowired
|
||||
private EventStore eventStore;
|
||||
private EventuateAggregateStore eventStore;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -48,52 +44,22 @@ public class MoneyTransferIntegrationTest {
|
||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), ""));
|
||||
|
||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
||||
toAccount.getEntityIdentifier(),
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||
toAccount.getEntityId(),
|
||||
new BigDecimal(80))));
|
||||
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<Account>> produce() {
|
||||
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<Account> account) {
|
||||
Assert.assertEquals(new BigDecimal(70), account.entity().getBalance());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
|
||||
account -> Assert.assertEquals(new BigDecimal(70), account.getEntity().getBalance()));
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<Account>> produce() {
|
||||
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<Account> account) {
|
||||
Assert.assertEquals(new BigDecimal(380), account.entity().getBalance());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(Account.class, toAccount.getEntityId()),
|
||||
account -> Assert.assertEquals(new BigDecimal(380), account.getEntity().getBalance()));
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
|
||||
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
|
||||
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -103,52 +69,22 @@ public class MoneyTransferIntegrationTest {
|
||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), ""));
|
||||
|
||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
||||
toAccount.getEntityIdentifier(),
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||
toAccount.getEntityId(),
|
||||
new BigDecimal(200))));
|
||||
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
|
||||
return (Observable<EntityWithMetadata<MoneyTransfer>>)eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
|
||||
Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.entity().getState());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||
updatedTransaction -> Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.getEntity().getState()));
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<Account>> produce() {
|
||||
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, fromAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<Account> account) {
|
||||
Assert.assertEquals(new BigDecimal(150), account.entity().getBalance());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(Account.class, fromAccount.getEntityId()),
|
||||
account -> Assert.assertEquals(new BigDecimal(150), account.getEntity().getBalance()));
|
||||
|
||||
eventually (
|
||||
new Producer<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<Account>> produce() {
|
||||
return (Observable<EntityWithMetadata<Account>>)eventStore.find(Account.class, toAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<Account>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<Account> account) {
|
||||
Assert.assertEquals(new BigDecimal(300), account.entity().getBalance());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(Account.class, toAccount.getEntityId()),
|
||||
account -> Assert.assertEquals(new BigDecimal(300), account.getEntity().getBalance()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.EntityWithMetadata;
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EntityWithMetadata;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer;
|
||||
@@ -37,7 +37,7 @@ public class AccountQuerySideIntegrationTest {
|
||||
private MoneyTransferService moneyTransferService;
|
||||
|
||||
@Autowired
|
||||
private EventStore eventStore;
|
||||
private EventuateAggregateStore eventStore;
|
||||
|
||||
@Autowired
|
||||
private AccountQueryService accountQueryService;
|
||||
@@ -50,49 +50,19 @@ public class AccountQuerySideIntegrationTest {
|
||||
final EntityWithIdAndVersion<Account> toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), ""));
|
||||
|
||||
final EntityWithIdAndVersion<MoneyTransfer> transaction = await(
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityIdentifier(),
|
||||
toAccount.getEntityIdentifier(),
|
||||
moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(),
|
||||
toAccount.getEntityId(),
|
||||
new BigDecimal(80))));
|
||||
|
||||
eventually(
|
||||
new Producer<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public Observable<EntityWithMetadata<MoneyTransfer>> produce() {
|
||||
return eventStore.find(MoneyTransfer.class, transaction.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<EntityWithMetadata<MoneyTransfer>>() {
|
||||
@Override
|
||||
public void verify(EntityWithMetadata<MoneyTransfer> updatedTransaction) {
|
||||
Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.entity().getState());
|
||||
}
|
||||
});
|
||||
() -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()),
|
||||
updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState()));
|
||||
|
||||
eventually(
|
||||
new Producer<AccountInfo>() {
|
||||
@Override
|
||||
public Observable<AccountInfo> produce() {
|
||||
return accountQueryService.findByAccountId(fromAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<AccountInfo>() {
|
||||
@Override
|
||||
public void verify(AccountInfo accountInfo) {
|
||||
Assert.assertEquals(70*100, accountInfo.getBalance());
|
||||
}
|
||||
});
|
||||
() -> accountQueryService.findByAccountId(fromAccount.getEntityId()),
|
||||
accountInfo -> Assert.assertEquals(70*100, accountInfo.getBalance()));
|
||||
eventually(
|
||||
new Producer<AccountInfo>() {
|
||||
@Override
|
||||
public Observable<AccountInfo> produce() {
|
||||
return accountQueryService.findByAccountId(toAccount.getEntityIdentifier());
|
||||
}
|
||||
},
|
||||
new Verifier<AccountInfo>() {
|
||||
@Override
|
||||
public void verify(AccountInfo accountInfo) {
|
||||
Assert.assertEquals(380*100, accountInfo.getBalance());
|
||||
}
|
||||
});
|
||||
() -> accountQueryService.findByAccountId(toAccount.getEntityId()),
|
||||
accountInfo -> Assert.assertEquals(380*100, accountInfo.getBalance()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts;
|
||||
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.AccountConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
|
||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideAccountConfiguration.class})
|
||||
@Import({AccountConfiguration.class, MoneyTransferConfiguration.class, EventuateJdbcEventStoreConfiguration.class,
|
||||
QuerySideAccountConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
public class AccountQuerySideTestConfiguration {
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.Customer;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.*;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import org.junit.Assert;
|
||||
@@ -14,7 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.await;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
@@ -36,7 +39,7 @@ public class CustomerQuerySideIntegrationTest {
|
||||
private CustomerQueryService customerQueryService;
|
||||
|
||||
@Autowired
|
||||
private EventStore eventStore;
|
||||
private EventuateAggregateStore eventStore;
|
||||
|
||||
@Test
|
||||
public void shouldCreateCustomerAndAddToAccount() throws Exception {
|
||||
@@ -44,13 +47,13 @@ public class CustomerQuerySideIntegrationTest {
|
||||
EntityWithIdAndVersion<Customer> customer = await(customerService.createCustomer(customerInfo));
|
||||
|
||||
ToAccountInfo toAccountInfo = generateToAccountInfo();
|
||||
EntityWithIdAndVersion<Customer> customerWithNewAccount = await(customerService.addToAccount(customer.getEntityIdentifier().getId(), toAccountInfo));
|
||||
EntityWithIdAndVersion<Customer> customerWithNewAccount = await(customerService.addToAccount(customer.getEntityId(), toAccountInfo));
|
||||
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return customerQueryService.findByCustomerId(customer.getEntityIdentifier());
|
||||
public CompletableFuture<QuerySideCustomer> produce() {
|
||||
return customerQueryService.findByCustomerId(customer.getEntityId());
|
||||
}
|
||||
},
|
||||
new Verifier<QuerySideCustomer>() {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Configuration
|
||||
@Import({CustomerConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideCustomerConfiguration.class})
|
||||
@Import({CustomerConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideCustomerConfiguration.class})
|
||||
public class CustomerQuerySideTestConfiguration {
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
compile project(":common-auth")
|
||||
compile project(":common-customers")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-security:$springBootVersion"
|
||||
|
||||
@@ -2,11 +2,12 @@ apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile project(":common-customers")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Aggregate;
|
||||
|
||||
import io.eventuate.Event;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class AccountChangedEvent implements Event {
|
||||
protected BigDecimal amount;
|
||||
protected EntityIdentifier transactionId;
|
||||
protected String transactionId;
|
||||
|
||||
public AccountChangedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
||||
public AccountChangedEvent(BigDecimal amount, String transactionId) {
|
||||
this.amount = amount;
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class AccountChangedEvent implements Event {
|
||||
public AccountChangedEvent() {
|
||||
}
|
||||
|
||||
public EntityIdentifier getTransactionId() {
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import io.eventuate.Aggregate;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class AccountCreditedEvent extends AccountChangedEvent {
|
||||
private AccountCreditedEvent() {
|
||||
}
|
||||
|
||||
public AccountCreditedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
||||
public AccountCreditedEvent(BigDecimal amount, String transactionId) {
|
||||
super(amount, transactionId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Aggregate;
|
||||
|
||||
import io.eventuate.Event;
|
||||
|
||||
public class AccountDebitFailedDueToInsufficientFundsEvent implements Event {
|
||||
private EntityIdentifier transactionId;
|
||||
private String transactionId;
|
||||
|
||||
private AccountDebitFailedDueToInsufficientFundsEvent() {
|
||||
}
|
||||
|
||||
public AccountDebitFailedDueToInsufficientFundsEvent(EntityIdentifier transactionId) {
|
||||
public AccountDebitFailedDueToInsufficientFundsEvent(String transactionId) {
|
||||
this.transactionId = transactionId;
|
||||
}
|
||||
|
||||
public EntityIdentifier getTransactionId() {
|
||||
public String getTransactionId() {
|
||||
return transactionId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import io.eventuate.Aggregate;
|
||||
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class AccountDebitedEvent extends AccountChangedEvent {
|
||||
private AccountDebitedEvent() {
|
||||
}
|
||||
|
||||
public AccountDebitedEvent(BigDecimal amount, EntityIdentifier transactionId) {
|
||||
public AccountDebitedEvent(BigDecimal amount, String transactionId) {
|
||||
super(amount, transactionId);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
|
||||
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.accounts.Account")
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts;
|
||||
@@ -1,7 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.EventEntity;
|
||||
|
||||
import io.eventuate.Event;
|
||||
import io.eventuate.EventEntity;
|
||||
|
||||
/**
|
||||
* Created by Main on 11.02.2016.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
|
||||
public class CreditRecordedEvent implements Event {
|
||||
private TransferDetails details;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
// import io.eventuate.Event;
|
||||
|
||||
import io.eventuate.Event;
|
||||
|
||||
public class DebitRecordedEvent implements Event {
|
||||
private TransferDetails details;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
|
||||
public class FailedDebitRecordedEvent implements Event {
|
||||
private TransferDetails details;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
|
||||
public class MoneyTransferCreatedEvent implements Event {
|
||||
private TransferDetails details;
|
||||
|
||||
@@ -4,15 +4,14 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.trans
|
||||
case class TransferDetails(fromAccountId : EntityIdentifier, toAccountId : EntityIdentifier, amount : BigDecimal)
|
||||
*/
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
public class TransferDetails {
|
||||
|
||||
private EntityIdentifier fromAccountId;
|
||||
private EntityIdentifier toAccountId;
|
||||
private String fromAccountId;
|
||||
private String toAccountId;
|
||||
private BigDecimal amount;
|
||||
private Date date;
|
||||
private String description;
|
||||
@@ -20,11 +19,11 @@ public class TransferDetails {
|
||||
private TransferDetails() {
|
||||
}
|
||||
|
||||
public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount) {
|
||||
public TransferDetails(String fromAccountId, String toAccountId, BigDecimal amount) {
|
||||
this(fromAccountId, toAccountId, amount, new Date(), "");
|
||||
}
|
||||
|
||||
public TransferDetails(EntityIdentifier fromAccountId, EntityIdentifier toAccountId, BigDecimal amount, Date date, String description) {
|
||||
public TransferDetails(String fromAccountId, String toAccountId, BigDecimal amount, Date date, String description) {
|
||||
this.fromAccountId = fromAccountId;
|
||||
this.toAccountId = toAccountId;
|
||||
this.amount = amount;
|
||||
@@ -32,11 +31,11 @@ public class TransferDetails {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public EntityIdentifier getFromAccountId() {
|
||||
public String getFromAccountId() {
|
||||
return fromAccountId;
|
||||
}
|
||||
|
||||
public EntityIdentifier getToAccountId() {
|
||||
public String getToAccountId() {
|
||||
return toAccountId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
@net.chrisrichardson.eventstore.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
|
||||
@io.eventuate.EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransfer")
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions;
|
||||
@@ -1,23 +1,21 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.common.accounts;
|
||||
|
||||
|
||||
import io.eventuate.javaclient.commonimpl.JSonMapper;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountOpenedEvent;
|
||||
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
|
||||
import net.chrisrichardson.utils.json.JSonMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
public class AccountOpenEventSerializationTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldSerde() {
|
||||
|
||||
AccountOpenedEvent event = new AccountOpenedEvent("00000000-00000000", "My Account", new BigDecimal(55), "");
|
||||
String json = JSonMapper.toJson(event, EventStoreCommonObjectMapping.getObjectMapper());
|
||||
String json = JSonMapper.toJson(event);
|
||||
System.out.println("json=" + json);
|
||||
|
||||
AccountOpenedEvent event2 = JSonMapper.fromJSon(AccountOpenedEvent.class, json, EventStoreCommonObjectMapping.getObjectMapper());
|
||||
AccountOpenedEvent event2 = JSonMapper.fromJson(json, AccountOpenedEvent.class);
|
||||
|
||||
Assert.assertEquals(event.getInitialBalance(), event2.getInitialBalance());
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
dependencies {
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
compile "io.springfox:springfox-swagger2:2.2.2"
|
||||
compile 'io.springfox:springfox-swagger-ui:2.2.2'
|
||||
|
||||
@@ -6,14 +6,14 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import rx.Observable;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.schema.WildcardType;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static springfox.documentation.schema.AlternateTypeRules.newRule;
|
||||
|
||||
@Configuration
|
||||
@@ -27,7 +27,7 @@ public class CommonSwaggerConfiguration {
|
||||
.apis(RequestHandlerSelectors.basePackage("net.chrisrichardson.eventstore.javaexamples.banking"))
|
||||
.build()
|
||||
.pathMapping("/")
|
||||
.genericModelSubstitutes(ResponseEntity.class, Observable.class)
|
||||
.genericModelSubstitutes(ResponseEntity.class, CompletableFuture.class)
|
||||
.alternateTypeRules(
|
||||
newRule(typeResolver.resolve(DeferredResult.class,
|
||||
typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
|
||||
testCompile "junit:junit:4.11"
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
|
||||
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public class DeferredUtils {
|
||||
|
||||
public static <T> DeferredResult<T> toDeferredResult(Observable<T> o) {
|
||||
final DeferredResult<T> d = new DeferredResult<T>();
|
||||
final AtomicReference<T> r = new AtomicReference<T>();
|
||||
|
||||
o.single().subscribe(new Subscriber<T>() {
|
||||
@Override
|
||||
public void onCompleted() {
|
||||
d.setResult(r.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
d.setErrorResult(e);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(T t) {
|
||||
r.set(t);
|
||||
}
|
||||
});
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.util;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.springframework.web.context.request.async.WebAsyncUtils;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
|
||||
|
||||
public class ObservableReturnValueHandler implements HandlerMethodReturnValueHandler {
|
||||
|
||||
@Override
|
||||
public boolean supportsReturnType(MethodParameter returnType) {
|
||||
return Observable.class.isAssignableFrom(returnType.getParameterType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer,
|
||||
NativeWebRequest webRequest) throws Exception {
|
||||
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
DeferredResult<?> d = DeferredUtils.toDeferredResult((Observable<?>) returnValue);
|
||||
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(d, mavContainer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,10 +3,10 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
compile project(":common-customers")
|
||||
compile project(":common-backend")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.EventUtil;
|
||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
||||
import io.eventuate.Event;
|
||||
import io.eventuate.EventUtil;
|
||||
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerAddedToAccount;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.Command;
|
||||
import io.eventuate.Command;
|
||||
|
||||
interface CustomerCommand extends Command {
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class CustomerConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -16,7 +16,7 @@ public class CustomerConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AggregateRepository<Customer, CustomerCommand> customerRepository(EventStore eventStore) {
|
||||
public AggregateRepository<Customer, CustomerCommand> customerRepository(EventuateAggregateStore eventStore) {
|
||||
return new AggregateRepository<Customer, CustomerCommand>(Customer.class, eventStore);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CustomerService {
|
||||
|
||||
@@ -15,12 +16,11 @@ public class CustomerService {
|
||||
this.accountRepository = accountRepository;
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> createCustomer(CustomerInfo customerInfo) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<Customer>> createCustomer(CustomerInfo customerInfo) {
|
||||
return accountRepository.save(new CreateCustomerCommand(customerInfo));
|
||||
}
|
||||
|
||||
public rx.Observable<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, ToAccountInfo toAccountInfo) {
|
||||
return accountRepository.update(new EntityIdentifier(customerId), new AddToAccountCommand(toAccountInfo));
|
||||
public CompletableFuture<EntityWithIdAndVersion<Customer>> addToAccount(String customerId, ToAccountInfo toAccountInfo) {
|
||||
return accountRepository.update(customerId, new AddToAccountCommand(toAccountInfo));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.CommandProcessingAggregates;
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import io.eventuate.Event;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerInfo;
|
||||
import org.junit.Assert;
|
||||
@@ -19,7 +18,7 @@ public class CustomerTest {
|
||||
|
||||
CustomerInfo customerInfo = generateCustomerInfo();
|
||||
|
||||
List<Event> events = CommandProcessingAggregates.processToList(customer, new CreateCustomerCommand(customerInfo));
|
||||
List<Event> events = customer.process(new CreateCustomerCommand(customerInfo));
|
||||
|
||||
Assert.assertEquals(1, events.size());
|
||||
Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass());
|
||||
|
||||
@@ -10,7 +10,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import io.eventuate.javaclient.spring.httpstomp.EventuateHttpStompClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CustomersCommandSideWebConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
@Import({CustomersCommandSideWebConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({CustomersCommandSideWebConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class CustomersCommandSideServiceConfiguration {
|
||||
|
||||
@@ -3,10 +3,9 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
compile project(":common-customers")
|
||||
compile project(":customers-command-side-backend")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAc
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 03.02.16.
|
||||
@@ -25,15 +26,15 @@ public class CustomerController {
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.POST)
|
||||
public Observable<CustomerResponse> createCustomer(@Validated @RequestBody CustomerInfo customer) {
|
||||
public CompletableFuture<CustomerResponse> createCustomer(@Validated @RequestBody CustomerInfo customer) {
|
||||
return customerService.createCustomer(customer)
|
||||
.map(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityIdentifier().getId(), customer));
|
||||
.thenApply(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityId(), customer));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST)
|
||||
public Observable<AddToAccountResponse> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) {
|
||||
public CompletableFuture<AddToAccountResponse> addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) {
|
||||
return customerService.addToAccount(id, request)
|
||||
.map(entityAndEventInfo -> new AddToAccountResponse(entityAndEventInfo.entityVersion().asString()));
|
||||
.thenApply(entityAndEventInfo -> new AddToAccountResponse(entityAndEventInfo.getEntityVersion().toString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.CustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by popikyardo on 03.02.16.
|
||||
@@ -21,14 +14,4 @@ import java.util.List;
|
||||
@ComponentScan
|
||||
public class CustomersCommandSideWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
class FakeThing {}
|
||||
|
||||
@Bean
|
||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
||||
// https://jira.spring.io/browse/SPR-13083
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
||||
handlers.add(0, new ObservableReturnValueHandler());
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
return new FakeThing();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
compile project(":common-backend")
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-data-mongodb:$springBootVersion"
|
||||
|
||||
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
|
||||
@@ -13,6 +13,6 @@ dependencies {
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import io.eventuate.CompletableFutureUtil;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CustomerQueryService {
|
||||
|
||||
@@ -15,19 +15,19 @@ public class CustomerQueryService {
|
||||
this.querySideCustomerRepository = querySideCustomerRepository;
|
||||
}
|
||||
|
||||
public Observable<QuerySideCustomer> findByCustomerId(EntityIdentifier customerId) {
|
||||
QuerySideCustomer customer = querySideCustomerRepository.findOne(customerId.getId());
|
||||
public CompletableFuture<QuerySideCustomer> findByCustomerId(String customerId) {
|
||||
QuerySideCustomer customer = querySideCustomerRepository.findOne(customerId);
|
||||
if (customer == null)
|
||||
return Observable.error(new EmptyResultDataAccessException(1));
|
||||
return CompletableFutureUtil.failedFuture(new EmptyResultDataAccessException(1));
|
||||
else
|
||||
return Observable.just(customer);
|
||||
return CompletableFuture.completedFuture(customer);
|
||||
}
|
||||
|
||||
public Observable<List<QuerySideCustomer>> findByEmail(String email){
|
||||
public CompletableFuture<List<QuerySideCustomer>> findByEmail(String email){
|
||||
List<QuerySideCustomer> customers = querySideCustomerRepository.findByEmailLike(email);
|
||||
if (customers.isEmpty())
|
||||
return Observable.error(new EmptyResultDataAccessException(1));
|
||||
return CompletableFutureUtil.failedFuture(new EmptyResultDataAccessException(1));
|
||||
else
|
||||
return Observable.just(customers);
|
||||
return CompletableFuture.completedFuture(customers);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
|
||||
import io.eventuate.DispatchedEvent;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerAddedToAccount;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.customers.CustomerCreatedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAccountInfo;
|
||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
||||
import net.chrisrichardson.eventstore.subscriptions.DispatchedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import rx.Observable;
|
||||
|
||||
/**
|
||||
* Created by Main on 04.02.2016.
|
||||
*/
|
||||
@EventSubscriber(id = "customerQuerySideEventHandlers")
|
||||
public class CustomerQueryWorkflow implements CompoundEventHandler {
|
||||
public class CustomerQueryWorkflow {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@@ -27,23 +25,21 @@ public class CustomerQueryWorkflow implements CompoundEventHandler {
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> create(DispatchedEvent<CustomerCreatedEvent> de) {
|
||||
CustomerCreatedEvent event = de.event();
|
||||
String id = de.getEntityIdentifier().getId();
|
||||
public void create(DispatchedEvent<CustomerCreatedEvent> de) {
|
||||
CustomerCreatedEvent event = de.getEvent();
|
||||
String id = de.getEntityId();
|
||||
|
||||
customerInfoUpdateService.create(id, event.getCustomerInfo());
|
||||
return Observable.just(null);
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<Object> addToAccount(DispatchedEvent<CustomerAddedToAccount> de) {
|
||||
CustomerAddedToAccount event = de.event();
|
||||
String id = de.getEntityIdentifier().getId();
|
||||
public void addToAccount(DispatchedEvent<CustomerAddedToAccount> de) {
|
||||
CustomerAddedToAccount event = de.getEvent();
|
||||
String id = de.getEntityId();
|
||||
|
||||
ToAccountInfo toAccountInfo = event.getToAccountInfo();
|
||||
|
||||
customerInfoUpdateService.addToAccount(id, toAccountInfo);
|
||||
return Observable.just(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
@@ -11,7 +11,7 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie
|
||||
*/
|
||||
@Configuration
|
||||
@EnableMongoRepositories
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class QuerySideCustomerConfiguration {
|
||||
@Bean
|
||||
public CustomerQueryWorkflow customerQueryWorkflow(CustomerInfoUpdateService accountInfoUpdateService) {
|
||||
|
||||
@@ -3,8 +3,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.cu
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -22,17 +20,7 @@ public class QuerySideDependencyChecker {
|
||||
try {
|
||||
logger.info("Checking mongodb connectivity {}", System.getenv("SPRING_DATA_MONGODB_URI"));
|
||||
|
||||
Observable.<Object>create(new Observable.OnSubscribe<Object>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super Object> subscriber) {
|
||||
try {
|
||||
subscriber.onNext(mongoTemplate.getDb().getCollectionNames());
|
||||
subscriber.onCompleted();
|
||||
} catch (Throwable t) {
|
||||
subscriber.onError(t);
|
||||
}
|
||||
}
|
||||
}).timeout(5, TimeUnit.SECONDS).toBlocking().first();
|
||||
mongoTemplate.getDb().getCollectionNames();
|
||||
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Error connecting to Mongo - have you set SPRING_DATA_MONGODB_URI or --spring.data.mongodb_uri?", e);
|
||||
|
||||
@@ -10,7 +10,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile project(":customers-command-side-service")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.client.config.EventStoreHttpClientConfiguration;
|
||||
import io.eventuate.javaclient.spring.httpstomp.EventuateHttpStompClientConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
@@ -13,7 +13,7 @@ import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
@Configuration
|
||||
@Import({QuerySideCustomerConfiguration.class, EventStoreHttpClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({QuerySideCustomerConfiguration.class, EventuateHttpStompClientConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class CustomersQuerySideServiceConfiguration {
|
||||
|
||||
@@ -2,7 +2,6 @@ apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile project(":customers-query-side-backend")
|
||||
compile project(":common-web")
|
||||
|
||||
compile "org.springframework.boot:spring-boot-starter-web:$springBootVersion"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator:$springBootVersion"
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityIdentifier;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.CustomerQueryService;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* Created by Main on 05.02.2016.
|
||||
@@ -25,14 +23,14 @@ public class CustomerQueryController {
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/customers/{customerId}", method = RequestMethod.GET)
|
||||
public Observable<QuerySideCustomer> getCustomer(@PathVariable String customerId) {
|
||||
return customerQueryService.findByCustomerId(new EntityIdentifier(customerId));
|
||||
public CompletableFuture<QuerySideCustomer> getCustomer(@PathVariable String customerId) {
|
||||
return customerQueryService.findByCustomerId(customerId);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/customers", method = RequestMethod.GET)
|
||||
public Observable<CustomersQueryResponse> getCustomersByEmail(@RequestParam String email) {
|
||||
public CompletableFuture<CustomersQueryResponse> getCustomersByEmail(@RequestParam String email) {
|
||||
return customerQueryService.findByEmail(email)
|
||||
.map(this::getCustomersQueryResponse);
|
||||
.thenApply(this::getCustomersQueryResponse);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.CustomerResponse;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,33 +1,13 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers.QuerySideCustomerConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.util.ObservableReturnValueHandler;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@Import({QuerySideCustomerConfiguration.class})
|
||||
@ComponentScan
|
||||
public class CustomersQuerySideWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
class FakeThing {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public FakeThing init(RequestMappingHandlerAdapter adapter) {
|
||||
// https://jira.spring.io/browse/SPR-13083
|
||||
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>(adapter.getReturnValueHandlers());
|
||||
handlers.add(0, new ObservableReturnValueHandler());
|
||||
adapter.setReturnValueHandlers(handlers);
|
||||
return new FakeThing();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
apply plugin: VerifyMongoDBConfigurationPlugin
|
||||
|
||||
dependencies {
|
||||
compile "org.scala-lang:scala-library:2.10.2"
|
||||
|
||||
testCompile project(":accounts-command-side-web")
|
||||
testCompile project(":transactions-command-side-web")
|
||||
testCompile project(":accounts-query-side-web")
|
||||
@@ -11,8 +9,6 @@ dependencies {
|
||||
testCompile project(":common-auth")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile scalaTestDependency
|
||||
|
||||
}
|
||||
|
||||
test {
|
||||
|
||||
@@ -10,7 +10,6 @@ import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accou
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferRequest;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CreateMoneyTransferResponse;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.accounts.GetAccountResponse;
|
||||
import net.chrisrichardson.eventstore.json.EventStoreCommonObjectMapping;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Producer;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils;
|
||||
@@ -19,13 +18,12 @@ import org.junit.Test;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
@@ -61,18 +59,7 @@ public class EndToEndTest {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
CustomersTestUtils customersTestUtils;
|
||||
|
||||
{
|
||||
|
||||
for (HttpMessageConverter<?> mc : restTemplate.getMessageConverters()) {
|
||||
if (mc instanceof MappingJackson2HttpMessageConverter) {
|
||||
((MappingJackson2HttpMessageConverter) mc).setObjectMapper(EventStoreCommonObjectMapping.getObjectMapper());
|
||||
}
|
||||
}
|
||||
|
||||
customersTestUtils = new CustomersTestUtils(restTemplate, customersQuerySideBaseUrl("/customers/"));
|
||||
}
|
||||
CustomersTestUtils customersTestUtils = new CustomersTestUtils(restTemplate, customersQuerySideBaseUrl("/customers/"));
|
||||
|
||||
|
||||
@Test
|
||||
@@ -181,8 +168,8 @@ public class EndToEndTest {
|
||||
eventually(
|
||||
new Producer<GetAccountResponse>() {
|
||||
@Override
|
||||
public Observable<GetAccountResponse> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
public CompletableFuture<GetAccountResponse> produce() {
|
||||
return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
accountsQuerySideBaseUrl("/accounts/" + fromAccountId),
|
||||
HttpMethod.GET,
|
||||
GetAccountResponse.class));
|
||||
|
||||
@@ -3,8 +3,7 @@ org.gradle.jvmargs=-XX:MaxPermSize=512m
|
||||
|
||||
eventuateMavenRepoUrl=http://mavenrepo.eventuate.io/release
|
||||
|
||||
scalaTestDependency=org.scalatest:scalatest_2.10:2.0
|
||||
springBootVersion=1.3.5.RELEASE
|
||||
|
||||
springBootVersion=1.2.8.RELEASE
|
||||
eventuateClientVersion=0.2.0.RELEASE
|
||||
|
||||
eventStoreClientVersion=0.12
|
||||
|
||||
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-all.zip
|
||||
distributionUrl=http\://services.gradle.org/distributions/gradle-2.11-all.zip
|
||||
|
||||
@@ -14,7 +14,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil-customers")
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
@@ -2,12 +2,12 @@ package net.chrisrichardson.eventstore.javaexamples.banking.web;
|
||||
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonauth.AuthConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.commonswagger.CommonSwaggerConfiguration;
|
||||
import io.eventuate.javaclient.spring.jdbc.EventuateJdbcEventStoreConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.accounts.CommandSideWebAccountsConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.customers.CustomersCommandSideWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions.CommandSideWebTransactionsConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.customers.queryside.CustomersQuerySideWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.web.queryside.QuerySideWebConfiguration;
|
||||
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -20,7 +20,7 @@ import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@Import({CommandSideWebAccountsConfiguration.class, CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class, QuerySideWebConfiguration.class, CustomersQuerySideWebConfiguration.class, CustomersCommandSideWebConfiguration.class, AuthConfiguration.class, CommonSwaggerConfiguration.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan
|
||||
public class BankingWebConfiguration extends WebMvcConfigurerAdapter {
|
||||
|
||||
@@ -24,12 +24,11 @@ import org.springframework.http.HttpMethod;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateCustomerInfo;
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.customers.CustomersTestUtils.generateToAccountInfo;
|
||||
@@ -91,7 +90,6 @@ public class BankingWebIntegrationTest {
|
||||
assertAccountBalance(fromAccountId, initialFromAccountBalance);
|
||||
assertAccountBalance(toAccountId, initialToAccountBalance);
|
||||
|
||||
|
||||
final CreateMoneyTransferResponse moneyTransfer = BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/transfers"),
|
||||
HttpMethod.POST,
|
||||
@@ -180,11 +178,11 @@ public class BankingWebIntegrationTest {
|
||||
eventually(
|
||||
new Producer<GetAccountResponse>() {
|
||||
@Override
|
||||
public Observable<GetAccountResponse> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/accounts/" + fromAccountId),
|
||||
HttpMethod.GET,
|
||||
GetAccountResponse.class));
|
||||
public CompletableFuture<GetAccountResponse> produce() {
|
||||
return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/accounts/" + fromAccountId),
|
||||
HttpMethod.GET,
|
||||
GetAccountResponse.class));
|
||||
}
|
||||
},
|
||||
new Verifier<GetAccountResponse>() {
|
||||
@@ -200,8 +198,8 @@ public class BankingWebIntegrationTest {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
public CompletableFuture<QuerySideCustomer> produce() {
|
||||
return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
baseUrl("/customers/" + customerId),
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
@@ -215,5 +213,4 @@ public class BankingWebIntegrationTest {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
include 'testutil'
|
||||
include 'common-web'
|
||||
include 'common-swagger'
|
||||
|
||||
include 'common-backend'
|
||||
|
||||
@@ -4,5 +4,7 @@ dependencies {
|
||||
compile project(":testutil")
|
||||
compile project(":common-auth")
|
||||
compile project(":common-customers")
|
||||
|
||||
compile "io.reactivex:rxjava:1.1.5"
|
||||
compile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import net.chrisrichardson.eventstorestore.javaexamples.testutil.Verifier;
|
||||
import org.junit.Assert;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil.eventually;
|
||||
|
||||
@@ -28,8 +29,8 @@ public class CustomersTestUtils {
|
||||
eventually(
|
||||
new Producer<QuerySideCustomer>() {
|
||||
@Override
|
||||
public Observable<QuerySideCustomer> produce() {
|
||||
return Observable.just(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
public CompletableFuture<QuerySideCustomer> produce() {
|
||||
return CompletableFuture.completedFuture(BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate,
|
||||
customersBaseUrl + customerId,
|
||||
HttpMethod.GET,
|
||||
QuerySideCustomer.class));
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
apply plugin: 'java'
|
||||
|
||||
dependencies {
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
compile 'com.fasterxml.jackson.core:jackson-core:2.4.3'
|
||||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3'
|
||||
compile 'com.fasterxml.jackson.module:jackson-module-scala_2.10:2.4.3'
|
||||
compile "junit:junit:4.11"
|
||||
compile "io.reactivex:rxjava:1.1.5"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||
|
||||
import net.chrisrichardson.eventstore.Aggregate;
|
||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventEntityUtil;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import io.eventuate.Aggregate;
|
||||
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||
import io.eventuate.javaclient.spring.EventEntityUtil;
|
||||
import org.junit.Test;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@@ -17,19 +17,15 @@ public abstract class AbstractEntityEventTest {
|
||||
@Override
|
||||
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
|
||||
Class eventClass = method.getParameterTypes()[0];
|
||||
String entityClassName = EventEntityUtil.entityClassFor(eventClass);
|
||||
try {
|
||||
Class.forName(entityClassName);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException("for " + entityClassName, e);
|
||||
}
|
||||
|
||||
EventEntityUtil.toEntityType(eventClass);
|
||||
}
|
||||
},
|
||||
new ReflectionUtils.MethodFilter() {
|
||||
@Override
|
||||
public boolean matches(Method method) {
|
||||
return method.getName().startsWith("apply") && method.getDeclaringClass() != Aggregate.class && method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
|
||||
return method.getName().startsWith("apply") &&
|
||||
method.getDeclaringClass() != Aggregate.class &&
|
||||
method.getDeclaringClass() != ReflectiveMutableCommandProcessingAggregate.class;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||
|
||||
import rx.Observable;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface Producer<T> {
|
||||
public Observable<T> produce();
|
||||
public CompletableFuture<T> produce();
|
||||
}
|
||||
|
||||
@@ -1,16 +1,25 @@
|
||||
package net.chrisrichardson.eventstorestore.javaexamples.testutil;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Subscriber;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.functions.Func2;
|
||||
import rx.internal.operators.OnSubscribeRefCount;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class TestUtil {
|
||||
|
||||
public static <T> T await(Observable<T> o) {
|
||||
return o.single().timeout(1, TimeUnit.SECONDS).toBlocking().getIterator().next();
|
||||
public static <T> T await(CompletableFuture<T> o) {
|
||||
try {
|
||||
return o.get(1, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | TimeoutException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +61,7 @@ public class TestUtil {
|
||||
@Override
|
||||
public Observable<Outcome<T>> call(Long aLong) {
|
||||
try {
|
||||
return producer.produce().map(new Func1<T, Outcome<T>>() {
|
||||
return fromCompletableFuture(producer.produce()).map(new Func1<T, Outcome<T>>() {
|
||||
@Override
|
||||
public Outcome<T> call(T t) {
|
||||
return new Success<T>(t);
|
||||
@@ -92,4 +101,21 @@ public class TestUtil {
|
||||
throw new RuntimeException((Throwable)possibleException);
|
||||
}
|
||||
|
||||
private static <T> Observable<T> fromCompletableFuture(CompletableFuture<T> future) {
|
||||
return Observable.create(new Observable.OnSubscribe<T>() {
|
||||
@Override
|
||||
public void call(Subscriber<? super T> subscriber) {
|
||||
future.handle((result, throwable) -> {
|
||||
if (throwable != null)
|
||||
subscriber.onError(throwable);
|
||||
else {
|
||||
subscriber.onNext(result);
|
||||
subscriber.onCompleted();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@ apply plugin: 'java'
|
||||
dependencies {
|
||||
|
||||
compile project(":common-backend")
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-java-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile project(":testutil")
|
||||
testCompile "junit:junit:4.11"
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test:$springBootVersion"
|
||||
testCompile "net.chrisrichardson.eventstore.client:eventstore-jdbc_2.10:$eventStoreClientVersion"
|
||||
testCompile "io.eventuate.client.java:eventuate-client-java-jdbc:$eventuateClientVersion"
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Event;
|
||||
import net.chrisrichardson.eventstore.EventUtil;
|
||||
import net.chrisrichardson.eventstore.ReflectiveMutableCommandProcessingAggregate;
|
||||
import io.eventuate.Event;
|
||||
import io.eventuate.EventUtil;
|
||||
import io.eventuate.ReflectiveMutableCommandProcessingAggregate;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.Command;
|
||||
import io.eventuate.Command;
|
||||
|
||||
interface MoneyTransferCommand extends Command {
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.EventStore;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import net.chrisrichardson.eventstore.subscriptions.*;
|
||||
import net.chrisrichardson.eventstore.subscriptions.config.EventStoreSubscriptionsConfiguration;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EventuateAggregateStore;
|
||||
import io.eventuate.javaclient.spring.EnableEventHandlers;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EnableJavaEventHandlers;
|
||||
|
||||
@Configuration
|
||||
@Import(EventStoreSubscriptionsConfiguration.class)
|
||||
@EnableJavaEventHandlers
|
||||
@EnableEventHandlers
|
||||
public class MoneyTransferConfiguration {
|
||||
|
||||
@Bean
|
||||
@@ -25,7 +22,7 @@ public class MoneyTransferConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventStore eventStore) {
|
||||
public AggregateRepository<MoneyTransfer, MoneyTransferCommand> moneyTransferRepository(EventuateAggregateStore eventStore) {
|
||||
return new AggregateRepository<MoneyTransfer, MoneyTransferCommand>(MoneyTransfer.class, eventStore);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
import net.chrisrichardson.eventstore.EntityWithIdAndVersion;
|
||||
import io.eventuate.AggregateRepository;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
|
||||
import net.chrisrichardson.eventstore.repository.AggregateRepository;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class MoneyTransferService {
|
||||
private final AggregateRepository<MoneyTransfer, MoneyTransferCommand> aggregateRepository;
|
||||
@@ -12,7 +13,7 @@ public class MoneyTransferService {
|
||||
this.aggregateRepository = aggregateRepository;
|
||||
}
|
||||
|
||||
public Observable<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> transferMoney(TransferDetails transferDetails) {
|
||||
return aggregateRepository.save(new CreateMoneyTransferCommand(transferDetails));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
package net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions;
|
||||
|
||||
|
||||
import net.chrisrichardson.eventstore.javaapi.consumer.EventHandlerContext;
|
||||
import io.eventuate.EntityWithIdAndVersion;
|
||||
import io.eventuate.EventHandlerContext;
|
||||
import io.eventuate.EventHandlerMethod;
|
||||
import io.eventuate.EventSubscriber;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountCreditedEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitFailedDueToInsufficientFundsEvent;
|
||||
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts.AccountDebitedEvent;
|
||||
import net.chrisrichardson.eventstore.subscriptions.CompoundEventHandler;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventHandlerMethod;
|
||||
import net.chrisrichardson.eventstore.subscriptions.EventSubscriber;
|
||||
import rx.Observable;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@EventSubscriber(id="transferEventHandlers")
|
||||
public class MoneyTransferWorkflow implements CompoundEventHandler {
|
||||
public class MoneyTransferWorkflow {
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebit(EventHandlerContext<AccountDebitedEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitCommand());
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordDebitFailed(EventHandlerContext<AccountDebitFailedDueToInsufficientFundsEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordDebitFailedCommand());
|
||||
}
|
||||
|
||||
@EventHandlerMethod
|
||||
public Observable<?> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
||||
public CompletableFuture<EntityWithIdAndVersion<MoneyTransfer>> recordCredit(EventHandlerContext<AccountCreditedEvent> ctx) {
|
||||
return ctx.update(MoneyTransfer.class, ctx.getEvent().getTransactionId(), new RecordCreditCommand());
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ dependencies {
|
||||
compile "org.springframework.boot:spring-boot-starter-web"
|
||||
compile "org.springframework.boot:spring-boot-starter-actuator"
|
||||
|
||||
compile "net.chrisrichardson.eventstore.client:eventstore-http-stomp-client_2.10:$eventStoreClientVersion"
|
||||
compile "io.eventuate.client.java:eventuate-client-java-http-stomp-spring:$eventuateClientVersion"
|
||||
|
||||
testCompile "org.springframework.boot:spring-boot-starter-test"
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user