use of alfio.model.PurchaseContext.PurchaseContextType 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())));
}
});
}
use of alfio.model.PurchaseContext.PurchaseContextType in project alf.io by alfio-event.
the class AdminReservationManager method updateReservation.
public Result<Boolean> updateReservation(PurchaseContextType purchaseContextType, String publicIdentifier, String reservationId, AdminReservationModification adminReservationModification, String username) {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
return template.execute(status -> {
try {
Result<Boolean> result = purchaseContextManager.findBy(purchaseContextType, publicIdentifier).map(event -> ticketReservationRepository.findOptionalReservationById(reservationId).map(r -> performUpdate(reservationId, event, r, adminReservationModification, username)).orElseGet(() -> Result.error(ErrorCode.ReservationError.UPDATE_FAILED))).orElseGet(() -> Result.error(ErrorCode.ReservationError.NOT_FOUND));
if (!result.isSuccess()) {
log.debug("Application error detected eventName: {} reservationId: {}, username: {}, reservation: {}", publicIdentifier, reservationId, username, AdminReservationModification.summary(adminReservationModification));
status.setRollbackOnly();
}
return result;
} catch (Exception e) {
log.error("Error during update of reservation eventName: {} reservationId: {}, username: {}, reservation: {}", publicIdentifier, reservationId, username, AdminReservationModification.summary(adminReservationModification));
status.setRollbackOnly();
return Result.error(singletonList(ErrorCode.custom("", e.getMessage())));
}
});
}
Aggregations