Search in sources :

Example 1 with PreReservedTicketDistributor

use of alfio.util.PreReservedTicketDistributor in project alf.io by alfio-event.

the class WaitingQueueManager method preReserveTickets.

private void preReserveTickets(Event event, int ticketsNeeded, int eventId, int alreadyReserved) {
    final int toBeGenerated = Math.abs(alreadyReserved - ticketsNeeded);
    EventStatisticView eventStatisticView = eventRepository.findStatisticsFor(eventId);
    Map<Integer, TicketCategoryStatisticView> ticketCategoriesStats = ticketCategoryRepository.findStatisticsForEventIdByCategoryId(eventId);
    List<Pair<Integer, TicketCategoryStatisticView>> collectedTickets = ticketCategoryRepository.findAllTicketCategories(eventId).stream().filter(tc -> !tc.isAccessRestricted()).sorted(Comparator.comparing(t -> t.getExpiration(event.getZoneId()))).map(tc -> Pair.of(determineAvailableSeats(ticketCategoriesStats.get(tc.getId()), eventStatisticView), ticketCategoriesStats.get(tc.getId()))).collect(new PreReservedTicketDistributor(toBeGenerated));
    MapSqlParameterSource[] candidates = collectedTickets.stream().flatMap(p -> selectTicketsForPreReservation(eventId, p).stream()).map(id -> new MapSqlParameterSource().addValue("id", id)).toArray(MapSqlParameterSource[]::new);
    jdbc.batchUpdate(ticketRepository.preReserveTicket(), candidates);
}
Also used : java.util(java.util) TicketReservationModification(alfio.model.modification.TicketReservationModification) TicketCategoryRepository(alfio.repository.TicketCategoryRepository) AffectedRowCountAndKey(ch.digitalfondue.npjt.AffectedRowCountAndKey) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) ZonedDateTime(java.time.ZonedDateTime) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConfigurationManager(alfio.manager.system.ConfigurationManager) Supplier(java.util.function.Supplier) Pair(org.apache.commons.lang3.tuple.Pair) WorkingDaysAdjusters(alfio.util.WorkingDaysAdjusters) Triple(org.apache.commons.lang3.tuple.Triple) TemplateResource(alfio.util.TemplateResource) MessageSource(org.springframework.context.MessageSource) EventUtil.determineAvailableSeats(alfio.util.EventUtil.determineAvailableSeats) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketRepository(alfio.repository.TicketRepository) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) EventRepository(alfio.repository.EventRepository) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) Stream(java.util.stream.Stream) alfio.model(alfio.model) Configuration(alfio.model.system.Configuration) Log4j2(lombok.extern.log4j.Log4j2) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) PreReservedTicketDistributor(alfio.util.PreReservedTicketDistributor) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) PreReservedTicketDistributor(alfio.util.PreReservedTicketDistributor) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ConfigurationManager (alfio.manager.system.ConfigurationManager)1 alfio.model (alfio.model)1 TicketReservationModification (alfio.model.modification.TicketReservationModification)1 TicketReservationWithOptionalCodeModification (alfio.model.modification.TicketReservationWithOptionalCodeModification)1 Configuration (alfio.model.system.Configuration)1 ConfigurationKeys (alfio.model.system.ConfigurationKeys)1 Organization (alfio.model.user.Organization)1 EventRepository (alfio.repository.EventRepository)1 TicketCategoryRepository (alfio.repository.TicketCategoryRepository)1 TicketRepository (alfio.repository.TicketRepository)1 WaitingQueueRepository (alfio.repository.WaitingQueueRepository)1 OrganizationRepository (alfio.repository.user.OrganizationRepository)1 EventUtil.determineAvailableSeats (alfio.util.EventUtil.determineAvailableSeats)1 PreReservedTicketDistributor (alfio.util.PreReservedTicketDistributor)1 TemplateManager (alfio.util.TemplateManager)1 TemplateResource (alfio.util.TemplateResource)1 WorkingDaysAdjusters (alfio.util.WorkingDaysAdjusters)1 AffectedRowCountAndKey (ch.digitalfondue.npjt.AffectedRowCountAndKey)1 ZonedDateTime (java.time.ZonedDateTime)1 java.util (java.util)1