Search in sources :

Example 1 with SaleableTicketCategory

use of alfio.controller.decorator.SaleableTicketCategory in project alf.io by alfio-event.

the class AdminWaitingQueueApiController method loadStatus.

private Map<String, Boolean> loadStatus(Event event) {
    ZonedDateTime now = ZonedDateTime.now(clockProvider.getClock().withZone(event.getZoneId()));
    List<SaleableTicketCategory> stcList = eventManager.loadTicketCategories(event).stream().filter(tc -> !tc.isAccessRestricted()).map(tc -> new SaleableTicketCategory(tc, now, event, ticketReservationManager.countAvailableTickets(event, tc), tc.getMaxTickets(), null)).collect(Collectors.toList());
    boolean active = EventUtil.checkWaitingQueuePreconditions(event, stcList, configurationManager, eventStatisticsManager.noSeatsAvailable());
    boolean paused = active && configurationManager.getFor(STOP_WAITING_QUEUE_SUBSCRIPTIONS, event.getConfigurationLevel()).getValueAsBooleanOrDefault();
    Map<String, Boolean> result = new HashMap<>();
    result.put("active", active);
    result.put("paused", paused);
    return result;
}
Also used : java.util(java.util) ExportUtils(alfio.util.ExportUtils) ZonedDateTime(java.time.ZonedDateTime) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) ConfigurationManager(alfio.manager.system.ConfigurationManager) Collections.singletonList(java.util.Collections.singletonList) Pair(org.apache.commons.lang3.tuple.Pair) HttpServletResponse(javax.servlet.http.HttpServletResponse) STOP_WAITING_QUEUE_SUBSCRIPTIONS(alfio.model.system.ConfigurationKeys.STOP_WAITING_QUEUE_SUBSCRIPTIONS) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) TicketReservationManager(alfio.manager.TicketReservationManager) WaitingQueueSubscription(alfio.model.WaitingQueueSubscription) EventManager(alfio.manager.EventManager) Principal(java.security.Principal) Stream(java.util.stream.Stream) ConfigurationModification(alfio.model.modification.ConfigurationModification) EventStatisticsManager(alfio.manager.EventStatisticsManager) Data(lombok.Data) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) EventUtil(alfio.util.EventUtil) ResponseEntity(org.springframework.http.ResponseEntity) Event(alfio.model.Event) ClockProvider(alfio.util.ClockProvider) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) WaitingQueueManager(alfio.manager.WaitingQueueManager) ZonedDateTime(java.time.ZonedDateTime) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory)

Example 2 with SaleableTicketCategory

use of alfio.controller.decorator.SaleableTicketCategory in project alf.io by alfio-event.

the class ReservationUtil method validateCategory.

private static void validateCategory(Errors bindingResult, TicketReservationManager tickReservationManager, EventManager eventManager, Event event, int maxAmountOfTicket, List<TicketReservationWithOptionalCodeModification> res, Optional<SpecialPrice> specialCode, ZonedDateTime now, TicketReservationModification r) {
    TicketCategory tc = eventManager.getTicketCategoryById(r.getTicketCategoryId(), event.getId());
    SaleableTicketCategory ticketCategory = new SaleableTicketCategory(tc, now, event, tickReservationManager.countAvailableTickets(event, tc), maxAmountOfTicket, null);
    if (!ticketCategory.getSaleable()) {
        bindingResult.reject(ErrorsCode.STEP_1_TICKET_CATEGORY_MUST_BE_SALEABLE);
        return;
    }
    res.add(new TicketReservationWithOptionalCodeModification(r, ticketCategory.isAccessRestricted() ? specialCode : Optional.empty()));
}
Also used : TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory)

Example 3 with SaleableTicketCategory

use of alfio.controller.decorator.SaleableTicketCategory in project alf.io by alfio-event.

the class EventApiV2Controller method getTicketCategories.

