use of alfio.model.modification.AdminReservationModification.Notification in project alf.io by alfio-event.
the class AdminReservationManager method confirmReservation.
// the following methods have an explicit transaction handling, therefore the @Transactional annotation is not helpful here
Result<Triple<TicketReservation, List<Ticket>, PurchaseContext>> confirmReservation(PurchaseContextType purchaseContextType, String eventName, String reservationId, String username, Notification notification, UUID subscriptionId) {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
return template.execute(status -> {
try {
Result<Triple<TicketReservation, List<Ticket>, PurchaseContext>> result = purchaseContextManager.findBy(purchaseContextType, eventName).map(purchaseContext -> ticketReservationRepository.findOptionalReservationById(reservationId).filter(r -> r.getStatus() == TicketReservationStatus.PENDING || r.getStatus() == TicketReservationStatus.STUCK).map(r -> performConfirmation(reservationId, purchaseContext, r, notification, username, subscriptionId)).orElseGet(() -> Result.error(ErrorCode.ReservationError.UPDATE_FAILED))).orElseGet(() -> Result.error(ErrorCode.ReservationError.NOT_FOUND));
if (!result.isSuccess()) {
log.debug("Reservation confirmation failed for eventName: {} reservationId: {}, username: {}", eventName, reservationId, username);
status.setRollbackOnly();
}
return result;
} catch (Exception e) {
log.error("Error during confirmation of reservation eventName: {} reservationId: {}, username: {}", eventName, reservationId, username);
status.setRollbackOnly();
return Result.error(singletonList(ErrorCode.custom("", e.getMessage())));
}
});
}
Aggregations