Search in sources :

Example 6 with TicketCategoryModification

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);
}
Also used : Category(alfio.model.modification.AdminReservationModification.Category) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Attendee(alfio.model.modification.AdminReservationModification.Attendee)

Example 7 with TicketCategoryModification

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);
        }
    });
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ZoneId(java.time.ZoneId) TicketCategoryModification(alfio.model.modification.TicketCategoryModification)

Example 8 with TicketCategoryModification

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)));
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) WaitingQueueRepository(alfio.repository.WaitingQueueRepository) TicketReservationRepository(alfio.repository.TicketReservationRepository) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) ConfigurationManager(alfio.manager.system.ConfigurationManager) EventModification(alfio.model.modification.EventModification) StringUtils(org.apache.commons.lang3.StringUtils) DateTimeModification(alfio.model.modification.DateTimeModification) RepositoryConfiguration(alfio.config.RepositoryConfiguration) BigDecimal(java.math.BigDecimal) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Pair(org.apache.commons.lang3.tuple.Pair) LocalTime(java.time.LocalTime) AuthorityRepository(alfio.repository.user.AuthorityRepository) Before(org.junit.Before) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) Collections.emptyMap(java.util.Collections.emptyMap) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketRepository(alfio.repository.TicketRepository) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) EventRepository(alfio.repository.EventRepository) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) DateUtils(org.apache.commons.lang3.time.DateUtils) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) TestConfiguration(alfio.TestConfiguration) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Assert.assertEquals(org.junit.Assert.assertEquals) Transactional(org.springframework.transaction.annotation.Transactional) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Test(org.junit.Test)

Example 9 with TicketCategoryModification

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);
}
Also used : DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TemplateManager(alfio.util.TemplateManager) ReservationApiController(alfio.controller.api.ReservationApiController) Before(org.junit.Before)

Aggregations

TicketCategoryModification (alfio.model.modification.TicketCategoryModification)9 DateTimeModification (alfio.model.modification.DateTimeModification)7 Before (org.junit.Before)6 EventModification (alfio.model.modification.EventModification)4 TestConfiguration (alfio.TestConfiguration)3 DataSourceConfiguration (alfio.config.DataSourceConfiguration)3 Initializer (alfio.config.Initializer)3 RepositoryConfiguration (alfio.config.RepositoryConfiguration)3 ConfigurationManager (alfio.manager.system.ConfigurationManager)3 UserManager (alfio.manager.user.UserManager)3 alfio.model (alfio.model)3 DateTimeModification.fromZonedDateTime (alfio.model.modification.DateTimeModification.fromZonedDateTime)3 ConfigurationKeys (alfio.model.system.ConfigurationKeys)3 EventRepository (alfio.repository.EventRepository)3 TicketRepository (alfio.repository.TicketRepository)3 TicketReservationRepository (alfio.repository.TicketReservationRepository)3 WaitingQueueRepository (alfio.repository.WaitingQueueRepository)3 ConfigurationRepository (alfio.repository.system.ConfigurationRepository)3 AuthorityRepository (alfio.repository.user.AuthorityRepository)3 OrganizationRepository (alfio.repository.user.OrganizationRepository)3