Search in sources :

Example 36 with Triple

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())));
        }
    });
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) ResultStatus(alfio.model.result.Result.ResultStatus) BigDecimal(java.math.BigDecimal) Json(alfio.util.Json) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) TemplateResource(alfio.util.TemplateResource) TICKET(alfio.model.Audit.EntityType.TICKET) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) Collectors(java.util.stream.Collectors) CANCEL_TICKET(alfio.model.Audit.EventType.CANCEL_TICKET) Stream(java.util.stream.Stream) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) java.util(java.util) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Function(java.util.function.Function) Attendee(alfio.model.modification.AdminReservationModification.Attendee) DateTimeModification(alfio.model.modification.DateTimeModification) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) MessageSource(org.springframework.context.MessageSource) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) MonetaryUtil(alfio.util.MonetaryUtil) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) Category(alfio.model.modification.AdminReservationModification.Category) EventUtil.generateEmptyTickets(alfio.util.EventUtil.generateEmptyTickets) AdminReservationModification(alfio.model.modification.AdminReservationModification) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException)

Example 37 with Triple

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())));
        }
    });
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate)

Example 38 with Triple

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);
        }
    }
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) OutputStream(java.io.OutputStream) Event(alfio.model.Event) TicketReservation(alfio.model.TicketReservation) PdfBoxRenderer(com.openhtmltopdf.pdfboxout.PdfBoxRenderer)

Example 39 with Triple

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";
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Example 40 with Triple

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";
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) TicketDecorator(alfio.controller.support.TicketDecorator) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) TicketReservation(alfio.model.TicketReservation)

Aggregations

Triple (org.apache.commons.lang3.tuple.Triple)51 ArrayList (java.util.ArrayList)20 ImmutableTriple (org.apache.commons.lang3.tuple.ImmutableTriple)18 List (java.util.List)13 Pair (org.apache.commons.lang3.tuple.Pair)10 Test (org.junit.Test)8 Collectors (java.util.stream.Collectors)7 java.util (java.util)6 Organization (alfio.model.user.Organization)5 Event (alfio.model.Event)4 Ticket (alfio.model.Ticket)4 TicketReservation (alfio.model.TicketReservation)4 IOException (java.io.IOException)4 BlockPos (net.minecraft.util.math.BlockPos)4 Mutable (org.apache.commons.lang3.mutable.Mutable)4 Triple (org.apache.hyracks.algebricks.common.utils.Triple)4 alfio.model (alfio.model)3 TicketCategory (alfio.model.TicketCategory)3 TemplateManager (alfio.util.TemplateManager)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3