Search in sources :

Example 1 with TicketCategoryModification

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

the class ConfigurationManagerIntegrationTest method prepareEnv.

@Before
public void prepareEnv() {
    // setup...
    organizationRepository.create("org", "org", "email@example.com");
    Organization organization = organizationRepository.findByName("org").get();
    userManager.insertUser(organization.getId(), USERNAME, "test", "test", "test@example.com", Role.OWNER, User.Type.INTERNAL);
    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description");
    desc.put("it", "muh description");
    desc.put("de", "muh description");
    List<TicketCategoryModification> ticketsCategory = Collections.singletonList(new TicketCategoryModification(null, "default", 20, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), Collections.singletonMap("en", "desc"), BigDecimal.TEN, false, "", false, null, null, null, null, null));
    EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", null, null, "eventShortName", "displayName", organization.getId(), "muh location", "0.0", "0.0", ZoneId.systemDefault().getId(), desc, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), BigDecimal.TEN, "CHF", 20, BigDecimal.ONE, true, null, ticketsCategory, false, new LocationDescriptor("", "", "", ""), 7, null, null);
    eventManager.createEvent(em);
    event = eventManager.getSingleEvent("eventShortName", "test");
    ticketCategory = ticketCategoryRepository.findAllTicketCategories(event.getId()).get(0);
}
Also used : Organization(alfio.model.user.Organization) DateTimeModification(alfio.model.modification.DateTimeModification) LocationDescriptor(alfio.model.modification.support.LocationDescriptor) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) EventModification(alfio.model.modification.EventModification) Before(org.junit.Before)

Example 2 with TicketCategoryModification

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

the class UploadedResourceIntegrationTest 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";
}
Also used : DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Event(alfio.model.Event) Before(org.junit.Before)

Example 3 with TicketCategoryModification

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

the class WaitingQueueProcessorIntegrationTest method initSoldOutEvent.

private Pair<String, Event> initSoldOutEvent(boolean withUnboundedCategory) throws InterruptedException {
    int boundedCategorySize = AVAILABLE_SEATS - (withUnboundedCategory ? 1 : 0);
    List<TicketCategoryModification> categories = new ArrayList<>();
    categories.add(new TicketCategoryModification(null, "default", boundedCategorySize, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", true, null, null, null, null, null));
    if (withUnboundedCategory) {
        categories.add(new TicketCategoryModification(null, "unbounded", 0, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION, BigDecimal.ZERO, false, "", false, null, null, null, null, null));
    }
    Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = pair.getKey();
    List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event);
    TicketCategory bounded = ticketCategories.stream().filter(t -> t.getName().equals("default")).findFirst().orElseThrow(IllegalStateException::new);
    List<Integer> boundedReserved = ticketRepository.selectFreeTicketsForPreReservation(event.getId(), 20, bounded.getId());
    assertEquals(boundedCategorySize, boundedReserved.size());
    List<Integer> reserved = new ArrayList<>(boundedReserved);
    String reservationId = UUID.randomUUID().toString();
    ticketReservationRepository.createNewReservation(reservationId, DateUtils.addHours(new Date(), 1), null, Locale.ITALIAN.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
    List<Integer> reservedForUpdate = withUnboundedCategory ? reserved.subList(0, 19) : reserved;
    ticketRepository.reserveTickets(reservationId, reservedForUpdate, bounded.getId(), Locale.ITALIAN.getLanguage(), 0);
    if (withUnboundedCategory) {
        TicketCategory unbounded = ticketCategories.stream().filter(t -> t.getName().equals("unbounded")).findFirst().orElseThrow(IllegalStateException::new);
        List<Integer> unboundedReserved = ticketRepository.selectNotAllocatedFreeTicketsForPreReservation(event.getId(), 20);
        assertEquals(1, unboundedReserved.size());
        reserved.addAll(unboundedReserved);
        ticketRepository.reserveTickets(reservationId, reserved.subList(19, 20), unbounded.getId(), Locale.ITALIAN.getLanguage(), 0);
    }
    ticketRepository.updateTicketsStatusWithReservationId(reservationId, Ticket.TicketStatus.ACQUIRED.name());
    // sold-out
    waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event), "peppino@garibaldi.com", null, Locale.ENGLISH);
    // we are testing ordering, not concurrency...
    Thread.sleep(100L);
    waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event), "bixio@mille.org", null, Locale.ITALIAN);
    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
    assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT)));
    // the following call shouldn't have any effect
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
    return Pair.of(reservationId, event);
}
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) LocalDate(java.time.LocalDate) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification)

