use of alfio.model.TicketCategory in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testUnboundedEventGeneration.
@Test
public void testUnboundedEventGeneration() {
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));
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());
assertEquals(AVAILABLE_SEATS, tickets.stream().filter(t -> t.getCategoryId() == null).count());
List<TicketCategory> ticketCategories = ticketCategoryRepository.findByEventId(event.getId());
assertEquals(1, ticketCategories.size());
assertEquals(0, ticketCategories.get(0).getMaxTickets());
}
use of alfio.model.TicketCategory in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testValidationBoundedFailedRestrictedFlag.
@Test
public void testValidationBoundedFailedRestrictedFlag() {
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, true, "", true, null, null, null, null, null));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getLeft();
String username = pair.getRight();
TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
Map<String, String> categoryDescription = ticketCategoryDescriptionRepository.descriptionForTicketCategory(category.getId());
TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 10, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", false, null, null, null, null, null);
Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username);
assertFalse(result.isSuccess());
}
use of alfio.model.TicketCategory in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testDecreaseRestrictedCategory.
@Test
public void testDecreaseRestrictedCategory() {
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, true, "", true, null, null, null, null, null));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getLeft();
String username = pair.getRight();
TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
Map<String, String> categoryDescription = ticketCategoryDescriptionRepository.descriptionForTicketCategory(category.getId());
TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 9, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null);
Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username);
assertTrue(result.isSuccess());
assertEquals(9, ticketRepository.countFreeTickets(event.getId(), category.getId()).intValue());
assertEquals(1, ticketRepository.countReleasedUnboundedTickets(event.getId()).intValue());
}
use of alfio.model.TicketCategory 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);
});
});
}
use of alfio.model.TicketCategory in project alf.io by alfio-event.
the class EventManagerIntegrationTest method testIncreaseRestrictedCategory.
@Test
public void testIncreaseRestrictedCategory() {
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, true, "", true, null, null, null, null, null));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
Event event = pair.getLeft();
String username = pair.getRight();
TicketCategory category = ticketCategoryRepository.findByEventId(event.getId()).get(0);
Map<String, String> categoryDescription = ticketCategoryDescriptionRepository.descriptionForTicketCategory(category.getId());
TicketCategoryModification tcm = new TicketCategoryModification(category.getId(), category.getName(), 11, DateTimeModification.fromZonedDateTime(category.getUtcInception()), DateTimeModification.fromZonedDateTime(category.getUtcExpiration()), categoryDescription, category.getPrice(), true, "", true, null, null, null, null, null);
Result<TicketCategory> result = eventManager.updateCategory(category.getId(), event, tcm, username);
assertTrue(result.isSuccess());
assertEquals(11, ticketRepository.countFreeTickets(event.getId(), category.getId()).intValue());
}
Aggregations