Search in sources :

Example 16 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testIncreaseEventSeatsWithABoundedCategory.

@Test
public void testIncreaseEventSeatsWithABoundedCategory() {
    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, "", true, 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(), 40, 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(20, tickets.size());
    assertEquals(20, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
    assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() != null).count());
}
Also used : Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 17 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testEventGenerationWithOverflow.

@Test(expected = IllegalArgumentException.class)
public void testEventGenerationWithOverflow() {
    List<TicketCategoryModification> categories = Arrays.asList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null), new TicketCategoryModification(null, "default", 0, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
    Event event = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository).getKey();
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, tickets.size());
    assertTrue(tickets.stream().noneMatch(t -> t.getCategoryId() == null));
}
Also used : alfio.repository(alfio.repository) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) OrganizationRepository(alfio.repository.user.OrganizationRepository) Test(org.junit.Test) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ZoneId(java.time.ZoneId) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) TicketCategory(alfio.model.TicketCategory) Initializer(alfio.config.Initializer) Ticket(alfio.model.Ticket) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Event(alfio.model.Event) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Ticket(alfio.model.Ticket) Event(alfio.model.Event) Test(org.junit.Test)

Example 18 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class CustomMessageManager method preview.

private List<MessageModification> preview(Event event, List<MessageModification> input, String username) {
    Model model = new ExtendedModelMap();
    Organization organization = eventManager.loadOrganizer(event, username);
    model.addAttribute("eventName", event.getDisplayName());
    model.addAttribute("fullName", "John Doe");
    model.addAttribute("organizationName", organization.getName());
    model.addAttribute("organizationEmail", organization.getEmail());
    model.addAttribute("reservationURL", "https://this-is-the-reservation-url");
    model.addAttribute("ticketURL", "https://this-is-the-ticket-url");
    model.addAttribute("reservationID", "RESID");
    return input.stream().map(m -> MessageModification.preview(m, renderResource(m.getSubject(), model, m.getLocale(), templateManager), renderResource(m.getText(), model, m.getLocale(), templateManager), m.isAttachTicket())).collect(Collectors.toList());
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) MessageModification(alfio.model.modification.MessageModification) Autowired(org.springframework.beans.factory.annotation.Autowired) Mailer(alfio.manager.system.Mailer) Json(alfio.util.Json) Model(org.springframework.ui.Model) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Triple(org.apache.commons.lang3.tuple.Triple) TicketRepository(alfio.repository.TicketRepository) Executor(java.util.concurrent.Executor) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TicketReservationManager(alfio.manager.TicketReservationManager) TicketCategory(alfio.model.TicketCategory) Component(org.springframework.stereotype.Component) EventManager(alfio.manager.EventManager) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Ticket(alfio.model.Ticket) NotificationManager(alfio.manager.NotificationManager) TicketReservation(alfio.model.TicketReservation) Log4j2(lombok.extern.log4j.Log4j2) Event(alfio.model.Event) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Organization(alfio.model.user.Organization) Model(org.springframework.ui.Model)

Example 19 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class CustomMessageManager method sendMessages.

