use of alfio.model.Event in project alf.io by alfio-event.
the class WaitingQueueController method subscribe.
@RequestMapping(value = "/event/{eventName}/waiting-queue/subscribe", method = RequestMethod.POST)
public String subscribe(@ModelAttribute WaitingQueueSubscriptionForm subscription, BindingResult bindingResult, Model model, @PathVariable("eventName") String eventName, RedirectAttributes redirectAttributes) {
Event event = eventRepository.findOptionalByShortName(eventName).orElseThrow(IllegalArgumentException::new);
Validator.validateWaitingQueueSubscription(subscription, bindingResult, event).ifSuccess(() -> {
if (waitingQueueManager.subscribe(event, subscription.toCustomerName(event), subscription.getEmail(), subscription.getSelectedCategory(), subscription.getUserLanguage())) {
redirectAttributes.addFlashAttribute("subscriptionComplete", true);
} else {
redirectAttributes.addFlashAttribute("subscriptionError", true);
}
});
return "redirect:/event/" + eventName + "/";
}
use of alfio.model.Event in project alf.io by alfio-event.
the class SpecialPriceManager method loadSentCodes.
public List<SpecialPrice> loadSentCodes(String eventName, int categoryId, String username) {
final Event event = eventManager.getSingleEvent(eventName, username);
checkOwnership(categoryId, event, username);
Predicate<SpecialPrice> p = SpecialPrice::notSent;
return specialPriceRepository.findAllByCategoryId(categoryId).stream().filter(p.negate()).collect(toList());
}
use of alfio.model.Event in project alf.io by alfio-event.
the class SpecialPriceManager method sendCodeToAssignee.
public boolean sendCodeToAssignee(List<SendCodeModification> input, String eventName, int categoryId, String username) {
final Event event = eventManager.getSingleEvent(eventName, username);
final Organization organization = eventManager.loadOrganizer(event, username);
Set<SendCodeModification> set = new LinkedHashSet<>(input);
checkCodeAssignment(set, categoryId, event, username);
Validate.isTrue(set.stream().allMatch(IS_CODE_PRESENT), "There are missing codes. Please check input file.");
List<ContentLanguage> eventLanguages = i18nManager.getEventLanguages(event.getLocales());
Validate.isTrue(!eventLanguages.isEmpty(), "No locales have been defined for the event. Please check the configuration");
ContentLanguage defaultLocale = eventLanguages.contains(ContentLanguage.ENGLISH) ? ContentLanguage.ENGLISH : eventLanguages.get(0);
set.forEach(m -> {
Locale locale = Locale.forLanguageTag(StringUtils.defaultString(StringUtils.trimToNull(m.getLanguage()), defaultLocale.getLanguage()));
Map<String, Object> model = TemplateResource.prepareModelForSendReservedCode(organization, event, m, eventManager.getEventUrl(event));
notificationManager.sendSimpleEmail(event, m.getEmail(), messageSource.getMessage("email-code.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.SEND_RESERVED_CODE, model, locale));
int marked = specialPriceRepository.markAsSent(ZonedDateTime.now(event.getZoneId()), m.getAssignee().trim(), m.getEmail().trim(), m.getCode().trim());
Validate.isTrue(marked == 1, "Expected exactly one row updated, got " + marked);
});
return true;
}
use of alfio.model.Event 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);
}
}
}
use of alfio.model.Event in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testDecreaseEventSeatsWithAnUnboundedCategory.
@Test
public void testDecreaseEventSeatsWithAnUnboundedCategory() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getKey();
EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null);
eventManager.updateEventPrices(event, update, pair.getValue());
List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
assertNotNull(tickets);
assertFalse(tickets.isEmpty());
assertEquals(10, tickets.size());
assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count());
}
Aggregations