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;
}
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()));
}
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());
}
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()));
}
Aggregations