Search in sources :

Example 1 with ReturnPaymentCommandDto

use of com.kloia.sample.dto.command.ReturnPaymentCommandDto in project eventapis by kloiasoft.

the class StockReleasedEventHandler method execute.

@KafkaListener(topics = "StockReleasedEvent", containerFactory = "eventsKafkaListenerContainerFactory")
public EventKey execute(StockReleasedEvent dto) throws EventStoreException, ConcurrentEventException {
    Orders order = orderQuery.queryEntity(dto.getOrderId());
    if (order.getState() == OrderState.RELEASING_STOCK) {
        OrderCancelledEvent orderCancelledEvent = new OrderCancelledEvent();
        log.info("Payment is processing : " + dto);
        EventKey eventKey = eventRepository.recordAndPublish(order, orderCancelledEvent);
        paymentClient.returnPaymentCommand(order.getPaymentId(), new ReturnPaymentCommandDto(order.getId()));
        return eventKey;
    } else
        throw new EventStoreException("Order state is not valid for this Operation: " + dto);
}
Also used : Orders(com.kloia.sample.model.Orders) EventStoreException(com.kloia.eventapis.exception.EventStoreException) OrderCancelledEvent(com.kloia.sample.dto.event.OrderCancelledEvent) ReturnPaymentCommandDto(com.kloia.sample.dto.command.ReturnPaymentCommandDto) EventKey(com.kloia.eventapis.common.EventKey) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

EventKey (com.kloia.eventapis.common.EventKey)1 EventStoreException (com.kloia.eventapis.exception.EventStoreException)1 ReturnPaymentCommandDto (com.kloia.sample.dto.command.ReturnPaymentCommandDto)1 OrderCancelledEvent (com.kloia.sample.dto.event.OrderCancelledEvent)1 Orders (com.kloia.sample.model.Orders)1 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1