@GetMapping("event/{eventName}/ticket-categories")
public ResponseEntity<ItemsByCategory> getTicketCategories(@PathVariable("eventName") String eventName, @RequestParam(value = "code", required = false) String code) {
    // 
    return eventRepository.findOptionalByShortName(eventName).filter(e -> e.getStatus() != Event.Status.DISABLED).map(event -> {
        var configurations = configurationManager.getFor(List.of(DISPLAY_TICKETS_LEFT_INDICATOR, MAX_AMOUNT_OF_TICKETS_BY_RESERVATION, DISPLAY_EXPIRED_CATEGORIES), event.getConfigurationLevel());
        var ticketCategoryLevelConfiguration = configurationManager.getAllCategoriesAndValueWith(event, MAX_AMOUNT_OF_TICKETS_BY_RESERVATION);
        var messageSource = messageSourceManager.getMessageSourceFor(event);
        var appliedPromoCode = promoCodeRequestManager.checkCode(event, code);
        Optional<SpecialPrice> specialCode = appliedPromoCode.getValue().getLeft();
        Optional<PromoCodeDiscount> promoCodeDiscount = appliedPromoCode.getValue().getRight();
        final ZonedDateTime now = event.now(clockProvider);
        // hide access restricted ticket categories
        var ticketCategories = ticketCategoryRepository.findAllTicketCategories(event.getId());
        List<SaleableTicketCategory> saleableTicketCategories = ticketCategories.stream().filter((c) -> !c.isAccessRestricted() || shouldDisplayRestrictedCategory(specialCode, c, promoCodeDiscount)).map((category) -> {
            int maxTickets = getMaxAmountOfTicketsPerReservation(configurations, ticketCategoryLevelConfiguration, category.getId());
            PromoCodeDiscount filteredPromoCode = promoCodeDiscount.filter(promoCode -> shouldApplyDiscount(promoCode, category)).orElse(null);
            if (specialCode.isPresent()) {
                maxTickets = Math.min(1, maxTickets);
            } else if (filteredPromoCode != null && filteredPromoCode.getMaxUsage() != null) {
                maxTickets = filteredPromoCode.getMaxUsage() - promoCodeRepository.countConfirmedPromoCode(filteredPromoCode.getId(), categoriesOrNull(filteredPromoCode), null, categoriesOrNull(filteredPromoCode) != null ? "X" : null);
            }
            return new SaleableTicketCategory(category, now, event, ticketReservationManager.countAvailableTickets(event, category), maxTickets, filteredPromoCode);
        }).collect(Collectors.toList());
        var valid = saleableTicketCategories.stream().filter(tc -> !tc.getExpired()).collect(Collectors.toList());
        // 
        var ticketCategoryIds = valid.stream().map(SaleableTicketCategory::getId).collect(Collectors.toList());
        var ticketCategoryDescriptions = ticketCategoryDescriptionRepository.descriptionsByTicketCategory(ticketCategoryIds);
        boolean displayTicketsLeft = configurations.get(DISPLAY_TICKETS_LEFT_INDICATOR).getValueAsBooleanOrDefault();
        var categoriesByExpiredFlag = saleableTicketCategories.stream().map(stc -> {
            var description = Formatters.applyCommonMark(ticketCategoryDescriptions.getOrDefault(stc.getId(), Collections.emptyMap()));
            var expiration = Formatters.getFormattedDate(event, stc.getZonedExpiration(), "common.ticket-category.date-format", messageSource);
            var inception = Formatters.getFormattedDate(event, stc.getZonedInception(), "common.ticket-category.date-format", messageSource);
            return new TicketCategory(stc, description, inception, expiration, displayTicketsLeft && !stc.isAccessRestricted());
        }).sorted(Comparator.comparingInt(TicketCategory::getOrdinal)).collect(partitioningBy(TicketCategory::isExpired));
        var promoCode = Optional.of(appliedPromoCode).filter(ValidatedResponse::isSuccess).map(ValidatedResponse::getValue).flatMap(Pair::getRight);
        // 
        var saleableAdditionalServices = additionalServiceRepository.loadAllForEvent(event.getId()).stream().map(as -> new SaleableAdditionalService(event, as, promoCode.orElse(null))).filter(SaleableAdditionalService::isNotExpired).collect(Collectors.toList());
        // will be used for fetching descriptions and titles for all the languages
        var saleableAdditionalServicesIds = saleableAdditionalServices.stream().map(SaleableAdditionalService::getId).collect(Collectors.toList());
        var additionalServiceTexts = additionalServiceTextRepository.getDescriptionsByAdditionalServiceIds(saleableAdditionalServicesIds);
        var additionalServicesRes = saleableAdditionalServices.stream().map(as -> {
            var expiration = Formatters.getFormattedDate(event, as.getZonedExpiration(), "common.ticket-category.date-format", messageSource);
            var inception = Formatters.getFormattedDate(event, as.getZonedInception(), "common.ticket-category.date-format", messageSource);
            var title = additionalServiceTexts.getOrDefault(as.getId(), Collections.emptyMap()).getOrDefault(AdditionalServiceText.TextType.TITLE, Collections.emptyMap());
            var description = Formatters.applyCommonMark(additionalServiceTexts.getOrDefault(as.getId(), Collections.emptyMap()).getOrDefault(AdditionalServiceText.TextType.DESCRIPTION, Collections.emptyMap()));
            return new AdditionalService(as.getId(), as.getType(), as.getSupplementPolicy(), as.isFixPrice(), as.getAvailableQuantity(), as.getMaxQtyPerOrder(), as.getFree(), as.getFormattedFinalPrice(), as.getSupportsDiscount(), as.getDiscountedPrice(), as.getVatApplies(), as.getVatIncluded(), as.getVatPercentage().toString(), as.isExpired(), as.getSaleInFuture(), inception, expiration, title, description);
        }).collect(Collectors.toList());
        // 
        // waiting queue parameters
        boolean displayWaitingQueueForm = EventUtil.displayWaitingQueueForm(event, saleableTicketCategories, configurationManager, eventStatisticsManager.noSeatsAvailable());
        boolean preSales = EventUtil.isPreSales(event, saleableTicketCategories);
        Predicate<SaleableTicketCategory> waitingQueueTargetCategory = tc -> !tc.getExpired() && !tc.isBounded();
        List<SaleableTicketCategory> unboundedCategories = saleableTicketCategories.stream().filter(waitingQueueTargetCategory).collect(Collectors.toList());
        var tcForWaitingList = unboundedCategories.stream().map(stc -> new ItemsByCategory.TicketCategoryForWaitingList(stc.getId(), stc.getName())).collect(toList());
        // 
        var activeCategories = categoriesByExpiredFlag.get(false);
        var expiredCategories = configurations.get(DISPLAY_EXPIRED_CATEGORIES).getValueAsBooleanOrDefault() ? categoriesByExpiredFlag.get(true) : List.<TicketCategory>of();
        return new ResponseEntity<>(new ItemsByCategory(activeCategories, expiredCategories, additionalServicesRes, displayWaitingQueueForm, preSales, tcForWaitingList), getCorsHeaders(), HttpStatus.OK);
    }).orElseGet(() -> ResponseEntity.notFound().headers(getCorsHeaders()).build());
}
Also used : ValidationResult(alfio.model.result.ValidationResult) alfio.repository(alfio.repository) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) ReservationForm(alfio.controller.form.ReservationForm) alfio.manager(alfio.manager) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) java.util(java.util) TicketReservationModification(alfio.model.modification.TicketReservationModification) SaleableAdditionalService(alfio.controller.decorator.SaleableAdditionalService) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) ZonedDateTime(java.time.ZonedDateTime) BindingResult(org.springframework.validation.BindingResult) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) ConfigurationManager(alfio.manager.system.ConfigurationManager) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) AdditionalService(alfio.controller.api.v2.model.AdditionalService) Formatters(alfio.controller.support.Formatters) alfio.util(alfio.util) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) Pair(org.apache.commons.lang3.tuple.Pair) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) EventLoader(alfio.controller.api.v2.user.support.EventLoader) ValidatedResponse(alfio.manager.support.response.ValidatedResponse) HttpSession(javax.servlet.http.HttpSession) EventWithAdditionalInfo(alfio.controller.api.v2.model.EventWithAdditionalInfo) WaitingQueueSubscriptionForm(alfio.controller.form.WaitingQueueSubscriptionForm) HttpHeaders(org.springframework.http.HttpHeaders) Predicate(java.util.function.Predicate) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SearchOptions(alfio.controller.form.SearchOptions) HttpStatus(org.springframework.http.HttpStatus) Validate(org.apache.commons.lang3.Validate) Principal(java.security.Principal) alfio.model(alfio.model) alfio.controller.api.v2.model(alfio.controller.api.v2.model) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ResponseEntity(org.springframework.http.ResponseEntity) I18nManager(alfio.manager.i18n.I18nManager) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) TicketCategory(alfio.controller.api.v2.model.TicketCategory) SaleableAdditionalService(alfio.controller.decorator.SaleableAdditionalService) SaleableAdditionalService(alfio.controller.decorator.SaleableAdditionalService) AdditionalService(alfio.controller.api.v2.model.AdditionalService) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) TicketCategory(alfio.controller.api.v2.model.TicketCategory) ValidatedResponse(alfio.manager.support.response.ValidatedResponse) Predicate(java.util.function.Predicate) ZonedDateTime(java.time.ZonedDateTime) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory)

