Search in sources :

Example 11 with TicketCategory

use of alfio.model.TicketCategory 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 12 with TicketCategory

use of alfio.model.TicketCategory 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)

Example 13 with TicketCategory

use of alfio.model.TicketCategory in project alf.io by alfio-event.

the class SpecialPriceManager method checkCodeAssignment.

private List<String> checkCodeAssignment(Set<SendCodeModification> input, int categoryId, Event event, String username) {
    final TicketCategory category = checkOwnership(categoryId, event, username);
    List<String> availableCodes = new ArrayList<>(specialPriceRepository.findActiveByCategoryId(category.getId()).stream().filter(SpecialPrice::notSent).map(SpecialPrice::getCode).collect(toList()));
    Validate.isTrue(input.size() <= availableCodes.size(), "Requested codes: " + input.size() + ", available: " + availableCodes.size() + ".");
    List<String> requestedCodes = input.stream().filter(IS_CODE_PRESENT).map(SendCodeModification::getCode).collect(toList());
    Validate.isTrue(requestedCodes.stream().distinct().count() == requestedCodes.size(), "Cannot assign the same code twice. Please fix the input file.");
    Validate.isTrue(requestedCodes.stream().allMatch(availableCodes::contains), "some requested codes don't exist.");
    return availableCodes;
}
Also used : SpecialPrice(alfio.model.SpecialPrice) TicketCategory(alfio.model.TicketCategory)

Example 14 with TicketCategory

use of alfio.model.TicketCategory in project alf.io by alfio-event.

the class SpecialPriceManager method checkOwnership.

private TicketCategory checkOwnership(int categoryId, Event event, String username) {
    eventManager.checkOwnership(event, username, event.getOrganizationId());
    final List<TicketCategory> categories = eventManager.loadTicketCategories(event);
    final TicketCategory category = categories.stream().filter(tc -> tc.getId() == categoryId).findFirst().orElseThrow(IllegalArgumentException::new);
    Validate.isTrue(category.isAccessRestricted(), "Access to the selected category is not restricted.");
    return category;
}
Also used : TicketCategory(alfio.model.TicketCategory)

Example 15 with TicketCategory

use of alfio.model.TicketCategory in project alf.io by alfio-event.

the class SpecialPriceTokenGenerator method generateCode.

private void generateCode(SpecialPrice specialPrice) {
    TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(specialPrice.getTicketCategoryId()).orElseThrow(IllegalStateException::new);
    Event event = eventRepository.findById(ticketCategory.getEventId());
    int maxLength = configurationManager.getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ticketCategory.getId(), ConfigurationKeys.SPECIAL_PRICE_CODE_LENGTH), 6);
    while (true) {
        try {
            log.trace("generate code for special price with id {}", specialPrice.getId());
            specialPriceRepository.updateCode(nextValidCode(maxLength), specialPrice.getId());
            log.trace("done.");
            return;
        } catch (DataAccessException e) {
            log.warn("got a duplicate. Retrying...", e);
        }
    }
}
Also used : Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) DataAccessException(org.springframework.dao.DataAccessException)

Aggregations

TicketCategory (alfio.model.TicketCategory)22 Event (alfio.model.Event)17 Test (org.junit.Test)11 Ticket (alfio.model.Ticket)6 Organization (alfio.model.user.Organization)6 TicketReservation (alfio.model.TicketReservation)4 Triple (org.apache.commons.lang3.tuple.Triple)3 SaleableTicketCategory (alfio.controller.decorator.SaleableTicketCategory)2 EventManager (alfio.manager.EventManager)2 TicketReservationManager (alfio.manager.TicketReservationManager)2 SpecialPrice (alfio.model.SpecialPrice)2 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)2 LocalDate (java.time.LocalDate)2 Collectors (java.util.stream.Collectors)2 TicketDecorator (alfio.controller.support.TicketDecorator)1 NotificationManager (alfio.manager.NotificationManager)1 Mailer (alfio.manager.system.Mailer)1 AdditionalService (alfio.model.AdditionalService)1 ASReservationWithOptionalCodeModification (alfio.model.modification.ASReservationWithOptionalCodeModification)1 AdditionalServiceReservationModification (alfio.model.modification.AdditionalServiceReservationModification)1