Changed to use the Eventuate Java Client

Simplified Spring MVC code since it supports CompletableFuture
This commit is contained in:
Chris Richardson
2016-05-16 06:27:47 -07:00
parent c5778b1379
commit 4b3fe001e7
73 changed files with 290 additions and 531 deletions

View File

@@ -6,7 +6,7 @@ dependencies {
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"
}

View File

@@ -1,36 +1,13 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferConfiguration;
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({MoneyTransferConfiguration.class})
@ComponentScan
public class CommandSideWebTransactionsConfiguration 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();
}
public class CommandSideWebTransactionsConfiguration {
}

View File

@@ -1,6 +1,6 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import net.chrisrichardson.eventstore.EntityIdentifier;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.transactions.MoneyTransferService;
import net.chrisrichardson.eventstore.javaexamples.banking.backend.common.transactions.TransferDetails;
import org.springframework.beans.factory.annotation.Autowired;
@@ -9,7 +9,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("/transfers")
@@ -23,13 +24,13 @@ public class MoneyTransferController {
}
@RequestMapping(method = RequestMethod.POST)
public Observable<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
public CompletableFuture<CreateMoneyTransferResponse> createMoneyTransfer(@Validated @RequestBody CreateMoneyTransferRequest request) {
TransferDetails transferDetails = new TransferDetails(
new EntityIdentifier(request.getFromAccountId()),
new EntityIdentifier(request.getToAccountId()),
request.getFromAccountId(),
request.getToAccountId(),
request.getAmount());
return moneyTransferService.transferMoney(transferDetails)
.map(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdentifier().getId()));
.thenApply(entityAndEventInfo -> new CreateMoneyTransferResponse(entityAndEventInfo.getEntityIdAndVersion().getEntityId()));
}
}

View File

@@ -1,12 +1,12 @@
package net.chrisrichardson.eventstore.javaexamples.banking.web.commandside.transactions;
import net.chrisrichardson.eventstore.jdbc.config.JdbcEventStoreConfiguration;
import io.eventuate.javaclient.spring.EventuateJdbcEventStoreConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
@Configuration
@Import({CommandSideWebTransactionsConfiguration.class, JdbcEventStoreConfiguration.class})
@Import({CommandSideWebTransactionsConfiguration.class, EventuateJdbcEventStoreConfiguration.class})
@EnableAutoConfiguration
public class MoneyTransferControllerIntegrationTestConfiguration {
}