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