Example 4 with TicketCategoryModification

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

the class WaitingQueueProcessorIntegrationTest method testAddSeatsAfterSoldOutWithoutUnbounded.

@Test
public void testAddSeatsAfterSoldOutWithoutUnbounded() throws InterruptedException {
    Pair<String, Event> pair = initSoldOutEvent(false);
    Event event = pair.getRight();
    EventModification eventModification = new EventModification(event.getId(), event.getType(), event.getWebsiteUrl(), event.getExternalUrl(), event.getTermsAndConditionsUrl(), event.getImageUrl(), event.getFileBlobId(), event.getShortName(), event.getDisplayName(), event.getOrganizationId(), event.getLocation(), event.getLatitude(), event.getLongitude(), event.getZoneId().getId(), emptyMap(), fromZonedDateTime(event.getBegin()), fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), eventRepository.countExistingTickets(event.getId()) + 1, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), Collections.emptyList(), event.isFreeOfCharge(), null, event.getLocales(), Collections.emptyList(), Collections.emptyList());
    eventManager.updateEventPrices(event, eventModification, "admin");
    // that should create an additional "RELEASED" ticket, but it won't be linked to any category, so the following call won't have any effect
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(0, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    // explicitly expand the category
    TicketCategory category = eventManager.loadTicketCategories(event).get(0);
    eventManager.updateCategory(category.getId(), event.getId(), new TicketCategoryModification(category.getId(), category.getName(), category.getMaxTickets() + 1, fromZonedDateTime(category.getInception(event.getZoneId())), fromZonedDateTime(category.getExpiration(event.getZoneId())), emptyMap(), category.getPrice(), category.isAccessRestricted(), "", category.isBounded(), null, null, null, null, null), "admin");
    // now the waiting queue processor should create the reservation for the first in line
    waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
    subscriptions = waitingQueueRepository.loadAll(event.getId());
    assertEquals(1, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
    Optional<WaitingQueueSubscription> first = subscriptions.stream().filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst();
    assertTrue(first.isPresent());
    assertEquals("Giuseppe Garibaldi", first.get().getFullName());
}
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) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) EventModification(alfio.model.modification.EventModification) Test(org.junit.Test)

Example 5 with TicketCategoryModification

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

the class AdminReservationManager method createCategory.

private Result<TicketCategory> createCategory(TicketsInfo ti, Event event, AdminReservationModification reservation, String username) {
    Category category = ti.getCategory();
    List<Attendee> attendees = ti.getAttendees();
    DateTimeModification inception = fromZonedDateTime(ZonedDateTime.now(event.getZoneId()));
    int tickets = attendees.size();
    TicketCategoryModification tcm = new TicketCategoryModification(category.getExistingCategoryId(), category.getName(), tickets, inception, reservation.getExpiration(), Collections.emptyMap(), category.getPrice(), true, "", true, null, null, null, null, null);
    int notAllocated = getNotAllocatedTickets(event);
    int missingTickets = Math.max(tickets - notAllocated, 0);
    Event modified = increaseSeatsIfNeeded(ti, event, missingTickets, event);
    return eventManager.insertCategory(modified, tcm, username).map(id -> ticketCategoryRepository.getByIdAndActive(id, event.getId()));
}
Also used : Category(alfio.model.modification.AdminReservationModification.Category) DateTimeModification(alfio.model.modification.DateTimeModification) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) Attendee(alfio.model.modification.AdminReservationModification.Attendee)

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