use of alfio.model.modification.TicketCategoryModification in project alf.io by alfio-event.
the class AdminReservationManager method checkExistingCategory.
private Result<TicketCategory> checkExistingCategory(TicketsInfo ti, Event event, String username) {
Category category = ti.getCategory();
List<Attendee> attendees = ti.getAttendees();
int tickets = attendees.size();
int eventId = event.getId();
TicketCategory existing = ticketCategoryRepository.getByIdAndActive(category.getExistingCategoryId(), eventId);
int existingCategoryId = existing.getId();
int freeTicketsInCategory = ticketRepository.countFreeTickets(eventId, existingCategoryId);
int notAllocated = getNotAllocatedTickets(event);
int missingTickets = Math.max(tickets - (freeTicketsInCategory + notAllocated), 0);
Event modified = increaseSeatsIfNeeded(ti, event, missingTickets, event);
if (freeTicketsInCategory < tickets && existing.isBounded()) {
int maxTickets = existing.getMaxTickets() + (tickets - freeTicketsInCategory);
TicketCategoryModification tcm = new TicketCategoryModification(existingCategoryId, existing.getName(), maxTickets, fromZonedDateTime(existing.getInception(modified.getZoneId())), fromZonedDateTime(existing.getExpiration(event.getZoneId())), Collections.emptyMap(), existing.getPrice(), existing.isAccessRestricted(), "", true, existing.getCode(), fromZonedDateTime(existing.getValidCheckInFrom(modified.getZoneId())), fromZonedDateTime(existing.getValidCheckInTo(modified.getZoneId())), fromZonedDateTime(existing.getTicketValidityStart(modified.getZoneId())), fromZonedDateTime(existing.getTicketValidityEnd(modified.getZoneId())));
return eventManager.updateCategory(existingCategoryId, modified, tcm, username, true);
}
return Result.success(existing);
}
use of alfio.model.modification.TicketCategoryModification in project alf.io by alfio-event.
the class EventManager method createCategoriesForEvent.
private void createCategoriesForEvent(EventModification em, Event event) {
boolean freeOfCharge = em.isFreeOfCharge();
ZoneId zoneId = TimeZone.getTimeZone(event.getTimeZone()).toZoneId();
int eventId = event.getId();
int requestedSeats = em.getTicketCategories().stream().filter(TicketCategoryModification::isBounded).mapToInt(TicketCategoryModification::getMaxTickets).sum();
int notAssignedTickets = em.getAvailableSeats() - requestedSeats;
Validate.isTrue(notAssignedTickets >= 0, "Total categories' seats cannot be more than the actual event seats");
Validate.isTrue(notAssignedTickets > 0 || em.getTicketCategories().stream().allMatch(TicketCategoryModification::isBounded), "Cannot add an unbounded category if there aren't any free tickets");
em.getTicketCategories().forEach(tc -> {
final int price = evaluatePrice(tc.getPriceInCents(), freeOfCharge);
final int maxTickets = tc.isBounded() ? tc.getMaxTickets() : 0;
final AffectedRowCountAndKey<Integer> category = ticketCategoryRepository.insert(tc.getInception().toZonedDateTime(zoneId), tc.getExpiration().toZonedDateTime(zoneId), tc.getName(), maxTickets, tc.isTokenGenerationRequested(), eventId, tc.isBounded(), price, StringUtils.trimToNull(tc.getCode()), toZonedDateTime(tc.getValidCheckInFrom(), zoneId), toZonedDateTime(tc.getValidCheckInTo(), zoneId), toZonedDateTime(tc.getTicketValidityStart(), zoneId), toZonedDateTime(tc.getTicketValidityEnd(), zoneId));
insertOrUpdateTicketCategoryDescription(category.getKey(), tc, event);
if (tc.isTokenGenerationRequested()) {
final TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(category.getKey(), event.getId());
final MapSqlParameterSource[] args = prepareTokenBulkInsertParameters(ticketCategory, ticketCategory.getMaxTickets());
jdbc.batchUpdate(specialPriceRepository.bulkInsert(), args);
}
});
}
use of alfio.model.modification.TicketCategoryModification in project alf.io by alfio-event.
the class WaitingQueueProcessorIntegrationTest method testPreRegistration.
@Test
public void testPreRegistration() {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), 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();
waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH);
waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN);
assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());
TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null);
eventManager.insertCategory(event.getId(), tcm, pair.getValue());
waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));
}
use of alfio.model.modification.TicketCategoryModification in project alf.io by alfio-event.
the class ReservationFlowIntegrationTest method ensureConfiguration.
@Before
public void ensureConfiguration() {
IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository);
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
Pair<Event, String> eventAndUser = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
event = eventAndUser.getKey();
user = eventAndUser.getValue() + "_owner";
//
TemplateManager templateManager = Mockito.mock(TemplateManager.class);
reservationApiController = new ReservationApiController(eventRepository, ticketHelper, templateManager, i18nManager, euVatChecker, ticketReservationRepository, ticketReservationManager);
}
Aggregations