use of org.apache.commons.lang3.tuple.Triple 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
public Result<Triple<TicketReservation, List<Ticket>, Event>> confirmReservation(String eventName, String reservationId, String username) {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
return template.execute(status -> {
try {
Result<Triple<TicketReservation, List<Ticket>, Event>> result = eventRepository.findOptionalByShortName(eventName).flatMap(e -> optionally(() -> {
eventManager.checkOwnership(e, username, e.getOrganizationId());
return e;
})).map(event -> ticketReservationRepository.findOptionalReservationById(reservationId).filter(r -> r.getStatus() == TicketReservationStatus.PENDING || r.getStatus() == TicketReservationStatus.STUCK).map(r -> performConfirmation(reservationId, event, r)).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 org.apache.commons.lang3.tuple.Triple in project alf.io by alfio-event.
the class AdminReservationRequestManager method processReservation.
private Result<Triple<TicketReservation, List<Ticket>, Event>> processReservation(AdminReservationRequest request, Pair<Event, User> p) {
DefaultTransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
return template.execute(status -> {
try {
String eventName = p.getLeft().getShortName();
String username = p.getRight().getUsername();
Result<Triple<TicketReservation, List<Ticket>, Event>> result = adminReservationManager.createReservation(request.getBody(), eventName, username).flatMap(r -> adminReservationManager.confirmReservation(eventName, r.getLeft().getId(), username));
if (!result.isSuccess()) {
status.setRollbackOnly();
}
return result;
} catch (Exception ex) {
status.setRollbackOnly();
return Result.error(singletonList(ErrorCode.custom("", ex.getMessage())));
}
});
}
use of org.apache.commons.lang3.tuple.Triple in project alf.io by alfio-event.
the class TicketController method generateTicketPdf.
@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/download-ticket", method = RequestMethod.GET)
public void generateTicketPdf(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, HttpServletRequest request, HttpServletResponse response) throws IOException, WriterException {
Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
if (!oData.isPresent()) {
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Triple<Event, TicketReservation, Ticket> data = oData.get();
Ticket ticket = data.getRight();
response.setContentType("application/pdf");
response.addHeader("Content-Disposition", "attachment; filename=ticket-" + ticketIdentifier + ".pdf");
try (OutputStream os = response.getOutputStream()) {
PdfBoxRenderer renderer = preparePdfTicket(request, data.getLeft(), data.getMiddle(), ticket).generate(ticket);
if (renderer != null) {
renderer.createPDF(os);
}
}
}
use of org.apache.commons.lang3.tuple.Triple in project alf.io by alfio-event.
the class TicketController method internalShowTicket.
private String internalShowTicket(String eventName, String ticketIdentifier, boolean ticketEmailSent, Model model, String backSuffix, Locale locale) {
Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
if (!oData.isPresent()) {
return "redirect:/event/" + eventName;
}
Triple<Event, TicketReservation, Ticket> data = oData.get();
TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(data.getRight().getCategoryId(), data.getLeft().getId());
Organization organization = organizationRepository.getById(data.getLeft().getOrganizationId());
Event event = data.getLeft();
TicketReservation reservation = data.getMiddle();
//
model.addAttribute("ticket", data.getRight()).addAttribute("reservation", //
reservation).addAttribute("event", //
event).addAttribute("ticketCategory", //
ticketCategory).addAttribute("organization", //
organization).addAttribute("ticketEmailSent", ticketEmailSent).addAttribute("reservationId", ticketReservationManager.getShortReservationID(event, reservation.getId())).addAttribute("deskPaymentRequired", Optional.ofNullable(reservation.getPaymentMethod()).orElse(PaymentProxy.STRIPE).isDeskPaymentRequired()).addAttribute("backSuffix", backSuffix).addAttribute("userLanguage", locale.getLanguage()).addAttribute("pageTitle", "show-ticket.header.title").addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName()).addAttribute("validityStart", Optional.ofNullable(ticketCategory.getTicketValidityStart(event.getZoneId())).orElse(event.getBegin())).addAttribute("validityEnd", Optional.ofNullable(ticketCategory.getTicketValidityEnd(event.getZoneId())).orElse(event.getEnd())).addAttribute("ticketIdParam", "ticketId=" + ticketIdentifier);
return "/event/show-ticket";
}
use of org.apache.commons.lang3.tuple.Triple in project alf.io by alfio-event.
the class TicketController method showTicketForUpdate.
@RequestMapping(value = "/event/{eventName}/ticket/{ticketIdentifier}/update", method = RequestMethod.GET)
public String showTicketForUpdate(@PathVariable("eventName") String eventName, @PathVariable("ticketIdentifier") String ticketIdentifier, Model model, Locale locale) {
Optional<Triple<Event, TicketReservation, Ticket>> oData = ticketReservationManager.fetchCompleteAndAssigned(eventName, ticketIdentifier);
if (!oData.isPresent()) {
return "redirect:/event/" + eventName;
}
Triple<Event, TicketReservation, Ticket> data = oData.get();
Event event = data.getLeft();
TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(data.getRight().getCategoryId(), event.getId());
Organization organization = organizationRepository.getById(event.getOrganizationId());
boolean enableFreeCancellation = configurationManager.getBooleanConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ticketCategory.getId(), ALLOW_FREE_TICKETS_CANCELLATION), false);
Ticket ticket = data.getRight();
//
model.addAttribute("ticketAndCategory", Pair.of(eventManager.getTicketCategoryById(ticket.getCategoryId(), event.getId()), new TicketDecorator(ticket, enableFreeCancellation, eventManager.checkTicketCancellationPrerequisites().apply(ticket), "ticket/" + ticket.getUuid() + "/view", ticketHelper.findTicketFieldConfigurationAndValue(event.getId(), ticket, locale), true, ""))).addAttribute("reservation", //
data.getMiddle()).addAttribute("reservationId", ticketReservationManager.getShortReservationID(event, data.getMiddle().getId())).addAttribute("event", //
event).addAttribute("ticketCategory", //
ticketCategory).addAttribute("countries", TicketHelper.getLocalizedCountries(locale)).addAttribute("organization", //
organization).addAttribute("pageTitle", "show-ticket.header.title").addAttribute("useFirstAndLastName", event.mustUseFirstAndLastName());
return "/event/update-ticket";
}
Aggregations