Example 4 with SaleableTicketCategory

use of alfio.controller.decorator.SaleableTicketCategory in project alf.io by alfio-event.

the class ReservationForm method validateCategory.

private static void validateCategory(Errors bindingResult, TicketReservationManager tickReservationManager, EventManager eventManager, Event event, int maxAmountOfTicket, List<TicketReservationWithOptionalCodeModification> res, Optional<SpecialPrice> specialCode, ZonedDateTime now, TicketReservationModification r) {
    TicketCategory tc = eventManager.getTicketCategoryById(r.getTicketCategoryId(), event.getId());
    SaleableTicketCategory ticketCategory = new SaleableTicketCategory(tc, "", now, event, tickReservationManager.countAvailableTickets(event, tc), maxAmountOfTicket, null);
    if (!ticketCategory.getSaleable()) {
        bindingResult.reject(ErrorsCode.STEP_1_TICKET_CATEGORY_MUST_BE_SALEABLE);
        return;
    }
    res.add(new TicketReservationWithOptionalCodeModification(r, ticketCategory.isAccessRestricted() ? specialCode : Optional.empty()));
}
Also used : TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) SaleableTicketCategory(alfio.controller.decorator.SaleableTicketCategory) TicketCategory(alfio.model.TicketCategory)

Aggregations

SaleableTicketCategory (alfio.controller.decorator.SaleableTicketCategory)4 ConfigurationManager (alfio.manager.system.ConfigurationManager)2 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)2 ConfigurationKeys (alfio.model.system.ConfigurationKeys)2 IOException (java.io.IOException)2 Principal (java.security.Principal)2 ZonedDateTime (java.time.ZonedDateTime)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AllArgsConstructor (lombok.AllArgsConstructor)2 Pair (org.apache.commons.lang3.tuple.Pair)2 HttpStatus (org.springframework.http.HttpStatus)2 ResponseEntity (org.springframework.http.ResponseEntity)2 org.springframework.web.bind.annotation (org.springframework.web.bind.annotation)2 alfio.controller.api.v2.model (alfio.controller.api.v2.model)1 AdditionalService (alfio.controller.api.v2.model.AdditionalService)1 EventWithAdditionalInfo (alfio.controller.api.v2.model.EventWithAdditionalInfo)1 TicketCategory (alfio.controller.api.v2.model.TicketCategory)1 EventLoader (alfio.controller.api.v2.user.support.EventLoader)1