Search in sources :

Example 41 with Event

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 + "/";
}
Also used : Event(alfio.model.Event) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with Event

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());
}
Also used : SpecialPrice(alfio.model.SpecialPrice) Event(alfio.model.Event)

Example 43 with Event

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;
}
Also used : Organization(alfio.model.user.Organization) Event(alfio.model.Event) ContentLanguage(alfio.model.ContentLanguage) SendCodeModification(alfio.model.modification.SendCodeModification)

Example 44 with Event

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);
        }
    }
}
Also used : Event(alfio.model.Event) TicketCategory(alfio.model.TicketCategory) DataAccessException(org.springframework.dao.DataAccessException)

Example 45 with Event

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());
}
Also used : Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Aggregations

Event (alfio.model.Event)71 Test (org.junit.Test)28 Ticket (alfio.model.Ticket)24 TicketCategory (alfio.model.TicketCategory)21 Organization (alfio.model.user.Organization)13 java.util (java.util)11 ZonedDateTime (java.time.ZonedDateTime)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 BigDecimal (java.math.BigDecimal)9 TicketReservation (alfio.model.TicketReservation)7 ConfigurationKeys (alfio.model.system.ConfigurationKeys)7 Collectors (java.util.stream.Collectors)7 Log4j2 (lombok.extern.log4j.Log4j2)7 StringUtils (org.apache.commons.lang3.StringUtils)7 ConfigurationManager (alfio.manager.system.ConfigurationManager)6 Configuration (alfio.model.system.Configuration)5 TicketRepository (alfio.repository.TicketRepository)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Triple (org.apache.commons.lang3.tuple.Triple)5 UserManager (alfio.manager.user.UserManager)4