public void sendMessages(String eventName, Optional<Integer> categoryId, List<MessageModification> input, String username) {
    Event event = eventManager.getSingleEvent(eventName, username);
    // dry run for checking the syntax
    preview(event, input, username);
    Organization organization = eventManager.loadOrganizer(event, username);
    AtomicInteger counter = new AtomicInteger();
    Map<String, List<MessageModification>> byLanguage = input.stream().collect(Collectors.groupingBy(m -> m.getLocale().getLanguage()));
    sendMessagesExecutor.execute(() -> {
        categoryId.map(id -> ticketRepository.findConfirmedByCategoryId(event.getId(), id)).orElseGet(() -> ticketRepository.findAllConfirmed(event.getId())).stream().filter(t -> isNotBlank(t.getFullName()) && isNotBlank(t.getEmail())).parallel().map(t -> {
            Model model = new ExtendedModelMap();
            model.addAttribute("eventName", eventName);
            model.addAttribute("fullName", t.getFullName());
            model.addAttribute("organizationName", organization.getName());
            model.addAttribute("organizationEmail", organization.getEmail());
            model.addAttribute("reservationURL", ticketReservationManager.reservationUrl(t.getTicketsReservationId(), event));
            model.addAttribute("reservationID", ticketReservationManager.getShortReservationID(event, t.getTicketsReservationId()));
            model.addAttribute("ticketURL", ticketReservationManager.ticketUpdateUrl(event, t.getUuid()));
            return Triple.of(t, t.getEmail(), model);
        }).forEach(triple -> {
            Ticket ticket = triple.getLeft();
            MessageModification m = Optional.ofNullable(byLanguage.get(ticket.getUserLanguage())).orElseGet(() -> byLanguage.get(byLanguage.keySet().stream().findFirst().orElseThrow(IllegalStateException::new))).get(0);
            Model model = triple.getRight();
            String subject = renderResource(m.getSubject(), model, m.getLocale(), templateManager);
            String text = renderResource(m.getText(), model, m.getLocale(), templateManager);
            List<Mailer.Attachment> attachments = new ArrayList<>();
            if (m.isAttachTicket()) {
                ticketReservationManager.findById(ticket.getTicketsReservationId()).ifPresent(reservation -> {
                    ticketCategoryRepository.getByIdAndActive(ticket.getCategoryId()).ifPresent(ticketCategory -> {
                        attachments.add(generateTicketAttachment(ticket, reservation, ticketCategory, organization));
                    });
                });
            }
            counter.incrementAndGet();
            notificationManager.sendSimpleEmail(event, triple.getMiddle(), subject, () -> text, attachments);
        });
    });
}
Also used : java.util(java.util) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) MessageModification(alfio.model.modification.MessageModification) Autowired(org.springframework.beans.factory.annotation.Autowired) Mailer(alfio.manager.system.Mailer) Json(alfio.util.Json) Model(org.springframework.ui.Model) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Triple(org.apache.commons.lang3.tuple.Triple) TicketRepository(alfio.repository.TicketRepository) Executor(java.util.concurrent.Executor) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TicketReservationManager(alfio.manager.TicketReservationManager) TicketCategory(alfio.model.TicketCategory) Component(org.springframework.stereotype.Component) EventManager(alfio.manager.EventManager) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) Ticket(alfio.model.Ticket) NotificationManager(alfio.manager.NotificationManager) TicketReservation(alfio.model.TicketReservation) Log4j2(lombok.extern.log4j.Log4j2) Event(alfio.model.Event) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) Ticket(alfio.model.Ticket) Organization(alfio.model.user.Organization) ExtendedModelMap(org.springframework.ui.ExtendedModelMap) MessageModification(alfio.model.modification.MessageModification) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Model(org.springframework.ui.Model) Event(alfio.model.Event)

Example 20 with Ticket

use of alfio.model.Ticket in project alf.io by alfio-event.

the class EventManagerIntegrationTest method testAddUnboundedCategory.

/**
 * When adding an unbounded category, we won't update the tickets status, because:
 * 1) if the unbounded category is using existing seats, the event cannot be already sold-out
 * 2) if the unbounded category has been added after an event edit (add seats), then the tickets are already "RELEASED"
 * 3) if there is another unbounded category, then it is safe not to update the tickets' status, in order to not
 *    interfere with the existing category
 */
@Test
public void testAddUnboundedCategory() {
    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, "", true, null, null, null, null, null));
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    TicketCategoryModification tcm = new TicketCategoryModification(null, "default", -1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null);
    eventManager.insertCategory(event.getId(), tcm, pair.getValue());
    List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId());
    assertNotNull(tickets);
    assertFalse(tickets.isEmpty());
    assertEquals(AVAILABLE_SEATS, 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)24 Ticket (alfio.model.Ticket)24 Test (org.junit.Test)13 TicketCategory (alfio.model.TicketCategory)10 TicketReservation (alfio.model.TicketReservation)7 Organization (alfio.model.user.Organization)6 ZonedDateTime (java.time.ZonedDateTime)5 java.util (java.util)5 Triple (org.apache.commons.lang3.tuple.Triple)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 UserManager (alfio.manager.user.UserManager)4 ErrorCode (alfio.model.result.ErrorCode)4 Result (alfio.model.result.Result)4 TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 Initializer (alfio.config.Initializer)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 TicketRepository (alfio.repository.TicketRepository)3 Collectors (java.util.stream.Collectors)3 Component (org.springframework.stereotype.Component)3