use of com.kloia.eventapis.exception.EventStoreException in project eventapis by kloiasoft.
the class CompositeRepositoryImplTest method shouldRecordAndPublishWithPreviousEventKeyAndPublishedEventAndConcurrencyResolverFactory.
@Test
public void shouldRecordAndPublishWithPreviousEventKeyAndPublishedEventAndConcurrencyResolverFactory() throws JsonProcessingException, EventStoreException, ConcurrentEventException {
mockCommon(intermediateEvent);
EventKey previousEntityEventKey = new EventKey();
ConcurrencyResolver concurrencyResolver = mock(ConcurrencyResolver.class);
Function<EntityEvent, ConcurrencyResolver<ConcurrentEventException>> factory = entityEvent -> concurrencyResolver;
EventKey actual = compositeRepository.recordAndPublish(previousEntityEventKey, intermediateEvent, factory);
assertCommon(intermediateEvent);
assertThat(actual, equalTo(eventKey));
assertThat(previousEventKeyCaptor.getValue().isPresent(), equalTo(true));
assertThat(previousEventKeyCaptor.getValue().get(), equalTo(previousEntityEventKey));
assertThat(concurrencyResolverFactoryCaptor.getValue(), equalTo(factory));
}
use of com.kloia.eventapis.exception.EventStoreException in project eventapis by kloiasoft.
the class ReturnPaymentCommand method execute.
@RequestMapping(value = "/payment/{paymentId}/return", method = RequestMethod.POST)
@Command
public EventKey execute(@PathVariable("paymentId") String paymentId, @RequestBody @Valid ReturnPaymentCommandDto dto) throws Exception {
dto.setPaymentId(paymentId);
Payment payment = paymentViewQuery.queryEntity(dto.getPaymentId());
if (payment.getState() == PaymentState.PAID) {
PaymentReturnedEvent paymentReturnedEvent = new PaymentReturnedEvent(payment.getOrderId(), payment.getAmount());
return eventRepository.recordAndPublish(payment, paymentReturnedEvent);
} else
throw new EventStoreException("Payment state is not valid for this Operation: " + dto);
}
use of com.kloia.eventapis.exception.EventStoreException in project eventapis by kloiasoft.
the class ProcessOrderCommand method execute.
@Override
public EventKey execute(@RequestBody ProcessOrderCommandDto dto) throws Exception {
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.INITIAL) {
ReserveStockEvent reserveStockEvent = new ReserveStockEvent(order.getStockId(), order.getOrderAmount(), dto.getPaymentInformation());
log.info("Template account saved: " + dto);
return eventRepository.recordAndPublish(order, reserveStockEvent);
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
use of com.kloia.eventapis.exception.EventStoreException in project eventapis by kloiasoft.
the class ProcessOrderCommand method process.
@RequestMapping(value = "/order/{orderId}/process", method = RequestMethod.POST)
@Command
public EventKey process(@PathVariable("orderId") String orderId, @RequestBody @Valid ProcessOrderCommandDto dto) throws Exception {
dto.setOrderId(orderId);
Orders order = orderQuery.queryEntity(dto.getOrderId());
if (order.getState() == OrderState.INITIAL) {
ReserveStockEvent reserveStockEvent = new ReserveStockEvent(order.getStockId(), order.getOrderAmount(), dto.getPaymentInformation());
log.info("Template account saved: " + dto);
return eventRepository.recordAndPublish(order, reserveStockEvent);
} else
throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
use of com.kloia.eventapis.exception.EventStoreException in project eventapis by kloiasoft.
the class CompositeRepositoryImpl method recordAndPublishInternal.
private <P extends PublishedEvent, T extends Exception> EventKey recordAndPublishInternal(P publishedEvent, Optional<EventKey> previousEventKey, Function<EntityEvent, ConcurrencyResolver<T>> concurrencyResolverFactory) throws EventStoreException, T {
long opDate = System.currentTimeMillis();
EventKey eventKey = eventRecorder.recordEntityEvent(publishedEvent, opDate, previousEventKey, concurrencyResolverFactory);
publishedEvent.setSender(eventKey);
String event;
try {
event = objectMapper.writerWithView(Views.PublishedOnly.class).writeValueAsString(publishedEvent);
} catch (JsonProcessingException e) {
throw new EventStoreException(e.getMessage(), e);
}
operationRepository.publishEvent(publishedEvent.getClass().getSimpleName(), event, opDate);
checkOperationFinalStates(publishedEvent);
return publishedEvent.getSender();
}
Aggregations