diff --git a/java-spring/accounts-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/accounts/AccountWorkflow.java b/java-spring/accounts-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/accounts/AccountWorkflow.java index 0813f59..0e0791c 100644 --- a/java-spring/accounts-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/accounts/AccountWorkflow.java +++ b/java-spring/accounts-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/accounts/AccountWorkflow.java @@ -14,37 +14,37 @@ import java.util.concurrent.CompletableFuture; @EventSubscriber(id = "accountEventHandlers") public class AccountWorkflow { - @EventHandlerMethod - public CompletableFuture debitAccount(EventHandlerContext ctx) { - MoneyTransferCreatedEvent event = ctx.getEvent(); - BigDecimal amount = event.getDetails().getAmount(); - String transactionId = ctx.getEntityId(); + @EventHandlerMethod + public CompletableFuture debitAccount(EventHandlerContext ctx) { + MoneyTransferCreatedEvent event = ctx.getEvent(); + BigDecimal amount = event.getDetails().getAmount(); + String transactionId = ctx.getEntityId(); - String fromAccountId = event.getDetails().getFromAccountId(); + String fromAccountId = event.getDetails().getFromAccountId(); - return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId)).handle((x, e) -> { - if (e != null) { - e.printStackTrace(); - } - return x; - } - ); - } + return ctx.update(Account.class, fromAccountId, new DebitAccountCommand(amount, transactionId)).handle((x, e) -> { + if (e != null) { + e.printStackTrace(); + } + return x; + } + ); + } - @EventHandlerMethod - public CompletableFuture> creditAccount(EventHandlerContext ctx) { - DebitRecordedEvent event = ctx.getEvent(); - BigDecimal amount = event.getDetails().getAmount(); - String fromAccountId = event.getDetails().getToAccountId(); - String transactionId = ctx.getEntityId(); + @EventHandlerMethod + public CompletableFuture> creditAccount(EventHandlerContext ctx) { + DebitRecordedEvent event = ctx.getEvent(); + BigDecimal amount = event.getDetails().getAmount(); + String fromAccountId = event.getDetails().getToAccountId(); + String transactionId = ctx.getEntityId(); - return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId)).handle((x, e) -> { - if (e != null) { - e.printStackTrace(); - } - return x; - } - ); - } + return ctx.update(Account.class, fromAccountId, new CreditAccountCommand(amount, transactionId)).handle((x, e) -> { + if (e != null) { + e.printStackTrace(); + } + return x; + } + ); + } } diff --git a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java index af71826..f0a7832 100644 --- a/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java +++ b/java-spring/accounts-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountInfoUpdateService.java @@ -14,7 +14,7 @@ import java.util.Collections; import static net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.accounts.MoneyUtil.toIntegerRepr; import static org.springframework.data.mongodb.core.query.Criteria.where; -public class AccountInfoUpdateService { +public class AccountInfoUpdateService { private Logger logger = LoggerFactory.getLogger(getClass()); private AccountInfoRepository accountInfoRepository; @@ -26,8 +26,7 @@ public class AccountInfoUpdateService { } - - public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, String version) { + public void create(String accountId, String customerId, String title, BigDecimal initialBalance, String description, String version) { try { accountInfoRepository.save(new AccountInfo( accountId, diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayProperties.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayProperties.java index fab5dc3..5db0b20 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayProperties.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayProperties.java @@ -11,50 +11,50 @@ import java.util.List; @ConfigurationProperties(prefix = "api.gateway") public class ApiGatewayProperties { - private List endpoints; + private List endpoints; - public static class Endpoint { - private String path; - private RequestMethod method; - private String location; + public static class Endpoint { + private String path; + private RequestMethod method; + private String location; - public Endpoint() { - } - - public Endpoint(String location) { - this.location = location; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public RequestMethod getMethod() { - return method; - } - - public void setMethod(RequestMethod method) { - this.method = method; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } + public Endpoint() { } - public List getEndpoints() { - return endpoints; + public Endpoint(String location) { + this.location = location; } - public void setEndpoints(List endpoints) { - this.endpoints = endpoints; + public String getPath() { + return path; } + + public void setPath(String path) { + this.path = path; + } + + public RequestMethod getMethod() { + return method; + } + + public void setMethod(RequestMethod method) { + this.method = method; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + } + + public List getEndpoints() { + return endpoints; + } + + public void setEndpoints(List endpoints) { + this.endpoints = endpoints; + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayServiceConfiguration.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayServiceConfiguration.java index 18f1fdc..b01f4dc 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayServiceConfiguration.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/ApiGatewayServiceConfiguration.java @@ -30,20 +30,20 @@ import java.util.Collections; @EnableConfigurationProperties({ApiGatewayProperties.class}) public class ApiGatewayServiceConfiguration extends WebMvcConfigurerAdapter { - @Bean - public RestTemplate restTemplate(HttpMessageConverters converters) { + @Bean + public RestTemplate restTemplate(HttpMessageConverters converters) { - // we have to define Apache HTTP client to use the PATCH verb - MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); - converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/json")); - converter.setObjectMapper(new ObjectMapper()); + // we have to define Apache HTTP client to use the PATCH verb + MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(); + converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/json")); + converter.setObjectMapper(new ObjectMapper()); - HttpClient httpClient = HttpClients.createDefault(); - RestTemplate restTemplate = new RestTemplate(Collections.>singletonList(converter)); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + HttpClient httpClient = HttpClients.createDefault(); + RestTemplate restTemplate = new RestTemplate(Collections.>singletonList(converter)); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); - restTemplate.setErrorHandler(new RestTemplateErrorHandler()); + restTemplate.setErrorHandler(new RestTemplateErrorHandler()); - return restTemplate; - } + return restTemplate; + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestTemplateErrorHandler.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestTemplateErrorHandler.java index 2a4bc31..3a13a71 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestTemplateErrorHandler.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestTemplateErrorHandler.java @@ -10,15 +10,15 @@ import java.io.IOException; public class RestTemplateErrorHandler implements ResponseErrorHandler { - private static final Logger log = LoggerFactory.getLogger(RestTemplateErrorHandler.class); + private static final Logger log = LoggerFactory.getLogger(RestTemplateErrorHandler.class); - @Override - public void handleError(ClientHttpResponse response) throws IOException { - log.error("Response error: {} {}", response.getStatusCode(), response.getStatusText()); - } + @Override + public void handleError(ClientHttpResponse response) throws IOException { + log.error("Response error: {} {}", response.getStatusCode(), response.getStatusText()); + } - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - return RestUtil.isError(response.getStatusCode()); - } + @Override + public boolean hasError(ClientHttpResponse response) throws IOException { + return RestUtil.isError(response.getStatusCode()); + } } \ No newline at end of file diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestUtil.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestUtil.java index bfbd3a7..7e6e9fc 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestUtil.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/RestUtil.java @@ -7,9 +7,9 @@ import org.springframework.http.HttpStatus; */ public class RestUtil { - public static boolean isError(HttpStatus status) { - HttpStatus.Series series = status.series(); - return (HttpStatus.Series.CLIENT_ERROR.equals(series) - || HttpStatus.Series.SERVER_ERROR.equals(series)); - } + public static boolean isError(HttpStatus status) { + HttpStatus.Series series = status.series(); + return (HttpStatus.Series.CLIENT_ERROR.equals(series) + || HttpStatus.Series.SERVER_ERROR.equals(series)); + } } \ No newline at end of file diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/controller/GatewayController.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/controller/GatewayController.java index 64cff3b..a7edbfa 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/controller/GatewayController.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/controller/GatewayController.java @@ -25,7 +25,8 @@ import java.io.InputStreamReader; import java.net.URISyntaxException; import java.util.stream.Collectors; -import static org.springframework.web.bind.annotation.RequestMethod.*; +import static org.springframework.web.bind.annotation.RequestMethod.GET; +import static org.springframework.web.bind.annotation.RequestMethod.POST; /** * Created by popikyardo on 15.01.16. @@ -33,43 +34,43 @@ import static org.springframework.web.bind.annotation.RequestMethod.*; @RestController public class GatewayController { - Logger log = LoggerFactory.getLogger(this.getClass()); + Logger log = LoggerFactory.getLogger(this.getClass()); - @Autowired - private ApiGatewayProperties apiGatewayProperties; + @Autowired + private ApiGatewayProperties apiGatewayProperties; - private HttpClient httpClient; + private HttpClient httpClient; - @PostConstruct - public void init() { - PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + @PostConstruct + public void init() { + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); - httpClient = HttpClients.custom() - .setConnectionManager(cm) - .build(); - } - - @RequestMapping(value = "/**", method = {GET, POST}) - public String proxyRequest(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, IOException, URISyntaxException { - HttpUriRequest proxiedRequest = createHttpUriRequest(request); - log.info("request: {}", proxiedRequest); - HttpResponse proxiedResponse = httpClient.execute(proxiedRequest); - return read(proxiedResponse.getEntity().getContent()); - } - - private HttpUriRequest createHttpUriRequest(HttpServletRequest request) throws URISyntaxException, NoSuchRequestHandlingMethodException, IOException { - URLRequestTransformer urlRequestTransformer = new URLRequestTransformer(apiGatewayProperties); - ContentRequestTransformer contentRequestTransformer = new ContentRequestTransformer(); - HeadersRequestTransformer headersRequestTransformer = new HeadersRequestTransformer(); - headersRequestTransformer.setPredecessor(contentRequestTransformer); - contentRequestTransformer.setPredecessor(urlRequestTransformer); - - return headersRequestTransformer.transform(request).build(); - } - - private String read(InputStream input) throws IOException { - try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) { - return buffer.lines().collect(Collectors.joining("\n")); - } + httpClient = HttpClients.custom() + .setConnectionManager(cm) + .build(); + } + + @RequestMapping(value = "/**", method = {GET, POST}) + public String proxyRequest(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, IOException, URISyntaxException { + HttpUriRequest proxiedRequest = createHttpUriRequest(request); + log.info("request: {}", proxiedRequest); + HttpResponse proxiedResponse = httpClient.execute(proxiedRequest); + return read(proxiedResponse.getEntity().getContent()); + } + + private HttpUriRequest createHttpUriRequest(HttpServletRequest request) throws URISyntaxException, NoSuchRequestHandlingMethodException, IOException { + URLRequestTransformer urlRequestTransformer = new URLRequestTransformer(apiGatewayProperties); + ContentRequestTransformer contentRequestTransformer = new ContentRequestTransformer(); + HeadersRequestTransformer headersRequestTransformer = new HeadersRequestTransformer(); + headersRequestTransformer.setPredecessor(contentRequestTransformer); + contentRequestTransformer.setPredecessor(urlRequestTransformer); + + return headersRequestTransformer.transform(request).build(); + } + + private String read(InputStream input) throws IOException { + try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) { + return buffer.lines().collect(Collectors.joining("\n")); } + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/main/ApiGatewayServiceMain.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/main/ApiGatewayServiceMain.java index cf97357..cc02dc0 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/main/ApiGatewayServiceMain.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/main/ApiGatewayServiceMain.java @@ -7,7 +7,7 @@ import org.springframework.boot.SpringApplication; * Created by Main on 19.01.2016. */ public class ApiGatewayServiceMain { - public static void main(String[] args) { - SpringApplication.run(ApiGatewayServiceConfiguration.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ApiGatewayServiceConfiguration.class, args); + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ContentRequestTransformer.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ContentRequestTransformer.java index 85d6af3..570f176 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ContentRequestTransformer.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ContentRequestTransformer.java @@ -15,16 +15,16 @@ import java.util.stream.Collectors; */ public class ContentRequestTransformer extends ProxyRequestTransformer { - @Override - public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException { - RequestBuilder requestBuilder = predecessor.transform(request); + @Override + public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException { + RequestBuilder requestBuilder = predecessor.transform(request); - String requestContent = request.getReader().lines().collect(Collectors.joining("")); - if(!requestContent.isEmpty()) { - StringEntity entity = new StringEntity(requestContent, ContentType.APPLICATION_JSON); - requestBuilder.setEntity(entity); - } - - return requestBuilder; + String requestContent = request.getReader().lines().collect(Collectors.joining("")); + if (!requestContent.isEmpty()) { + StringEntity entity = new StringEntity(requestContent, ContentType.APPLICATION_JSON); + requestBuilder.setEntity(entity); } + + return requestBuilder; + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/HeadersRequestTransformer.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/HeadersRequestTransformer.java index b338f3c..b39a589 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/HeadersRequestTransformer.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/HeadersRequestTransformer.java @@ -13,20 +13,19 @@ import java.util.Enumeration; */ public class HeadersRequestTransformer extends ProxyRequestTransformer { + @Override + public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException { + RequestBuilder requestBuilder = predecessor.transform(request); - @Override - public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException { - RequestBuilder requestBuilder = predecessor.transform(request); - - Enumeration headerNames = request.getHeaderNames(); - while (headerNames.hasMoreElements()) { - String headerName = headerNames.nextElement(); - String headerValue = request.getHeader(headerName); - if(headerName.equals("x-access-token")) { - requestBuilder.addHeader(headerName, headerValue); - } - } - - return requestBuilder; + Enumeration headerNames = request.getHeaderNames(); + while (headerNames.hasMoreElements()) { + String headerName = headerNames.nextElement(); + String headerValue = request.getHeader(headerName); + if (headerName.equals("x-access-token")) { + requestBuilder.addHeader(headerName, headerValue); + } } + + return requestBuilder; + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ProxyRequestTransformer.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ProxyRequestTransformer.java index 1de2096..a983433 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ProxyRequestTransformer.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/ProxyRequestTransformer.java @@ -12,11 +12,11 @@ import java.net.URISyntaxException; */ public abstract class ProxyRequestTransformer { - protected ProxyRequestTransformer predecessor; + protected ProxyRequestTransformer predecessor; - public abstract RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException; + public abstract RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException, IOException; - public void setPredecessor(ProxyRequestTransformer transformer) { - this.predecessor = transformer; - }; + public void setPredecessor(ProxyRequestTransformer transformer) { + this.predecessor = transformer; + } } diff --git a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/URLRequestTransformer.java b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/URLRequestTransformer.java index 2cae5bc..c68af48 100755 --- a/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/URLRequestTransformer.java +++ b/java-spring/api-gateway-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/apigateway/utils/URLRequestTransformer.java @@ -14,35 +14,35 @@ import java.net.URISyntaxException; */ public class URLRequestTransformer extends ProxyRequestTransformer { - private ApiGatewayProperties apiGatewayProperties; + private ApiGatewayProperties apiGatewayProperties; - public URLRequestTransformer(ApiGatewayProperties apiGatewayProperties) { - this.apiGatewayProperties = apiGatewayProperties; + public URLRequestTransformer(ApiGatewayProperties apiGatewayProperties) { + this.apiGatewayProperties = apiGatewayProperties; + } + + @Override + public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException { + String requestURI = request.getRequestURI(); + URI uri; + if (request.getQueryString() != null && !request.getQueryString().isEmpty()) { + uri = new URI(getServiceUrl(requestURI, request) + "?" + request.getQueryString()); + } else { + uri = new URI(getServiceUrl(requestURI, request)); } - @Override - public RequestBuilder transform(HttpServletRequest request) throws NoSuchRequestHandlingMethodException, URISyntaxException { - String requestURI = request.getRequestURI(); - URI uri; - if (request.getQueryString() != null && !request.getQueryString().isEmpty()) { - uri = new URI(getServiceUrl(requestURI, request) + "?" + request.getQueryString()); - } else { - uri = new URI(getServiceUrl(requestURI, request)); - } + RequestBuilder rb = RequestBuilder.create(request.getMethod()); + rb.setUri(uri); + return rb; + } - RequestBuilder rb = RequestBuilder.create(request.getMethod()); - rb.setUri(uri); - return rb; - } + private String getServiceUrl(String requestURI, HttpServletRequest httpServletRequest) throws NoSuchRequestHandlingMethodException { - private String getServiceUrl(String requestURI, HttpServletRequest httpServletRequest) throws NoSuchRequestHandlingMethodException { - - ApiGatewayProperties.Endpoint endpoint = - apiGatewayProperties.getEndpoints().stream() - .filter(e -> - requestURI.matches(e.getPath()) && e.getMethod() == RequestMethod.valueOf(httpServletRequest.getMethod()) - ) - .findFirst().orElseThrow(() -> new NoSuchRequestHandlingMethodException(httpServletRequest)); - return endpoint.getLocation() + requestURI; - } + ApiGatewayProperties.Endpoint endpoint = + apiGatewayProperties.getEndpoints().stream() + .filter(e -> + requestURI.matches(e.getPath()) && e.getMethod() == RequestMethod.valueOf(httpServletRequest.getMethod()) + ) + .findFirst().orElseThrow(() -> new NoSuchRequestHandlingMethodException(httpServletRequest)); + return endpoint.getLocation() + requestURI; + } } diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/MoneyTransferIntegrationTest.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/MoneyTransferIntegrationTest.java index b265f82..6516ee4 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/MoneyTransferIntegrationTest.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/MoneyTransferIntegrationTest.java @@ -23,7 +23,7 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes=BankingTestConfiguration.class) +@SpringApplicationConfiguration(classes = BankingTestConfiguration.class) @IntegrationTest public class MoneyTransferIntegrationTest { @@ -35,11 +35,11 @@ public class MoneyTransferIntegrationTest { @Autowired private EventuateAggregateStore eventStore; - + @Test public void shouldTransferMoney() { - final EntityWithIdAndVersion fromAccount= await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); + final EntityWithIdAndVersion fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); final EntityWithIdAndVersion toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), "")); @@ -49,22 +49,22 @@ public class MoneyTransferIntegrationTest { new BigDecimal(80)))); - eventually ( + eventually( () -> eventStore.find(Account.class, fromAccount.getEntityId()), account -> Assert.assertEquals(new BigDecimal(70), account.getEntity().getBalance())); - eventually ( + eventually( () -> eventStore.find(Account.class, toAccount.getEntityId()), account -> Assert.assertEquals(new BigDecimal(380), account.getEntity().getBalance())); - eventually ( + eventually( () -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()), updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState())); } @Test public void shouldFailDueToInsufficientFunds() { - final EntityWithIdAndVersion fromAccount= await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); + final EntityWithIdAndVersion fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); final EntityWithIdAndVersion toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), "")); @@ -74,15 +74,15 @@ public class MoneyTransferIntegrationTest { new BigDecimal(200)))); - eventually ( + eventually( () -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()), updatedTransaction -> Assert.assertEquals(TransferState.FAILED_DUE_TO_INSUFFICIENT_FUNDS, updatedTransaction.getEntity().getState())); - eventually ( + eventually( () -> eventStore.find(Account.class, fromAccount.getEntityId()), account -> Assert.assertEquals(new BigDecimal(150), account.getEntity().getBalance())); - eventually ( + eventually( () -> eventStore.find(Account.class, toAccount.getEntityId()), account -> Assert.assertEquals(new BigDecimal(300), account.getEntity().getBalance())); diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQuerySideIntegrationTest.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQuerySideIntegrationTest.java index b2047fa..bb1bfbd 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQuerySideIntegrationTest.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/accounts/AccountQuerySideIntegrationTest.java @@ -26,39 +26,39 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil @IntegrationTest public class AccountQuerySideIntegrationTest { - @Autowired - private AccountService accountService; + @Autowired + private AccountService accountService; - @Autowired - private MoneyTransferService moneyTransferService; + @Autowired + private MoneyTransferService moneyTransferService; - @Autowired - private EventuateAggregateStore eventStore; + @Autowired + private EventuateAggregateStore eventStore; - @Autowired - private AccountQueryService accountQueryService; + @Autowired + private AccountQueryService accountQueryService; - @Test - public void shouldUpdateQuerySide() throws Exception { + @Test + public void shouldUpdateQuerySide() throws Exception { - final EntityWithIdAndVersion fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); + final EntityWithIdAndVersion fromAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(150), "")); - final EntityWithIdAndVersion toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), "")); + final EntityWithIdAndVersion toAccount = await(accountService.openAccount("00000000-00000000", "My Account", new BigDecimal(300), "")); - final EntityWithIdAndVersion transaction = await( - moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(), - toAccount.getEntityId(), - new BigDecimal(80)))); + final EntityWithIdAndVersion transaction = await( + moneyTransferService.transferMoney(new TransferDetails(fromAccount.getEntityId(), + toAccount.getEntityId(), + new BigDecimal(80)))); - eventually( - () -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()), - updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState())); + eventually( + () -> eventStore.find(MoneyTransfer.class, transaction.getEntityId()), + updatedTransaction -> Assert.assertEquals(TransferState.COMPLETED, updatedTransaction.getEntity().getState())); - eventually( - () -> accountQueryService.findByAccountId(fromAccount.getEntityId()), - accountInfo -> Assert.assertEquals(70 * 100, accountInfo.getBalance())); - eventually( - () -> accountQueryService.findByAccountId(toAccount.getEntityId()), - accountInfo -> Assert.assertEquals(380 * 100, accountInfo.getBalance())); - } + eventually( + () -> accountQueryService.findByAccountId(fromAccount.getEntityId()), + accountInfo -> Assert.assertEquals(70 * 100, accountInfo.getBalance())); + eventually( + () -> accountQueryService.findByAccountId(toAccount.getEntityId()), + accountInfo -> Assert.assertEquals(380 * 100, accountInfo.getBalance())); + } } diff --git a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java index 84c6c08..89956b7 100644 --- a/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java +++ b/java-spring/backend-integration-tests/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQuerySideIntegrationTest.java @@ -32,43 +32,43 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil @IntegrationTest public class CustomerQuerySideIntegrationTest { - @Autowired - private CustomerService customerService; + @Autowired + private CustomerService customerService; - @Autowired - private CustomerQueryService customerQueryService; + @Autowired + private CustomerQueryService customerQueryService; - @Autowired + @Autowired private EventuateAggregateStore eventStore; - @Test - public void shouldCreateCustomerAndAddToAccount() throws Exception { - CustomerInfo customerInfo = generateCustomerInfo(); - EntityWithIdAndVersion customer = await(customerService.createCustomer(customerInfo)); + @Test + public void shouldCreateCustomerAndAddToAccount() throws Exception { + CustomerInfo customerInfo = generateCustomerInfo(); + EntityWithIdAndVersion customer = await(customerService.createCustomer(customerInfo)); - ToAccountInfo toAccountInfo = generateToAccountInfo(); - EntityWithIdAndVersion customerWithNewAccount = await(customerService.addToAccount(customer.getEntityId(), toAccountInfo)); + ToAccountInfo toAccountInfo = generateToAccountInfo(); + EntityWithIdAndVersion customerWithNewAccount = await(customerService.addToAccount(customer.getEntityId(), toAccountInfo)); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return customerQueryService.findByCustomerId(customer.getEntityId()); - } - }, - new Verifier() { - @Override - public void verify(QuerySideCustomer querySideCustomer) { - Assert.assertEquals(customerInfo.getName(), querySideCustomer.getName()); - Assert.assertEquals(customerInfo.getSsn(), querySideCustomer.getSsn()); - Assert.assertEquals(customerInfo.getEmail(), querySideCustomer.getEmail()); - Assert.assertEquals(customerInfo.getPhoneNumber(), querySideCustomer.getPhoneNumber()); - Assert.assertEquals(customerInfo.getAddress(), querySideCustomer.getAddress()); + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return customerQueryService.findByCustomerId(customer.getEntityId()); + } + }, + new Verifier() { + @Override + public void verify(QuerySideCustomer querySideCustomer) { + Assert.assertEquals(customerInfo.getName(), querySideCustomer.getName()); + Assert.assertEquals(customerInfo.getSsn(), querySideCustomer.getSsn()); + Assert.assertEquals(customerInfo.getEmail(), querySideCustomer.getEmail()); + Assert.assertEquals(customerInfo.getPhoneNumber(), querySideCustomer.getPhoneNumber()); + Assert.assertEquals(customerInfo.getAddress(), querySideCustomer.getAddress()); - Assert.assertNotNull(querySideCustomer.getToAccounts()); - Assert.assertFalse(querySideCustomer.getToAccounts().isEmpty()); - Assert.assertEquals(querySideCustomer.getToAccounts().get("11111111-11111111"), toAccountInfo); - } - }); - } + Assert.assertNotNull(querySideCustomer.getToAccounts()); + Assert.assertFalse(querySideCustomer.getToAccounts().isEmpty()); + Assert.assertEquals(querySideCustomer.getToAccounts().get("11111111-11111111"), toAccountInfo); + } + }); + } } diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java index cb1df52..c86f4f5 100644 --- a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/controller/AuthController.java @@ -30,35 +30,35 @@ import static org.springframework.web.bind.annotation.RequestMethod.POST; @Validated public class AuthController { - @Autowired - private TokenService tokenService; + @Autowired + private TokenService tokenService; - @Autowired - private CustomerAuthService customerAuthService; + @Autowired + private CustomerAuthService customerAuthService; - private static ObjectMapper objectMapper = new ObjectMapper(); + private static ObjectMapper objectMapper = new ObjectMapper(); - @RequestMapping(value = "/login", method = POST) - public ResponseEntity doAuth(@RequestBody @Valid AuthRequest request) throws IOException { - QuerySideCustomer customer = customerAuthService.findByEmail(request.getEmail()); + @RequestMapping(value = "/login", method = POST) + public ResponseEntity doAuth(@RequestBody @Valid AuthRequest request) throws IOException { + QuerySideCustomer customer = customerAuthService.findByEmail(request.getEmail()); - Token token = tokenService.allocateToken(objectMapper.writeValueAsString(new User(request.getEmail()))); - return ResponseEntity.status(HttpStatus.OK).header("access-token", token.getKey()) - .body(customer); - } + Token token = tokenService.allocateToken(objectMapper.writeValueAsString(new User(request.getEmail()))); + return ResponseEntity.status(HttpStatus.OK).header("access-token", token.getKey()) + .body(customer); + } - @ResponseStatus(value = HttpStatus.NOT_FOUND) - @ExceptionHandler(IncorrectResultSizeDataAccessException.class) - public ErrorResponse customersNotFound() { - return new ErrorResponse("Customer not found"); - } + @ResponseStatus(value = HttpStatus.NOT_FOUND) + @ExceptionHandler(IncorrectResultSizeDataAccessException.class) + public ErrorResponse customersNotFound() { + return new ErrorResponse("Customer not found"); + } - @RequestMapping(value = "/user", method = GET) - public ResponseEntity getCurrentUser() { - Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + @RequestMapping(value = "/user", method = GET) + public ResponseEntity getCurrentUser() { + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - return ResponseEntity.status(HttpStatus.OK).body(customerAuthService.findByEmail(auth.getName())); - } + return ResponseEntity.status(HttpStatus.OK).body(customerAuthService.findByEmail(auth.getName())); + } } diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java index 0b0f3a6..237879e 100644 --- a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/AuthRequest.java @@ -8,22 +8,22 @@ import org.hibernate.validator.constraints.NotBlank; */ public class AuthRequest { - @NotBlank - @Email - private String email; + @NotBlank + @Email + private String email; - public AuthRequest() { - } + public AuthRequest() { + } - public AuthRequest(String email) { - this.email = email; - } + public AuthRequest(String email) { + this.email = email; + } - public String getEmail() { - return email; - } + public String getEmail() { + return email; + } - public void setEmail(String email) { - this.email = email; - } + public void setEmail(String email) { + this.email = email; + } } diff --git a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/ErrorResponse.java b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/ErrorResponse.java index 3718e60..2aa5f1c 100644 --- a/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/ErrorResponse.java +++ b/java-spring/common-auth-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/ErrorResponse.java @@ -5,20 +5,20 @@ package net.chrisrichardson.eventstore.javaexamples.banking.commonauth.model; */ public class ErrorResponse { - private String message; + private String message; - public ErrorResponse() { - } + public ErrorResponse() { + } - public ErrorResponse(String message) { - this.message = message; - } + public ErrorResponse(String message) { + this.message = message; + } - public String getMessage() { - return message; - } + public String getMessage() { + return message; + } - public void setMessage(String message) { - this.message = message; - } + public void setMessage(String message) { + this.message = message; + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java index c875ca6..ea6fcac 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthConfiguration.java @@ -32,66 +32,66 @@ import java.security.SecureRandom; @EnableConfigurationProperties({AuthProperties.class}) public class AuthConfiguration extends WebSecurityConfigurerAdapter { - @Autowired - private AuthProperties securityProperties; + @Autowired + private AuthProperties securityProperties; - @Autowired - private TokenAuthenticationService tokenAuthenticationService; + @Autowired + private TokenAuthenticationService tokenAuthenticationService; - @Autowired - CustomerAuthService customerAuthService; + @Autowired + CustomerAuthService customerAuthService; - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - //auth.inMemoryAuthentication(); - auth.userDetailsService(userDetailsServiceBean()); - } + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + //auth.inMemoryAuthentication(); + auth.userDetailsService(userDetailsServiceBean()); + } - @Override - public UserDetailsService userDetailsServiceBean() { - return email -> { + @Override + public UserDetailsService userDetailsServiceBean() { + return email -> { /* QuerySideCustomer customer = customerAuthService.findByEmail(email); if (customer != null) { return new User(email); } else { throw new UsernameNotFoundException(String.format("could not find the customer '%s'", email)); }*/ - //authorize everyone with basic authentication - return new User(email, "", true, true, true, true, - AuthorityUtils.createAuthorityList("USER")); + //authorize everyone with basic authentication + return new User(email, "", true, true, true, true, + AuthorityUtils.createAuthorityList("USER")); }; - } + } - @Bean - public CustomerAuthService customerAuthService(CustomerAuthRepository customerAuthRepository) { - return new CustomerAuthService(customerAuthRepository); - } + @Bean + public CustomerAuthService customerAuthService(CustomerAuthRepository customerAuthRepository) { + return new CustomerAuthService(customerAuthRepository); + } - @Bean - @Override - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } + @Bean + @Override + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } - @Override - protected void configure(HttpSecurity http) throws Exception { - http.csrf().disable() - .httpBasic().and() - .authorizeRequests() - .antMatchers("/index.html", "/", "/**.js", "/**.css").permitAll() - .antMatchers("/swagger-ui.html", "/v2/api-docs").permitAll() - .antMatchers(HttpMethod.POST, "/customers", "/login").permitAll() - .anyRequest().authenticated().and() - .addFilterAfter(new StatelessAuthenticationFilter(tokenAuthenticationService), BasicAuthenticationFilter.class); - } + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable() + .httpBasic().and() + .authorizeRequests() + .antMatchers("/index.html", "/", "/**.js", "/**.css").permitAll() + .antMatchers("/swagger-ui.html", "/v2/api-docs").permitAll() + .antMatchers(HttpMethod.POST, "/customers", "/login").permitAll() + .anyRequest().authenticated().and() + .addFilterAfter(new StatelessAuthenticationFilter(tokenAuthenticationService), BasicAuthenticationFilter.class); + } - @Bean - public TokenService tokenService() { - KeyBasedPersistenceTokenService res = new KeyBasedPersistenceTokenService(); - res.setSecureRandom(new SecureRandom()); - res.setServerSecret(securityProperties.getServerSecret()); - res.setServerInteger(securityProperties.getServerInteger()); + @Bean + public TokenService tokenService() { + KeyBasedPersistenceTokenService res = new KeyBasedPersistenceTokenService(); + res.setSecureRandom(new SecureRandom()); + res.setServerSecret(securityProperties.getServerSecret()); + res.setServerInteger(securityProperties.getServerInteger()); - return res; - } + return res; + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthProperties.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthProperties.java index 155b0c9..f83b3a7 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthProperties.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/AuthProperties.java @@ -7,22 +7,22 @@ import org.springframework.boot.context.properties.ConfigurationProperties; */ @ConfigurationProperties(locations = "classpath:auth.properties", ignoreUnknownFields = false, prefix = "auth") public class AuthProperties { - private String serverSecret; - private Integer serverInteger; + private String serverSecret; + private Integer serverInteger; - public String getServerSecret() { - return serverSecret; - } + public String getServerSecret() { + return serverSecret; + } - public void setServerSecret(String serverSecret) { - this.serverSecret = serverSecret; - } + public void setServerSecret(String serverSecret) { + this.serverSecret = serverSecret; + } - public Integer getServerInteger() { - return serverInteger; - } + public Integer getServerInteger() { + return serverInteger; + } - public void setServerInteger(Integer serverInteger) { - this.serverInteger = serverInteger; - } + public void setServerInteger(Integer serverInteger) { + this.serverInteger = serverInteger; + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java index e70d919..4c5425e 100644 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthRepository.java @@ -7,5 +7,5 @@ import java.util.List; interface CustomerAuthRepository extends MongoRepository { - List findByEmail(String email); -} + List findByEmail(String email); +} \ No newline at end of file diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java index 61ad68f..27904b3 100644 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/CustomerAuthService.java @@ -2,7 +2,6 @@ package net.chrisrichardson.eventstore.javaexamples.banking.commonauth; import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.QuerySideCustomer; import org.springframework.dao.EmptyResultDataAccessException; -import org.springframework.dao.IncorrectResultSizeDataAccessException; import java.util.List; @@ -10,20 +9,20 @@ import java.util.List; * Created by Main on 15.02.2016. */ public class CustomerAuthService { - private CustomerAuthRepository customerAuthRepository; + private CustomerAuthRepository customerAuthRepository; - public CustomerAuthService(CustomerAuthRepository customerAuthRepository) { - this.customerAuthRepository = customerAuthRepository; - } + public CustomerAuthService(CustomerAuthRepository customerAuthRepository) { + this.customerAuthRepository = customerAuthRepository; + } - public QuerySideCustomer findByEmail(String email){ - List customers = customerAuthRepository.findByEmail(email); - if (customers.isEmpty()) - throw new EmptyResultDataAccessException(1); - //TODO: add unique email constraint + public QuerySideCustomer findByEmail(String email) { + List customers = customerAuthRepository.findByEmail(email); + if (customers.isEmpty()) + throw new EmptyResultDataAccessException(1); + //TODO: add unique email constraint /* else if(customers.size()>1) throw new IncorrectResultSizeDataAccessException(1, customers.size());*/ - else - return customers.get(0); - } + else + return customers.get(0); + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/TokenAuthenticationService.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/TokenAuthenticationService.java index 15a6eea..ecea757 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/TokenAuthenticationService.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/TokenAuthenticationService.java @@ -18,26 +18,26 @@ import java.io.IOException; @Service public class TokenAuthenticationService { - @Autowired - private TokenService tokenService; + @Autowired + private TokenService tokenService; - private static final String AUTH_HEADER_NAME = "access-token"; - private static final long DAY = 1000 * 60 * 60 * 24; + private static final String AUTH_HEADER_NAME = "access-token"; + private static final long DAY = 1000 * 60 * 60 * 24; - private ObjectMapper mapper = new ObjectMapper(); + private ObjectMapper mapper = new ObjectMapper(); - public Authentication getAuthentication(HttpServletRequest request) throws IOException { - final String tokenString = request.getHeader(AUTH_HEADER_NAME); + public Authentication getAuthentication(HttpServletRequest request) throws IOException { + final String tokenString = request.getHeader(AUTH_HEADER_NAME); - if (tokenString != null) { - Token token = tokenService.verifyToken(tokenString); - final User user = mapper.readValue(token.getExtendedInformation(), User.class); + if (tokenString != null) { + Token token = tokenService.verifyToken(tokenString); + final User user = mapper.readValue(token.getExtendedInformation(), User.class); - if (user != null && (System.currentTimeMillis() - token.getKeyCreationTime()) < DAY) { - return new UserAuthentication(user); - } - } - return null; + if (user != null && (System.currentTimeMillis() - token.getKeyCreationTime()) < DAY) { + return new UserAuthentication(user); + } } + return null; + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/filter/StatelessAuthenticationFilter.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/filter/StatelessAuthenticationFilter.java index bd20db8..517b0e1 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/filter/StatelessAuthenticationFilter.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/filter/StatelessAuthenticationFilter.java @@ -16,18 +16,18 @@ import java.io.IOException; */ public class StatelessAuthenticationFilter extends GenericFilterBean { - private final TokenAuthenticationService tokenAuthenticationService; + private final TokenAuthenticationService tokenAuthenticationService; - public StatelessAuthenticationFilter(TokenAuthenticationService taService) { - this.tokenAuthenticationService = taService; - } + public StatelessAuthenticationFilter(TokenAuthenticationService taService) { + this.tokenAuthenticationService = taService; + } - @Override - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { - if (SecurityContextHolder.getContext().getAuthentication()==null) { - SecurityContextHolder.getContext().setAuthentication( - tokenAuthenticationService.getAuthentication((HttpServletRequest) req)); - } - chain.doFilter(req, res); + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + if (SecurityContextHolder.getContext().getAuthentication() == null) { + SecurityContextHolder.getContext().setAuthentication( + tokenAuthenticationService.getAuthentication((HttpServletRequest) req)); } + chain.doFilter(req, res); + } } \ No newline at end of file diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java index a5841d5..657a555 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/User.java @@ -16,63 +16,63 @@ import java.util.Set; @JsonIgnoreProperties(ignoreUnknown = true) public class User implements UserDetails { - private String email; + private String email; - public User() { - } + public User() { + } - public User(String email) { - this.email = email; - } + public User(String email) { + this.email = email; + } - public void setUsername(String username) { - this.email = username; - } + public void setUsername(String username) { + this.email = username; + } - @Override - @JsonIgnore - public Collection getAuthorities() { - SimpleGrantedAuthority authority = new SimpleGrantedAuthority("USER"); - Set res = new HashSet(); - res.add(authority); - return res; - } + @Override + @JsonIgnore + public Collection getAuthorities() { + SimpleGrantedAuthority authority = new SimpleGrantedAuthority("USER"); + Set res = new HashSet(); + res.add(authority); + return res; + } - @Override - public String getPassword() { - return ""; - } + @Override + public String getPassword() { + return ""; + } - @Override - public String getUsername() { - return this.email; - } + @Override + public String getUsername() { + return this.email; + } - @Override - public boolean isAccountNonExpired() { - return false; - } + @Override + public boolean isAccountNonExpired() { + return false; + } - @Override - public boolean isAccountNonLocked() { - return false; - } + @Override + public boolean isAccountNonLocked() { + return false; + } - @Override - public boolean isCredentialsNonExpired() { - return false; - } + @Override + public boolean isCredentialsNonExpired() { + return false; + } - @Override - public boolean isEnabled() { - return false; - } + @Override + public boolean isEnabled() { + return false; + } - public String getEmail() { - return email; - } + public String getEmail() { + return email; + } - public void setEmail(String email) { - this.email = email; - } + public void setEmail(String email) { + this.email = email; + } } diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/UserAuthentication.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/UserAuthentication.java index 51d8079..81b9083 100755 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/UserAuthentication.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/model/UserAuthentication.java @@ -10,45 +10,45 @@ import java.util.Collection; */ public class UserAuthentication implements Authentication { - private final User user; - private boolean authenticated = true; + private final User user; + private boolean authenticated = true; - public UserAuthentication(User user) { - this.user = user; - } + public UserAuthentication(User user) { + this.user = user; + } - @Override - public String getName() { - return user.getUsername(); - } + @Override + public String getName() { + return user.getUsername(); + } - @Override - public Collection getAuthorities() { - return user.getAuthorities(); - } + @Override + public Collection getAuthorities() { + return user.getAuthorities(); + } - @Override - public Object getCredentials() { - return user.getPassword(); - } + @Override + public Object getCredentials() { + return user.getPassword(); + } - @Override - public User getDetails() { - return user; - } + @Override + public User getDetails() { + return user; + } - @Override - public Object getPrincipal() { - return user.getUsername(); - } + @Override + public Object getPrincipal() { + return user.getUsername(); + } - @Override - public boolean isAuthenticated() { - return authenticated; - } + @Override + public boolean isAuthenticated() { + return authenticated; + } - @Override - public void setAuthenticated(boolean authenticated) { - this.authenticated = authenticated; - } + @Override + public void setAuthenticated(boolean authenticated) { + this.authenticated = authenticated; + } } \ No newline at end of file diff --git a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/utils/BasicAuthUtils.java b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/utils/BasicAuthUtils.java index 58a7ae0..e97d94b 100644 --- a/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/utils/BasicAuthUtils.java +++ b/java-spring/common-auth/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/commonauth/utils/BasicAuthUtils.java @@ -13,33 +13,33 @@ import java.nio.charset.Charset; */ public class BasicAuthUtils { - public static HttpHeaders basicAuthHeaders(String username) { - return new HttpHeaders() { - { - String auth = username + ":"; - byte[] encodedAuth = Base64.encodeBase64( - auth.getBytes(Charset.forName("US-ASCII"))); - String authHeader = "Basic " + new String(encodedAuth); - set("Authorization", authHeader); - } - }; + public static HttpHeaders basicAuthHeaders(String username) { + return new HttpHeaders() { + { + String auth = username + ":"; + byte[] encodedAuth = Base64.encodeBase64( + auth.getBytes(Charset.forName("US-ASCII"))); + String authHeader = "Basic " + new String(encodedAuth); + set("Authorization", authHeader); + } + }; + } + + public static T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class responseType) { + return doBasicAuthenticatedRequest(restTemplate, url, httpMethod, responseType, null); + } + + public static T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class responseType, Object requestObject) { + HttpEntity httpEntity; + if (requestObject != null) { + httpEntity = new HttpEntity(requestObject, BasicAuthUtils.basicAuthHeaders("test_user@mail.com")); + } else { + httpEntity = new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")); } - public static T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class responseType) { - return doBasicAuthenticatedRequest(restTemplate, url, httpMethod, responseType, null); - } - - public static T doBasicAuthenticatedRequest(RestTemplate restTemplate, String url, HttpMethod httpMethod, Class responseType, Object requestObject) { - HttpEntity httpEntity; - if(requestObject!=null) { - httpEntity = new HttpEntity(requestObject, BasicAuthUtils.basicAuthHeaders("test_user@mail.com")); - } else { - httpEntity = new HttpEntity(BasicAuthUtils.basicAuthHeaders("test_user@mail.com")); - } - - return restTemplate.exchange(url, - httpMethod, - httpEntity, - responseType).getBody(); - } + return restTemplate.exchange(url, + httpMethod, + httpEntity, + responseType).getBody(); + } } diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountChangedEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountChangedEvent.java index 44364f6..08cec47 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountChangedEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountChangedEvent.java @@ -1,7 +1,5 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts; -import io.eventuate.Aggregate; - import io.eventuate.Event; import java.math.BigDecimal; diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountCreditedEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountCreditedEvent.java index dee571d..2e1669f 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountCreditedEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountCreditedEvent.java @@ -1,8 +1,5 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts; -import io.eventuate.Aggregate; - - import java.math.BigDecimal; public class AccountCreditedEvent extends AccountChangedEvent { diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitFailedDueToInsufficientFundsEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitFailedDueToInsufficientFundsEvent.java index ad3296e..daea33a 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitFailedDueToInsufficientFundsEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitFailedDueToInsufficientFundsEvent.java @@ -1,7 +1,5 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts; -import io.eventuate.Aggregate; - import io.eventuate.Event; public class AccountDebitFailedDueToInsufficientFundsEvent implements Event { diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitedEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitedEvent.java index 09887f4..5cd010f 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitedEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/accounts/AccountDebitedEvent.java @@ -1,8 +1,5 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.common.accounts; -import io.eventuate.Aggregate; - - import java.math.BigDecimal; public class AccountDebitedEvent extends AccountChangedEvent { diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java index c487e86..ea47143 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerAddedToAccount.java @@ -7,20 +7,20 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAc */ public class CustomerAddedToAccount extends CustomerEvent { - private ToAccountInfo toAccountInfo; + private ToAccountInfo toAccountInfo; - public CustomerAddedToAccount() { - } + public CustomerAddedToAccount() { + } - public CustomerAddedToAccount(ToAccountInfo toAccountInfo) { - this.toAccountInfo = toAccountInfo; - } + public CustomerAddedToAccount(ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; + } - public ToAccountInfo getToAccountInfo() { - return toAccountInfo; - } + public ToAccountInfo getToAccountInfo() { + return toAccountInfo; + } - public void setToAccountInfo(ToAccountInfo toAccountInfo) { - this.toAccountInfo = toAccountInfo; - } + public void setToAccountInfo(ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; + } } diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java index 723d6e6..5c29620 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerCreatedEvent.java @@ -7,20 +7,20 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust */ public class CustomerCreatedEvent extends CustomerEvent { - private CustomerInfo customerInfo; + private CustomerInfo customerInfo; - public CustomerCreatedEvent() { - } + public CustomerCreatedEvent() { + } - public CustomerCreatedEvent(CustomerInfo customerInfo) { - this.customerInfo = customerInfo; - } + public CustomerCreatedEvent(CustomerInfo customerInfo) { + this.customerInfo = customerInfo; + } - public CustomerInfo getCustomerInfo() { - return customerInfo; - } + public CustomerInfo getCustomerInfo() { + return customerInfo; + } - public void setCustomerInfo(CustomerInfo customerInfo) { - this.customerInfo = customerInfo; - } + public void setCustomerInfo(CustomerInfo customerInfo) { + this.customerInfo = customerInfo; + } } diff --git a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerEvent.java b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerEvent.java index d893487..8cb1c9d 100644 --- a/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerEvent.java +++ b/java-spring/common-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/common/customers/CustomerEvent.java @@ -7,6 +7,6 @@ import io.eventuate.EventEntity; /** * Created by Main on 11.02.2016. */ -@EventEntity(entity="net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.Customer") -public abstract class CustomerEvent implements Event { +@EventEntity(entity = "net.chrisrichardson.eventstore.javaexamples.banking.backend.commandside.customers.Customer") +public abstract class CustomerEvent implements Event { } \ No newline at end of file diff --git a/java-spring/common-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountOpenEventSerializationTest.java b/java-spring/common-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountOpenEventSerializationTest.java index ee90074..abe72dc 100644 --- a/java-spring/common-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountOpenEventSerializationTest.java +++ b/java-spring/common-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountOpenEventSerializationTest.java @@ -6,6 +6,7 @@ import org.junit.Assert; import org.junit.Test; import java.math.BigDecimal; + public class AccountOpenEventSerializationTest { @Test diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java index fd32fc8..4d99051 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/AccountTransactionInfo.java @@ -18,7 +18,7 @@ public class AccountTransactionInfo { } public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount) { - this(transactionId, fromAccountId, toAccountId, amount, new Date(), ""); + this(transactionId, fromAccountId, toAccountId, amount, new Date(), ""); } public AccountTransactionInfo(String transactionId, String fromAccountId, String toAccountId, long amount, Date date, String description) { diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java index a8d10d4..2c2c88d 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/accounts/GetAccountResponse.java @@ -4,50 +4,50 @@ import java.math.BigDecimal; public class GetAccountResponse { - private String accountId; - private BigDecimal balance; - private String title; - private String description; + private String accountId; + private BigDecimal balance; + private String title; + private String description; - public GetAccountResponse() { - } + public GetAccountResponse() { + } - public GetAccountResponse(String accountId, BigDecimal balance, String title, String description) { - this.accountId = accountId; - this.balance = balance; - this.title = title; - this.description = description; - } + public GetAccountResponse(String accountId, BigDecimal balance, String title, String description) { + this.accountId = accountId; + this.balance = balance; + this.title = title; + this.description = description; + } - public void setBalance(BigDecimal balance) { - this.balance = balance; - } + public void setBalance(BigDecimal balance) { + this.balance = balance; + } - public void setAccountId(String accountId) { - this.accountId = accountId; - } + public void setAccountId(String accountId) { + this.accountId = accountId; + } - public String getAccountId() { - return accountId; - } + public String getAccountId() { + return accountId; + } - public BigDecimal getBalance() { - return balance; - } + public BigDecimal getBalance() { + return balance; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - this.title = title; - } + public void setTitle(String title) { + this.title = title; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java index 296699e..b61b5b8 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/AddToAccountResponse.java @@ -5,20 +5,20 @@ package net.chrisrichardson.eventstore.javaexamples.banking.common.customers; */ public class AddToAccountResponse { - private String version; + private String version; - public AddToAccountResponse() { - } + public AddToAccountResponse() { + } - public AddToAccountResponse(String version) { - this.version = version; - } + public AddToAccountResponse(String version) { + this.version = version; + } - public String getVersion() { - return version; - } + public String getVersion() { + return version; + } - public void setVersion(String version) { - this.version = version; - } + public void setVersion(String version) { + this.version = version; + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java index cb035f3..70dc947 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Address.java @@ -9,74 +9,74 @@ import javax.validation.constraints.NotNull; * Created by popikyardo on 02.02.16. */ public class Address { - @NotNull - private String street1; - private String street2; - @NotNull - private String city; - @NotNull - private String state; - @NotNull - private String zipCode; + @NotNull + private String street1; + private String street2; + @NotNull + private String city; + @NotNull + private String state; + @NotNull + private String zipCode; - public Address() { - } + public Address() { + } - public Address(String street1, String street2, String city, String state, String zipCode) { - this.street1 = street1; - this.street2 = street2; - this.city = city; - this.state = state; - this.zipCode = zipCode; - } + public Address(String street1, String street2, String city, String state, String zipCode) { + this.street1 = street1; + this.street2 = street2; + this.city = city; + this.state = state; + this.zipCode = zipCode; + } - public String getStreet1() { - return street1; - } + public String getStreet1() { + return street1; + } - public void setStreet1(String street1) { - this.street1 = street1; - } + public void setStreet1(String street1) { + this.street1 = street1; + } - public String getStreet2() { - return street2; - } + public String getStreet2() { + return street2; + } - public void setStreet2(String street2) { - this.street2 = street2; - } + public void setStreet2(String street2) { + this.street2 = street2; + } - public String getCity() { - return city; - } + public String getCity() { + return city; + } - public void setCity(String city) { - this.city = city; - } + public void setCity(String city) { + this.city = city; + } - public String getState() { - return state; - } + public String getState() { + return state; + } - public void setState(String state) { - this.state = state; - } + public void setState(String state) { + this.state = state; + } - public String getZipCode() { - return zipCode; - } + public String getZipCode() { + return zipCode; + } - public void setZipCode(String zipCode) { - this.zipCode = zipCode; - } + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } - @Override - public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java index 4f85c42..9de577d 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerInfo.java @@ -9,53 +9,53 @@ import javax.validation.constraints.NotNull; * Created by popikyardo on 03.02.16. */ public class CustomerInfo { - private Name name; - @NotNull - protected String email; - @NotNull - protected String ssn; - @NotNull - protected String phoneNumber; - protected Address address; + private Name name; + @NotNull + protected String email; + @NotNull + protected String ssn; + @NotNull + protected String phoneNumber; + protected Address address; - public CustomerInfo() { - } + public CustomerInfo() { + } - public CustomerInfo(Name name, String email, String ssn, String phoneNumber, Address address) { - this.name = name; - this.email = email; - this.ssn = ssn; - this.phoneNumber = phoneNumber; - this.address = address; - } + public CustomerInfo(Name name, String email, String ssn, String phoneNumber, Address address) { + this.name = name; + this.email = email; + this.ssn = ssn; + this.phoneNumber = phoneNumber; + this.address = address; + } - public Name getName() { - return name; - } + public Name getName() { + return name; + } - public String getEmail() { - return email; - } + public String getEmail() { + return email; + } - public String getSsn() { - return ssn; - } + public String getSsn() { + return ssn; + } - public String getPhoneNumber() { - return phoneNumber; - } + public String getPhoneNumber() { + return phoneNumber; + } - public Address getAddress() { - return address; - } + public Address getAddress() { + return address; + } - @Override - public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java index b380282..61d7707 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/CustomerResponse.java @@ -8,40 +8,40 @@ import org.apache.commons.lang.builder.HashCodeBuilder; */ public class CustomerResponse { - private String id; - private CustomerInfo customerInfo; + private String id; + private CustomerInfo customerInfo; - public CustomerResponse() { - } + public CustomerResponse() { + } - public CustomerResponse(String id, CustomerInfo customerInfo) { - this.id = id; - this.customerInfo = customerInfo; - } + public CustomerResponse(String id, CustomerInfo customerInfo) { + this.id = id; + this.customerInfo = customerInfo; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public CustomerInfo getCustomerInfo() { - return customerInfo; - } + public CustomerInfo getCustomerInfo() { + return customerInfo; + } - public void setCustomerInfo(CustomerInfo customerInfo) { - this.customerInfo = customerInfo; - } + public void setCustomerInfo(CustomerInfo customerInfo) { + this.customerInfo = customerInfo; + } - @Override - public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java index 312363d..eef1ad1 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/Name.java @@ -9,42 +9,42 @@ import javax.validation.constraints.NotNull; * Created by Main on 10.02.2016. */ public class Name { - @NotNull - private String firstName; - @NotNull - private String lastName; + @NotNull + private String firstName; + @NotNull + private String lastName; - public Name() { - } + public Name() { + } - public Name(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } + public Name(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } - public String getFirstName() { - return firstName; - } + public String getFirstName() { + return firstName; + } - public void setFirstName(String firstName) { - this.firstName = firstName; - } + public void setFirstName(String firstName) { + this.firstName = firstName; + } - public String getLastName() { - return lastName; - } + public String getLastName() { + return lastName; + } - public void setLastName(String lastName) { - this.lastName = lastName; - } + public void setLastName(String lastName) { + this.lastName = lastName; + } - @Override - public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java index fec1a9c..4efdc56 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/QuerySideCustomer.java @@ -5,81 +5,81 @@ import java.util.Map; /** * Created by Main on 05.02.2016. */ -public class QuerySideCustomer{ - private String id; - private Name name; - private String email; - private String ssn; - private String phoneNumber; - private Address address; - private Map toAccounts; +public class QuerySideCustomer { + private String id; + private Name name; + private String email; + private String ssn; + private String phoneNumber; + private Address address; + private Map toAccounts; - public QuerySideCustomer() { - } + public QuerySideCustomer() { + } - public QuerySideCustomer(String id, Name name, String email, String ssn, String phoneNumber, Address address, Map toAccounts) { - this.id = id; - this.name = name; - this.email = email; - this.ssn = ssn; - this.phoneNumber = phoneNumber; - this.address = address; - this.toAccounts = toAccounts; - } + public QuerySideCustomer(String id, Name name, String email, String ssn, String phoneNumber, Address address, Map toAccounts) { + this.id = id; + this.name = name; + this.email = email; + this.ssn = ssn; + this.phoneNumber = phoneNumber; + this.address = address; + this.toAccounts = toAccounts; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public Name getName() { - return name; - } + public Name getName() { + return name; + } - public void setName(Name name) { - this.name = name; - } + public void setName(Name name) { + this.name = name; + } - public String getEmail() { - return email; - } + public String getEmail() { + return email; + } - public void setEmail(String email) { - this.email = email; - } + public void setEmail(String email) { + this.email = email; + } - public String getSsn() { - return ssn; - } + public String getSsn() { + return ssn; + } - public void setSsn(String ssn) { - this.ssn = ssn; - } + public void setSsn(String ssn) { + this.ssn = ssn; + } - public String getPhoneNumber() { - return phoneNumber; - } + public String getPhoneNumber() { + return phoneNumber; + } - public void setPhoneNumber(String phoneNumber) { - this.phoneNumber = phoneNumber; - } + public void setPhoneNumber(String phoneNumber) { + this.phoneNumber = phoneNumber; + } - public Address getAddress() { - return address; - } + public Address getAddress() { + return address; + } - public void setAddress(Address address) { - this.address = address; - } + public void setAddress(Address address) { + this.address = address; + } - public Map getToAccounts() { - return toAccounts; - } + public Map getToAccounts() { + return toAccounts; + } - public void setToAccounts(Map toAccounts) { - this.toAccounts = toAccounts; - } + public void setToAccounts(Map toAccounts) { + this.toAccounts = toAccounts; + } } diff --git a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java index b725851..41fcde2 100644 --- a/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java +++ b/java-spring/common/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/common/customers/ToAccountInfo.java @@ -8,60 +8,60 @@ import org.apache.commons.lang.builder.HashCodeBuilder; * Created by Main on 08.02.2016. */ public class ToAccountInfo { - private String id; - private String title; - private String owner; - private String description; + private String id; + private String title; + private String owner; + private String description; - public ToAccountInfo() { - } + public ToAccountInfo() { + } - public ToAccountInfo(String id, String title, String owner, String description) { - this.id = id; - this.title = title; - this.owner = owner; - this.description = description; - } + public ToAccountInfo(String id, String title, String owner, String description) { + this.id = id; + this.title = title; + this.owner = owner; + this.description = description; + } - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - this.title = title; - } + public void setTitle(String title) { + this.title = title; + } - public String getOwner() { - return owner; - } + public String getOwner() { + return owner; + } - public void setOwner(String owner) { - this.owner = owner; - } + public void setOwner(String owner) { + this.owner = owner; + } - public String getDescription() { - return description; - } + public String getDescription() { + return description; + } - public void setDescription(String description) { - this.description = description; - } + public void setDescription(String description) { + this.description = description; + } - @Override - public boolean equals(Object o) { - return EqualsBuilder.reflectionEquals(this, o); - } + @Override + public boolean equals(Object o) { + return EqualsBuilder.reflectionEquals(this, o); + } - @Override - public int hashCode() { - return HashCodeBuilder.reflectionHashCode(this); - } + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java index 5365b2c..2de4a38 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/AddToAccountCommand.java @@ -7,13 +7,13 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.ToAc */ public class AddToAccountCommand implements CustomerCommand { - private ToAccountInfo toAccountInfo; + private ToAccountInfo toAccountInfo; - public AddToAccountCommand(ToAccountInfo toAccountInfo) { - this.toAccountInfo = toAccountInfo; - } + public AddToAccountCommand(ToAccountInfo toAccountInfo) { + this.toAccountInfo = toAccountInfo; + } - public ToAccountInfo getToAccountInfo() { - return toAccountInfo; - } + public ToAccountInfo getToAccountInfo() { + return toAccountInfo; + } } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java index 31ea7f8..c7ebe65 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CreateCustomerCommand.java @@ -6,13 +6,13 @@ import net.chrisrichardson.eventstore.javaexamples.banking.common.customers.Cust * Created by popikyardo on 02.02.16. */ public class CreateCustomerCommand implements CustomerCommand { - private CustomerInfo customerInfo; + private CustomerInfo customerInfo; - public CreateCustomerCommand(CustomerInfo customerInfo) { - this.customerInfo = customerInfo; - } + public CreateCustomerCommand(CustomerInfo customerInfo) { + this.customerInfo = customerInfo; + } - public CustomerInfo getCustomerInfo() { - return customerInfo; - } + public CustomerInfo getCustomerInfo() { + return customerInfo; + } } diff --git a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java index 7e2fab0..ffd65c5 100644 --- a/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java +++ b/java-spring/customers-command-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/Customer.java @@ -14,24 +14,24 @@ import java.util.List; */ public class Customer extends ReflectiveMutableCommandProcessingAggregate { - private CustomerInfo customerInfo; + private CustomerInfo customerInfo; - public List process(CreateCustomerCommand cmd) { - return EventUtil.events(new CustomerCreatedEvent(cmd.getCustomerInfo())); - } + public List process(CreateCustomerCommand cmd) { + return EventUtil.events(new CustomerCreatedEvent(cmd.getCustomerInfo())); + } - public List process(AddToAccountCommand cmd) { - return EventUtil.events(new CustomerAddedToAccount(cmd.getToAccountInfo())); - } + public List process(AddToAccountCommand cmd) { + return EventUtil.events(new CustomerAddedToAccount(cmd.getToAccountInfo())); + } - public void apply(CustomerCreatedEvent event) { - customerInfo = event.getCustomerInfo(); - } + public void apply(CustomerCreatedEvent event) { + customerInfo = event.getCustomerInfo(); + } - public void apply(CustomerAddedToAccount event) { - } + public void apply(CustomerAddedToAccount event) { + } - public CustomerInfo getCustomerInfo() { - return customerInfo; - } + public CustomerInfo getCustomerInfo() { + return customerInfo; + } } diff --git a/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java b/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java index 36f2871..43d71fe 100644 --- a/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java +++ b/java-spring/customers-command-side-backend/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/commandside/customers/CustomerTest.java @@ -12,20 +12,20 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.Customer public class CustomerTest { - @Test - public void testSomething() { - Customer customer = new Customer(); + @Test + public void testSomething() { + Customer customer = new Customer(); - CustomerInfo customerInfo = generateCustomerInfo(); + CustomerInfo customerInfo = generateCustomerInfo(); - List events = customer.process(new CreateCustomerCommand(customerInfo)); + List events = customer.process(new CreateCustomerCommand(customerInfo)); - Assert.assertEquals(1, events.size()); - Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass()); + Assert.assertEquals(1, events.size()); + Assert.assertEquals(CustomerCreatedEvent.class, events.get(0).getClass()); - customer.applyEvent(events.get(0)); - Assert.assertEquals(customerInfo, customer.getCustomerInfo()); - } + customer.applyEvent(events.get(0)); + Assert.assertEquals(customerInfo, customer.getCustomerInfo()); + } } diff --git a/java-spring/customers-command-side-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceConfiguration.java b/java-spring/customers-command-side-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceConfiguration.java index 608702c..4f85215 100644 --- a/java-spring/customers-command-side-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceConfiguration.java +++ b/java-spring/customers-command-side-service/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/CustomersCommandSideServiceConfiguration.java @@ -24,6 +24,4 @@ public class CustomersCommandSideServiceConfiguration { HttpMessageConverter additional = new MappingJackson2HttpMessageConverter(); return new HttpMessageConverters(additional); } - - } diff --git a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java index b584068..5da5cee 100644 --- a/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java +++ b/java-spring/customers-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/customers/CustomerController.java @@ -18,23 +18,23 @@ import java.util.concurrent.CompletableFuture; @RequestMapping("/customers") public class CustomerController { - private CustomerService customerService; + private CustomerService customerService; - @Autowired - public CustomerController(CustomerService customerService) { - this.customerService = customerService; - } + @Autowired + public CustomerController(CustomerService customerService) { + this.customerService = customerService; + } - @RequestMapping(method = RequestMethod.POST) - public CompletableFuture createCustomer(@Validated @RequestBody CustomerInfo customer) { - return customerService.createCustomer(customer) - .thenApply(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityId(), customer)); - } + @RequestMapping(method = RequestMethod.POST) + public CompletableFuture createCustomer(@Validated @RequestBody CustomerInfo customer) { + return customerService.createCustomer(customer) + .thenApply(entityAndEventInfo -> new CustomerResponse(entityAndEventInfo.getEntityId(), customer)); + } - @RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST) - public CompletableFuture addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) { - return customerService.addToAccount(id, request) - .thenApply(entityAndEventInfo -> new AddToAccountResponse(entityAndEventInfo.getEntityVersion().toString())); - } + @RequestMapping(value = "/{id}/toaccounts", method = RequestMethod.POST) + public CompletableFuture addToAccount(@PathVariable String id, @Validated @RequestBody ToAccountInfo request) { + return customerService.addToAccount(id, request) + .thenApply(entityAndEventInfo -> new AddToAccountResponse(entityAndEventInfo.getEntityVersion().toString())); + } } diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java index 53250ca..fd70386 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerInfoUpdateService.java @@ -13,36 +13,36 @@ import java.util.Collections; */ public class CustomerInfoUpdateService { - private Logger logger = LoggerFactory.getLogger(getClass()); + private Logger logger = LoggerFactory.getLogger(getClass()); - private QuerySideCustomerRepository accountInfoRepository; + private QuerySideCustomerRepository accountInfoRepository; - public CustomerInfoUpdateService(QuerySideCustomerRepository accountInfoRepository) { - this.accountInfoRepository = accountInfoRepository; + public CustomerInfoUpdateService(QuerySideCustomerRepository accountInfoRepository) { + this.accountInfoRepository = accountInfoRepository; + } + + public void create(String id, CustomerInfo customerInfo) { + try { + accountInfoRepository.save(new QuerySideCustomer(id, + customerInfo.getName(), + customerInfo.getEmail(), + customerInfo.getSsn(), + customerInfo.getPhoneNumber(), + customerInfo.getAddress(), + Collections.emptyMap() + ) + ); + logger.info("Saved in mongo"); + } catch (Throwable t) { + logger.error("Error during saving: ", t); + throw new RuntimeException(t); } + } - public void create(String id, CustomerInfo customerInfo) { - try { - accountInfoRepository.save(new QuerySideCustomer(id, - customerInfo.getName(), - customerInfo.getEmail(), - customerInfo.getSsn(), - customerInfo.getPhoneNumber(), - customerInfo.getAddress(), - Collections.emptyMap() - ) - ); - logger.info("Saved in mongo"); - } catch (Throwable t) { - logger.error("Error during saving: ", t); - throw new RuntimeException(t); - } - } - - public void addToAccount(String id, ToAccountInfo accountInfo) { - QuerySideCustomer customer = accountInfoRepository.findOne(id); - customer.getToAccounts().put(accountInfo.getId(), accountInfo); - accountInfoRepository.save(customer); - } + public void addToAccount(String id, ToAccountInfo accountInfo) { + QuerySideCustomer customer = accountInfoRepository.findOne(id); + customer.getToAccounts().put(accountInfo.getId(), accountInfo); + accountInfoRepository.save(customer); + } } diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java index 0fb4a76..0888113 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryService.java @@ -23,7 +23,7 @@ public class CustomerQueryService { return CompletableFuture.completedFuture(customer); } - public CompletableFuture> findByEmail(String email){ + public CompletableFuture> findByEmail(String email) { List customers = querySideCustomerRepository.findByEmailLike(email); if (customers.isEmpty()) return CompletableFutureUtil.failedFuture(new EmptyResultDataAccessException(1)); diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java index 18a2b9b..0070a63 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/CustomerQueryWorkflow.java @@ -15,31 +15,31 @@ import org.slf4j.LoggerFactory; @EventSubscriber(id = "customerQuerySideEventHandlers") public class CustomerQueryWorkflow { - private Logger logger = LoggerFactory.getLogger(getClass()); + private Logger logger = LoggerFactory.getLogger(getClass()); - private CustomerInfoUpdateService customerInfoUpdateService; + private CustomerInfoUpdateService customerInfoUpdateService; - public CustomerQueryWorkflow(CustomerInfoUpdateService customerInfoUpdateService) { - this.customerInfoUpdateService = customerInfoUpdateService; - } + public CustomerQueryWorkflow(CustomerInfoUpdateService customerInfoUpdateService) { + this.customerInfoUpdateService = customerInfoUpdateService; + } - @EventHandlerMethod - public void create(DispatchedEvent de) { - CustomerCreatedEvent event = de.getEvent(); - String id = de.getEntityId(); + @EventHandlerMethod + public void create(DispatchedEvent de) { + CustomerCreatedEvent event = de.getEvent(); + String id = de.getEntityId(); - customerInfoUpdateService.create(id, event.getCustomerInfo()); - } + customerInfoUpdateService.create(id, event.getCustomerInfo()); + } - @EventHandlerMethod - public void addToAccount(DispatchedEvent de) { - CustomerAddedToAccount event = de.getEvent(); - String id = de.getEntityId(); + @EventHandlerMethod + public void addToAccount(DispatchedEvent de) { + CustomerAddedToAccount event = de.getEvent(); + String id = de.getEntityId(); - ToAccountInfo toAccountInfo = event.getToAccountInfo(); + ToAccountInfo toAccountInfo = event.getToAccountInfo(); - customerInfoUpdateService.addToAccount(id, toAccountInfo); - } + customerInfoUpdateService.addToAccount(id, toAccountInfo); + } } diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerConfiguration.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerConfiguration.java index 6611e50..3c7b47f 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerConfiguration.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerConfiguration.java @@ -13,25 +13,25 @@ import org.springframework.data.mongodb.repository.config.EnableMongoRepositorie @EnableMongoRepositories @EnableEventHandlers public class QuerySideCustomerConfiguration { - @Bean - public CustomerQueryWorkflow customerQueryWorkflow(CustomerInfoUpdateService accountInfoUpdateService) { - return new CustomerQueryWorkflow(accountInfoUpdateService); - } + @Bean + public CustomerQueryWorkflow customerQueryWorkflow(CustomerInfoUpdateService accountInfoUpdateService) { + return new CustomerQueryWorkflow(accountInfoUpdateService); + } - @Bean - public CustomerInfoUpdateService customerInfoUpdateService(QuerySideCustomerRepository querySideCustomerRepository) { - return new CustomerInfoUpdateService(querySideCustomerRepository); - } + @Bean + public CustomerInfoUpdateService customerInfoUpdateService(QuerySideCustomerRepository querySideCustomerRepository) { + return new CustomerInfoUpdateService(querySideCustomerRepository); + } - @Bean - public CustomerQueryService customerQueryService(QuerySideCustomerRepository accountInfoRepository) { - return new CustomerQueryService(accountInfoRepository); - } + @Bean + public CustomerQueryService customerQueryService(QuerySideCustomerRepository accountInfoRepository) { + return new CustomerQueryService(accountInfoRepository); + } - @Bean - public QuerySideDependencyChecker querysideDependencyChecker(MongoTemplate mongoTemplate) { - return new QuerySideDependencyChecker(mongoTemplate); - } + @Bean + public QuerySideDependencyChecker querysideDependencyChecker(MongoTemplate mongoTemplate) { + return new QuerySideDependencyChecker(mongoTemplate); + } } diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java index 35bbfba..16121ff 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideCustomerRepository.java @@ -7,5 +7,5 @@ import java.util.List; interface QuerySideCustomerRepository extends MongoRepository { - List findByEmailLike(String email); + List findByEmailLike(String email); } diff --git a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideDependencyChecker.java b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideDependencyChecker.java index 51d6e0a..0d7d33c 100644 --- a/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideDependencyChecker.java +++ b/java-spring/customers-query-side-backend/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/backend/queryside/customers/QuerySideDependencyChecker.java @@ -1,11 +1,10 @@ package net.chrisrichardson.eventstore.javaexamples.banking.backend.queryside.customers; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.mongodb.core.MongoTemplate; + import org.slf4j.Logger; + import org.slf4j.LoggerFactory; + import org.springframework.data.mongodb.core.MongoTemplate; -import javax.annotation.PostConstruct; -import java.util.concurrent.TimeUnit; + import javax.annotation.PostConstruct; public class QuerySideDependencyChecker { private Logger logger = LoggerFactory.getLogger(getClass()); diff --git a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomerQueryController.java b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomerQueryController.java index 5fd9dac..a78d857 100644 --- a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomerQueryController.java +++ b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomerQueryController.java @@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; + import java.util.List; import java.util.concurrent.CompletableFuture; @@ -15,32 +16,32 @@ import java.util.concurrent.CompletableFuture; @RestController public class CustomerQueryController { - private CustomerQueryService customerQueryService; + private CustomerQueryService customerQueryService; - @Autowired - public CustomerQueryController(CustomerQueryService customerQueryService) { - this.customerQueryService = customerQueryService; - } + @Autowired + public CustomerQueryController(CustomerQueryService customerQueryService) { + this.customerQueryService = customerQueryService; + } - @RequestMapping(value = "/customers/{customerId}", method = RequestMethod.GET) - public CompletableFuture getCustomer(@PathVariable String customerId) { - return customerQueryService.findByCustomerId(customerId); - } + @RequestMapping(value = "/customers/{customerId}", method = RequestMethod.GET) + public CompletableFuture getCustomer(@PathVariable String customerId) { + return customerQueryService.findByCustomerId(customerId); + } - @RequestMapping(value = "/customers", method = RequestMethod.GET) - public CompletableFuture getCustomersByEmail(@RequestParam String email) { - return customerQueryService.findByEmail(email) - .thenApply(this::getCustomersQueryResponse); - } + @RequestMapping(value = "/customers", method = RequestMethod.GET) + public CompletableFuture getCustomersByEmail(@RequestParam String email) { + return customerQueryService.findByEmail(email) + .thenApply(this::getCustomersQueryResponse); + } - @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "customers not found") - @ExceptionHandler(EmptyResultDataAccessException.class) - public void customersNotFound() { + @ResponseStatus(value = HttpStatus.NOT_FOUND, reason = "customers not found") + @ExceptionHandler(EmptyResultDataAccessException.class) + public void customersNotFound() { - } + } - private CustomersQueryResponse getCustomersQueryResponse(List customersList) { - return new CustomersQueryResponse(customersList); - } + private CustomersQueryResponse getCustomersQueryResponse(List customersList) { + return new CustomersQueryResponse(customersList); + } } diff --git a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomersQueryResponse.java b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomersQueryResponse.java index 4ab7974..ded893d 100644 --- a/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomersQueryResponse.java +++ b/java-spring/customers-query-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/customers/queryside/CustomersQueryResponse.java @@ -9,20 +9,20 @@ import java.util.List; */ public class CustomersQueryResponse { - private List customers; + private List customers; - public CustomersQueryResponse() { - } + public CustomersQueryResponse() { + } - public CustomersQueryResponse(List customers) { - this.customers = customers; - } + public CustomersQueryResponse(List customers) { + this.customers = customers; + } - public List getCustomers() { - return customers; - } + public List getCustomers() { + return customers; + } - public void setCustomers(List customers) { - this.customers = customers; - } + public void setCustomers(List customers) { + this.customers = customers; + } } diff --git a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java index 75e964d..29684ab 100644 --- a/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java +++ b/java-spring/e2e-test/src/test/java/net/chrisrichardson/eventstore/examples/bank/web/EndToEndTest.java @@ -8,32 +8,32 @@ import org.springframework.web.client.RestTemplate; public class EndToEndTest extends AbstractRestAPITest { - private String getenv(String name, String defaultValue) { - String x = System.getenv(name); - return x == null ? defaultValue : x; - } + private String getenv(String name, String defaultValue) { + String x = System.getenv(name); + return x == null ? defaultValue : x; + } - RestTemplate restTemplate = new RestTemplate(); + RestTemplate restTemplate = new RestTemplate(); - CustomersTestUtils customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); + CustomersTestUtils customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); - public String baseUrl(String path) { - return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + 8080 + "/" + path; - } + public String baseUrl(String path) { + return "http://" + getenv("SERVICE_HOST", "localhost") + ":" + 8080 + "/" + path; + } - @Override - public CustomersTestUtils getCustomersTestUtils() { - return customersTestUtils; - } + @Override + public CustomersTestUtils getCustomersTestUtils() { + return customersTestUtils; + } - @Override - public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { - return new AuthenticatedRestTemplate(restTemplate); - } + @Override + public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { + return new AuthenticatedRestTemplate(restTemplate); + } - @Override - public RestTemplate getRestTemplate() { - return restTemplate; - } + @Override + public RestTemplate getRestTemplate() { + return restTemplate; + } } diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java index 28dd511..bb03f31 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingAuthTest.java @@ -29,45 +29,45 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.Customer @IntegrationTest({"server.port=0", "management.port=0"}) public class BankingAuthTest { - @Value("${local.server.port}") - private int port; + @Value("${local.server.port}") + private int port; - @Autowired - RestTemplate restTemplate; + @Autowired + RestTemplate restTemplate; - CustomersTestUtils customersTestUtils; + CustomersTestUtils customersTestUtils; - @PostConstruct - private void init() { - customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); - } + @PostConstruct + private void init() { + customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); + } - private String baseUrl(String path) { - return "http://localhost:" + port + "/" + path; - } + private String baseUrl(String path) { + return "http://localhost:" + port + "/" + path; + } - @Test - public void shouldCreateCustomerAndLogin() { - String email = uniqueEmail(); - CustomerInfo customerInfo = generateCustomerInfo(email); + @Test + public void shouldCreateCustomerAndLogin() { + String email = uniqueEmail(); + CustomerInfo customerInfo = generateCustomerInfo(email); - final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); - final String customerId = customerResponse.getId(); + final CustomerResponse customerResponse = restTemplate.postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); - Assert.assertNotNull(customerId); - Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); + Assert.assertNotNull(customerId); + Assert.assertEquals(customerInfo, customerResponse.getCustomerInfo()); - customersTestUtils.assertCustomerResponse(customerId, customerInfo); + customersTestUtils.assertCustomerResponse(customerId, customerInfo); - AuthRequest authRequest = new AuthRequest(email); + AuthRequest authRequest = new AuthRequest(email); - final QuerySideCustomer loginQuerySideCustomer = restTemplate.postForEntity(baseUrl("/login"), authRequest, QuerySideCustomer.class).getBody(); + final QuerySideCustomer loginQuerySideCustomer = restTemplate.postForEntity(baseUrl("/login"), authRequest, QuerySideCustomer.class).getBody(); - customersTestUtils.assertQuerySideCustomerEqualscCustomerInfo(loginQuerySideCustomer, customerResponse.getCustomerInfo()); - } + customersTestUtils.assertQuerySideCustomerEqualscCustomerInfo(loginQuerySideCustomer, customerResponse.getCustomerInfo()); + } - private String uniqueEmail() { - return System.currentTimeMillis() + "@email.com"; - } + private String uniqueEmail() { + return System.currentTimeMillis() + "@email.com"; + } } diff --git a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java index dfd1f3d..49a6402 100644 --- a/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java +++ b/java-spring/monolithic-service/src/test/java/net/chrisrichardson/eventstore/javaexamples/banking/web/BankingWebIntegrationTest.java @@ -20,36 +20,36 @@ import javax.annotation.PostConstruct; @IntegrationTest({"server.port=0", "management.port=0"}) public class BankingWebIntegrationTest extends AbstractRestAPITest { - @Value("${local.server.port}") - private int port; + @Value("${local.server.port}") + private int port; - CustomersTestUtils customersTestUtils; + CustomersTestUtils customersTestUtils; - @PostConstruct - private void init() { - customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); - } + @PostConstruct + private void init() { + customersTestUtils = new CustomersTestUtils(restTemplate, baseUrl("/customers/")); + } - @Override - public String baseUrl(String path) { - return "http://localhost:" + port + "/" + path; - } + @Override + public String baseUrl(String path) { + return "http://localhost:" + port + "/" + path; + } - @Override - public CustomersTestUtils getCustomersTestUtils() { - return customersTestUtils; - } + @Override + public CustomersTestUtils getCustomersTestUtils() { + return customersTestUtils; + } - @Autowired - RestTemplate restTemplate; + @Autowired + RestTemplate restTemplate; - @Override - public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { - return new AuthenticatedRestTemplate(restTemplate); - } + @Override + public AuthenticatedRestTemplate getAuthenticatedRestTemplate() { + return new AuthenticatedRestTemplate(restTemplate); + } - @Override - public RestTemplate getRestTemplate() { - return restTemplate; - } + @Override + public RestTemplate getRestTemplate() { + return restTemplate; + } } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java index 00d52ba..a780590 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AbstractRestAPITest.java @@ -27,172 +27,172 @@ import static org.junit.Assert.assertTrue; public abstract class AbstractRestAPITest { - @Test - public void shouldCreateAccountsAndTransferMoney() { - BigDecimal initialFromAccountBalance = new BigDecimal(500); - BigDecimal initialToAccountBalance = new BigDecimal(100); - BigDecimal amountToTransfer = new BigDecimal(150); + @Test + public void shouldCreateAccountsAndTransferMoney() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + BigDecimal initialToAccountBalance = new BigDecimal(100); + BigDecimal amountToTransfer = new BigDecimal(150); - BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer); - BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer); + BigDecimal finalFromAccountBalance = initialFromAccountBalance.subtract(amountToTransfer); + BigDecimal finalToAccountBalance = initialToAccountBalance.add(amountToTransfer); - final CreateAccountResponse fromAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), - new CreateAccountRequest("00000000-00000000", "My 1 Account", "", initialFromAccountBalance), - CreateAccountResponse.class); + final CreateAccountResponse fromAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest("00000000-00000000", "My 1 Account", "", initialFromAccountBalance), + CreateAccountResponse.class); - final String fromAccountId = fromAccount.getAccountId(); + final String fromAccountId = fromAccount.getAccountId(); - CreateAccountResponse toAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), - new CreateAccountRequest("00000000-00000000", "My 2 Account", "", initialToAccountBalance), - CreateAccountResponse.class); + CreateAccountResponse toAccount = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest("00000000-00000000", "My 2 Account", "", initialToAccountBalance), + CreateAccountResponse.class); - String toAccountId = toAccount.getAccountId(); + String toAccountId = toAccount.getAccountId(); - Assert.assertNotNull(fromAccountId); - Assert.assertNotNull(toAccountId); + Assert.assertNotNull(fromAccountId); + Assert.assertNotNull(toAccountId); - assertAccountBalance(fromAccountId, initialFromAccountBalance); - assertAccountBalance(toAccountId, initialToAccountBalance); + assertAccountBalance(fromAccountId, initialFromAccountBalance); + assertAccountBalance(toAccountId, initialToAccountBalance); - final CreateMoneyTransferResponse moneyTransfer = getAuthenticatedRestTemplate().postForEntity(baseUrl("/transfers"), - new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, ""), - CreateMoneyTransferResponse.class); + final CreateMoneyTransferResponse moneyTransfer = getAuthenticatedRestTemplate().postForEntity(baseUrl("/transfers"), + new CreateMoneyTransferRequest(fromAccountId, toAccountId, amountToTransfer, ""), + CreateMoneyTransferResponse.class); - assertAccountBalance(fromAccountId, finalFromAccountBalance); - assertAccountBalance(toAccountId, finalToAccountBalance); + assertAccountBalance(fromAccountId, finalFromAccountBalance); + assertAccountBalance(toAccountId, finalToAccountBalance); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId + "/history"), - AccountTransactionInfo[].class)); - } - }, - new Verifier() { - @Override - public void verify(AccountTransactionInfo[] transactionInfos) { - Optional first = Arrays.asList(transactionInfos).stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId())).findFirst(); + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId + "/history"), + AccountTransactionInfo[].class)); + } + }, + new Verifier() { + @Override + public void verify(AccountTransactionInfo[] transactionInfos) { + Optional first = Arrays.asList(transactionInfos).stream().filter(ti -> ti.getTransactionId().equals(moneyTransfer.getMoneyTransferId())).findFirst(); - assertTrue(first.isPresent()); + assertTrue(first.isPresent()); - AccountTransactionInfo ti = first.get(); + AccountTransactionInfo ti = first.get(); - assertEquals(fromAccountId, ti.getFromAccountId()); - assertEquals(toAccountId, ti.getToAccountId()); - assertEquals(toAccountId, ti.getToAccountId()); - assertEquals(fromAccountId, ti.getFromAccountId()); - assertEquals(toCents(amountToTransfer).longValue(), ti.getAmount()); - } - }); - } + assertEquals(fromAccountId, ti.getFromAccountId()); + assertEquals(toAccountId, ti.getToAccountId()); + assertEquals(toAccountId, ti.getToAccountId()); + assertEquals(fromAccountId, ti.getFromAccountId()); + assertEquals(toCents(amountToTransfer).longValue(), ti.getAmount()); + } + }); + } - @Test - public void shouldCreateAccountsAndGetByCustomer() { - BigDecimal initialFromAccountBalance = new BigDecimal(500); - CustomerInfo customerInfo = generateCustomerInfo(); + @Test + public void shouldCreateAccountsAndGetByCustomer() { + BigDecimal initialFromAccountBalance = new BigDecimal(500); + CustomerInfo customerInfo = generateCustomerInfo(); - final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); - final String customerId = customerResponse.getId(); + final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); - Assert.assertNotNull(customerId); - assertEquals(customerInfo, customerResponse.getCustomerInfo()); + Assert.assertNotNull(customerId); + assertEquals(customerInfo, customerResponse.getCustomerInfo()); - getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); + getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); - final CreateAccountResponse account = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), - new CreateAccountRequest(customerId, "My 1 Account", "", initialFromAccountBalance), - CreateAccountResponse.class); + final CreateAccountResponse account = getAuthenticatedRestTemplate().postForEntity(baseUrl("/accounts"), + new CreateAccountRequest(customerId, "My 1 Account", "", initialFromAccountBalance), + CreateAccountResponse.class); - final String accountId = account.getAccountId(); + final String accountId = account.getAccountId(); - Assert.assertNotNull(accountId); + Assert.assertNotNull(accountId); - assertAccountBalance(accountId, initialFromAccountBalance); + assertAccountBalance(accountId, initialFromAccountBalance); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts?customerId=" + customerId), - GetAccountResponse[].class)); - } - }, - new Verifier() { - @Override - public void verify(GetAccountResponse[] accountResponses) { - assertTrue(Arrays.asList(accountResponses).stream().filter(acc -> acc.getAccountId().equals(accountId)).findFirst().isPresent()); - } - }); - } + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts?customerId=" + customerId), + GetAccountResponse[].class)); + } + }, + new Verifier() { + @Override + public void verify(GetAccountResponse[] accountResponses) { + assertTrue(Arrays.asList(accountResponses).stream().filter(acc -> acc.getAccountId().equals(accountId)).findFirst().isPresent()); + } + }); + } - @Test - public void shouldCreateCustomersAndAddToAccount() { - CustomerInfo customerInfo = generateCustomerInfo(); + @Test + public void shouldCreateCustomersAndAddToAccount() { + CustomerInfo customerInfo = generateCustomerInfo(); - final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); - final String customerId = customerResponse.getId(); + final CustomerResponse customerResponse = getRestTemplate().postForEntity(baseUrl("/customers"), customerInfo, CustomerResponse.class).getBody(); + final String customerId = customerResponse.getId(); - Assert.assertNotNull(customerId); - assertEquals(customerInfo, customerResponse.getCustomerInfo()); + Assert.assertNotNull(customerId); + assertEquals(customerInfo, customerResponse.getCustomerInfo()); - getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); + getCustomersTestUtils().assertCustomerResponse(customerId, customerInfo); - ToAccountInfo toAccountInfo = generateToAccountInfo(); + ToAccountInfo toAccountInfo = generateToAccountInfo(); - getAuthenticatedRestTemplate().postForEntity(baseUrl("/customers/" + customerId + "/toaccounts"), - toAccountInfo, - null); + getAuthenticatedRestTemplate().postForEntity(baseUrl("/customers/" + customerId + "/toaccounts"), + toAccountInfo, + null); - assertToAccountsContains(customerId, toAccountInfo); - } + assertToAccountsContains(customerId, toAccountInfo); + } - private BigDecimal toCents(BigDecimal dollarAmount) { - return dollarAmount.multiply(new BigDecimal(100)); - } + private BigDecimal toCents(BigDecimal dollarAmount) { + return dollarAmount.multiply(new BigDecimal(100)); + } - private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { - final BigDecimal inCents = toCents(expectedBalanceInDollars); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId), - GetAccountResponse.class)); - } - }, - new Verifier() { - @Override - public void verify(GetAccountResponse accountInfo) { - assertEquals(fromAccountId, accountInfo.getAccountId()); - assertEquals(inCents, accountInfo.getBalance()); - } - }); - } + private void assertAccountBalance(final String fromAccountId, final BigDecimal expectedBalanceInDollars) { + final BigDecimal inCents = toCents(expectedBalanceInDollars); + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/accounts/" + fromAccountId), + GetAccountResponse.class)); + } + }, + new Verifier() { + @Override + public void verify(GetAccountResponse accountInfo) { + assertEquals(fromAccountId, accountInfo.getAccountId()); + assertEquals(inCents, accountInfo.getBalance()); + } + }); + } - private void assertToAccountsContains(final String customerId, final ToAccountInfo toAccountInfo) { - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/customers/" + customerId), - QuerySideCustomer.class)); - } - }, - new Verifier() { - @Override - public void verify(QuerySideCustomer customerResponse) { - assertEquals(customerId, customerResponse.getId()); - assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); - } - }); - } + private void assertToAccountsContains(final String customerId, final ToAccountInfo toAccountInfo) { + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(getAuthenticatedRestTemplate().getForEntity(baseUrl("/customers/" + customerId), + QuerySideCustomer.class)); + } + }, + new Verifier() { + @Override + public void verify(QuerySideCustomer customerResponse) { + assertEquals(customerId, customerResponse.getId()); + assertTrue(customerResponse.getToAccounts().values().stream().anyMatch(t -> t.equals(toAccountInfo))); + } + }); + } - public abstract AuthenticatedRestTemplate getAuthenticatedRestTemplate(); + public abstract AuthenticatedRestTemplate getAuthenticatedRestTemplate(); - public abstract RestTemplate getRestTemplate(); + public abstract RestTemplate getRestTemplate(); - public abstract String baseUrl(String path); + public abstract String baseUrl(String path); - public abstract CustomersTestUtils getCustomersTestUtils(); + public abstract CustomersTestUtils getCustomersTestUtils(); } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java index f8c55ce..bd980e4 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/AuthenticatedRestTemplate.java @@ -6,25 +6,25 @@ import org.springframework.web.client.RestTemplate; public class AuthenticatedRestTemplate { - private RestTemplate restTemplate; + private RestTemplate restTemplate; - public AuthenticatedRestTemplate(RestTemplate restTemplate) { - this.restTemplate = restTemplate; - } + public AuthenticatedRestTemplate(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } - public T getForEntity(String url, Class clazz) { - return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - url, - HttpMethod.GET, - clazz); - } + public T getForEntity(String url, Class clazz) { + return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + url, + HttpMethod.GET, + clazz); + } - public T postForEntity(String url, Object requestObject, Class clazz) { - return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, - url, - HttpMethod.POST, - clazz, - requestObject - ); - } + public T postForEntity(String url, Object requestObject, Class clazz) { + return BasicAuthUtils.doBasicAuthenticatedRequest(restTemplate, + url, + HttpMethod.POST, + clazz, + requestObject + ); + } } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java index 6d1bdb1..a9e6e6e 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/CustomersTestUtils.java @@ -13,59 +13,59 @@ import static net.chrisrichardson.eventstorestore.javaexamples.testutil.TestUtil */ public class CustomersTestUtils { - private RestTemplate restTemplate; - private String customersBaseUrl; + private RestTemplate restTemplate; + private String customersBaseUrl; - public CustomersTestUtils(RestTemplate restTemplate, String customersBaseUrl) { - this.restTemplate = restTemplate; - this.customersBaseUrl = customersBaseUrl; - } + public CustomersTestUtils(RestTemplate restTemplate, String customersBaseUrl) { + this.restTemplate = restTemplate; + this.customersBaseUrl = customersBaseUrl; + } - public void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) { - AuthenticatedRestTemplate art = new AuthenticatedRestTemplate(restTemplate); - eventually( - new Producer() { - @Override - public CompletableFuture produce() { - return CompletableFuture.completedFuture(art.getForEntity(customersBaseUrl + customerId, QuerySideCustomer.class)); - } - }, - new Verifier() { - @Override - public void verify(QuerySideCustomer querySideCustomer) { - Assert.assertEquals(customerId, querySideCustomer.getId()); - assertQuerySideCustomerEqualscCustomerInfo(querySideCustomer, customerInfo); - } - }); - } + public void assertCustomerResponse(final String customerId, final CustomerInfo customerInfo) { + AuthenticatedRestTemplate art = new AuthenticatedRestTemplate(restTemplate); + eventually( + new Producer() { + @Override + public CompletableFuture produce() { + return CompletableFuture.completedFuture(art.getForEntity(customersBaseUrl + customerId, QuerySideCustomer.class)); + } + }, + new Verifier() { + @Override + public void verify(QuerySideCustomer querySideCustomer) { + Assert.assertEquals(customerId, querySideCustomer.getId()); + assertQuerySideCustomerEqualscCustomerInfo(querySideCustomer, customerInfo); + } + }); + } - public void assertQuerySideCustomerEqualscCustomerInfo(QuerySideCustomer querySideCustomer, CustomerInfo customerInfo) { - Assert.assertEquals(querySideCustomer.getName(), customerInfo.getName()); - Assert.assertEquals(querySideCustomer.getEmail(), customerInfo.getEmail()); - Assert.assertEquals(querySideCustomer.getPhoneNumber(), customerInfo.getPhoneNumber()); - Assert.assertEquals(querySideCustomer.getSsn(), customerInfo.getSsn()); - Assert.assertEquals(querySideCustomer.getAddress(), customerInfo.getAddress()); - } + public void assertQuerySideCustomerEqualscCustomerInfo(QuerySideCustomer querySideCustomer, CustomerInfo customerInfo) { + Assert.assertEquals(querySideCustomer.getName(), customerInfo.getName()); + Assert.assertEquals(querySideCustomer.getEmail(), customerInfo.getEmail()); + Assert.assertEquals(querySideCustomer.getPhoneNumber(), customerInfo.getPhoneNumber()); + Assert.assertEquals(querySideCustomer.getSsn(), customerInfo.getSsn()); + Assert.assertEquals(querySideCustomer.getAddress(), customerInfo.getAddress()); + } - public static CustomerInfo generateCustomerInfo() { - return generateCustomerInfo("current@email.com"); - } + public static CustomerInfo generateCustomerInfo() { + return generateCustomerInfo("current@email.com"); + } - public static CustomerInfo generateCustomerInfo(String email) { - return new CustomerInfo( - new Name("John", "Doe"), - email, - "000-00-0000", - "1-111-111-1111", - new Address("street 1", - "street 2", - "City", - "State", - "1111111") - ); - } + public static CustomerInfo generateCustomerInfo(String email) { + return new CustomerInfo( + new Name("John", "Doe"), + email, + "000-00-0000", + "1-111-111-1111", + new Address("street 1", + "street 2", + "City", + "State", + "1111111") + ); + } - public static ToAccountInfo generateToAccountInfo() { - return new ToAccountInfo("11111111-11111111", "New Account", "John Doe", ""); - } + public static ToAccountInfo generateToAccountInfo() { + return new ToAccountInfo("11111111-11111111", "New Account", "John Doe", ""); + } } diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestTemplateErrorHandler.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestTemplateErrorHandler.java index e33e8db..b3e9dcc 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestTemplateErrorHandler.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestTemplateErrorHandler.java @@ -10,15 +10,15 @@ import java.io.IOException; public class RestTemplateErrorHandler implements ResponseErrorHandler { - private static final Logger log = LoggerFactory.getLogger(RestTemplateErrorHandler.class); + private static final Logger log = LoggerFactory.getLogger(RestTemplateErrorHandler.class); - @Override - public void handleError(ClientHttpResponse response) throws IOException { - log.error("Response error: {} {}", response.getStatusCode(), response.getStatusText()); - } + @Override + public void handleError(ClientHttpResponse response) throws IOException { + log.error("Response error: {} {}", response.getStatusCode(), response.getStatusText()); + } - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - return RestUtil.isError(response.getStatusCode()); - } + @Override + public boolean hasError(ClientHttpResponse response) throws IOException { + return RestUtil.isError(response.getStatusCode()); + } } \ No newline at end of file diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestUtil.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestUtil.java index 52c7ed8..ce807bc 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestUtil.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/RestUtil.java @@ -4,9 +4,9 @@ import org.springframework.http.HttpStatus; public class RestUtil { - public static boolean isError(HttpStatus status) { - HttpStatus.Series series = status.series(); - return (HttpStatus.Series.CLIENT_ERROR.equals(series) - || HttpStatus.Series.SERVER_ERROR.equals(series)); - } + public static boolean isError(HttpStatus status) { + HttpStatus.Series series = status.series(); + return (HttpStatus.Series.CLIENT_ERROR.equals(series) + || HttpStatus.Series.SERVER_ERROR.equals(series)); + } } \ No newline at end of file diff --git a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java index f39dfe7..96eea4f 100644 --- a/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java +++ b/java-spring/testutil/src/main/java/net/chrisrichardson/eventstorestore/javaexamples/testutil/TestUtil.java @@ -37,7 +37,7 @@ public class TestUtil { } - static class Success implements Outcome { + static class Success implements Outcome { T value; @@ -98,7 +98,7 @@ public class TestUtil { }).first().toBlocking().getIterator().next().first; if (possibleException != null) - throw new RuntimeException((Throwable)possibleException); + throw new RuntimeException((Throwable) possibleException); } private static Observable fromCompletableFuture(CompletableFuture future) { diff --git a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java index 9c353bc..7c5649f 100644 --- a/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java +++ b/java-spring/transactions-command-side-web/src/main/java/net/chrisrichardson/eventstore/javaexamples/banking/web/commandside/transactions/MoneyTransferController.java @@ -12,9 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.util.concurrent.CompletableFuture; - import java.util.Date; +import java.util.concurrent.CompletableFuture; @RestController @RequestMapping("/transfers")