Search in sources :

Example 1 with CustomerData

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

the class AdminReservationManagerIntegrationTest method testReserveFromNewCategory.

@Test
public void testReserveFromNewCategory() throws Exception {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null));
    Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = eventWithUsername.getKey();
    String username = eventWithUsername.getValue();
    DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
    CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
    Category category = new Category(null, "name", new BigDecimal("100.00"));
    int attendees = AVAILABLE_SEATS;
    List<TicketsInfo> ticketsInfoList = Collections.singletonList(new TicketsInfo(category, generateAttendees(attendees), true, false));
    AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
    Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
    assertTrue(result.isSuccess());
    Pair<TicketReservation, List<Ticket>> data = result.getData();
    List<Ticket> tickets = data.getRight();
    assertTrue(tickets.size() == attendees);
    assertNotNull(data.getLeft());
    int categoryId = tickets.get(0).getCategoryId();
    Event modified = eventManager.getSingleEvent(event.getShortName(), username);
    assertEquals(attendees + 1, eventRepository.countExistingTickets(event.getId()).intValue());
    assertEquals(attendees, ticketRepository.findPendingTicketsInCategories(Collections.singletonList(categoryId)).size());
    TicketCategory categoryModified = ticketCategoryRepository.getByIdAndActive(categoryId, event.getId());
    assertEquals(categoryModified.getMaxTickets(), attendees);
    ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
    adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
    ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId()).contains(data.getLeft().getId()));
}
Also used : Category(alfio.model.modification.AdminReservationModification.Category) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) BigDecimal(java.math.BigDecimal) Collectors.toList(java.util.stream.Collectors.toList) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 2 with CustomerData

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

the class AdminReservationManagerIntegrationTest method testReserveMixed.

@Test
public void testReserveMixed() throws Exception {
    List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 1, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null));
    Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = eventWithUsername.getKey();
    String username = eventWithUsername.getValue();
    DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
    CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
    TicketCategory existingCategory = ticketCategoryRepository.findByEventId(event.getId()).get(0);
    Category resExistingCategory = new Category(existingCategory.getId(), "", existingCategory.getPrice());
    Category resNewCategory = new Category(null, "name", new BigDecimal("100.00"));
    int attendees = 1;
    List<TicketsInfo> ticketsInfoList = Arrays.asList(new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false), new TicketsInfo(resNewCategory, generateAttendees(attendees), false, false), new TicketsInfo(resExistingCategory, generateAttendees(attendees), false, false));
    AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
    Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
    assertTrue(result.isSuccess());
    Pair<TicketReservation, List<Ticket>> data = result.getData();
    List<Ticket> tickets = data.getRight();
    assertTrue(tickets.size() == 3);
    assertNotNull(data.getLeft());
    assertTrue(tickets.stream().allMatch(t -> t.getTicketsReservationId().equals(data.getKey().getId())));
    int resExistingCategoryId = tickets.get(0).getCategoryId();
    int resNewCategoryId = tickets.get(2).getCategoryId();
    Event modified = eventManager.getSingleEvent(event.getShortName(), username);
    assertEquals(AVAILABLE_SEATS, eventRepository.countExistingTickets(event.getId()).intValue());
    assertEquals(3, ticketRepository.findPendingTicketsInCategories(Arrays.asList(resExistingCategoryId, resNewCategoryId)).size());
    assertEquals(3, ticketRepository.findTicketsInReservation(data.getLeft().getId()).size());
    String reservationId = data.getLeft().getId();
    assertEquals(ticketRepository.findTicketsInReservation(reservationId).stream().findFirst().get().getId(), ticketRepository.findFirstTicketInReservation(reservationId).get().getId());
    ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
    adminReservationManager.confirmReservation(event.getShortName(), data.getLeft().getId(), username);
    ticketCategoryRepository.findByEventId(event.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.TAKEN)));
    assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId()).contains(data.getLeft().getId()));
}
Also used : alfio.repository(alfio.repository) IntStream(java.util.stream.IntStream) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Attendee(alfio.model.modification.AdminReservationModification.Attendee) 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) Triple(org.apache.commons.lang3.tuple.Triple) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Test(org.junit.Test) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) Collectors.toList(java.util.stream.Collectors.toList) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Category(alfio.model.modification.AdminReservationModification.Category) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Category(alfio.model.modification.AdminReservationModification.Category) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) BigDecimal(java.math.BigDecimal) Collectors.toList(java.util.stream.Collectors.toList) Pair(org.apache.commons.lang3.tuple.Pair) Test(org.junit.Test)

Example 3 with CustomerData

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

the class AdminReservationRequestManager method spread.

private Stream<AdminReservationModification> spread(AdminReservationModification src, boolean single) {
    if (single) {
        return Stream.of(src);
    }
    return src.getTicketsInfo().stream().flatMap(ti -> ti.getAttendees().stream().map(a -> Pair.of(a, new AdminReservationModification.TicketsInfo(ti.getCategory(), singletonList(a), ti.isAddSeatsIfNotAvailable(), ti.isUpdateAttendees())))).map(p -> {
        AdminReservationModification.Attendee attendee = p.getLeft();
        String language = StringUtils.defaultIfBlank(attendee.getLanguage(), src.getLanguage());
        CustomerData cd = new CustomerData(attendee.getFirstName(), attendee.getLastName(), attendee.getEmailAddress(), null, language);
        return new AdminReservationModification(src.getExpiration(), cd, singletonList(p.getRight()), language, src.isUpdateContactData(), src.getNotification());
    });
}
Also used : TransactionDefinition(org.springframework.transaction.TransactionDefinition) RequiredArgsConstructor(lombok.RequiredArgsConstructor) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) Json(alfio.util.Json) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) Map(java.util.Map) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) Optional.ofNullable(java.util.Optional.ofNullable) User(alfio.model.user.User) UUID(java.util.UUID) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) EventRepository(alfio.repository.EventRepository) Collectors(java.util.stream.Collectors) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) List(java.util.List) Stream(java.util.stream.Stream) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdminReservationRequestRepository(alfio.repository.AdminReservationRequestRepository) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) AdminReservationModification(alfio.model.modification.AdminReservationModification) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) Transactional(org.springframework.transaction.annotation.Transactional) AdminReservationModification(alfio.model.modification.AdminReservationModification) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData)

Example 4 with CustomerData

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

the class AdminReservationManagerIntegrationTest method performExistingCategoryTest.

private Triple<Event, String, TicketReservation> performExistingCategoryTest(List<TicketCategoryModification> categories, boolean bounded, List<Integer> attendeesNr, boolean addSeatsIfNotAvailable, boolean expectSuccess, int reservedTickets, int expectedEventSeats) {
    assertEquals("Test error: categories' size must be equal to attendees' size", categories.size(), attendeesNr.size());
    Pair<Event, String> eventWithUsername = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
    Event event = eventWithUsername.getKey();
    String username = eventWithUsername.getValue();
    DateTimeModification expiration = DateTimeModification.fromZonedDateTime(ZonedDateTime.now().plusDays(1));
    CustomerData customerData = new CustomerData("Integration", "Test", "integration-test@test.ch", "Billing Address", "en");
    Iterator<Integer> attendeesIterator = attendeesNr.iterator();
    List<TicketCategory> existingCategories = ticketCategoryRepository.findByEventId(event.getId());
    List<Attendee> allAttendees = new ArrayList<>();
    List<TicketsInfo> ticketsInfoList = existingCategories.stream().map(existingCategory -> {
        Category category = new Category(existingCategory.getId(), existingCategory.getName(), existingCategory.getPrice());
        List<Attendee> attendees = generateAttendees(attendeesIterator.next());
        allAttendees.addAll(attendees);
        return new TicketsInfo(category, attendees, addSeatsIfNotAvailable, false);
    }).collect(toList());
    AdminReservationModification modification = new AdminReservationModification(expiration, customerData, ticketsInfoList, "en", false, null);
    if (reservedTickets > 0) {
        TicketReservationModification trm = new TicketReservationModification();
        trm.setAmount(reservedTickets);
        trm.setTicketCategoryId(existingCategories.get(0).getId());
        TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty());
        ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), DateUtils.addDays(new Date(), 1), Optional.empty(), Optional.empty(), Locale.ENGLISH, false);
    }
    Result<Pair<TicketReservation, List<Ticket>>> result = adminReservationManager.createReservation(modification, event.getShortName(), username);
    if (expectSuccess) {
        validateSuccess(bounded, attendeesNr, event, username, existingCategories, result, allAttendees, expectedEventSeats, reservedTickets);
    } else {
        assertFalse(result.isSuccess());
        return null;
    }
    return Triple.of(eventWithUsername.getLeft(), eventWithUsername.getRight(), result.getData().getKey());
}
Also used : alfio.repository(alfio.repository) IntStream(java.util.stream.IntStream) java.util(java.util) BeforeClass(org.junit.BeforeClass) ZonedDateTime(java.time.ZonedDateTime) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) Attendee(alfio.model.modification.AdminReservationModification.Attendee) 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) Triple(org.apache.commons.lang3.tuple.Triple) OrganizationRepository(alfio.repository.user.OrganizationRepository) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Test(org.junit.Test) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) IntegrationTestUtil(alfio.test.util.IntegrationTestUtil) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) Collectors.toList(java.util.stream.Collectors.toList) Initializer(alfio.config.Initializer) alfio.model(alfio.model) UserManager(alfio.manager.user.UserManager) ContextConfiguration(org.springframework.test.context.ContextConfiguration) LocalDate(java.time.LocalDate) DataSourceConfiguration(alfio.config.DataSourceConfiguration) Category(alfio.model.modification.AdminReservationModification.Category) TestConfiguration(alfio.TestConfiguration) Assert(org.junit.Assert) alfio.model.modification(alfio.model.modification) Transactional(org.springframework.transaction.annotation.Transactional) Category(alfio.model.modification.AdminReservationModification.Category) CustomerData(alfio.model.modification.AdminReservationModification.CustomerData) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Attendee(alfio.model.modification.AdminReservationModification.Attendee) LocalDate(java.time.LocalDate) Collectors.toList(java.util.stream.Collectors.toList) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

CustomerData (alfio.model.modification.AdminReservationModification.CustomerData)4 Pair (org.apache.commons.lang3.tuple.Pair)4 alfio.model (alfio.model)3 Category (alfio.model.modification.AdminReservationModification.Category)3 TicketsInfo (alfio.model.modification.AdminReservationModification.TicketsInfo)3 Result (alfio.model.result.Result)3 BigDecimal (java.math.BigDecimal)3 Collectors.toList (java.util.stream.Collectors.toList)3 Triple (org.apache.commons.lang3.tuple.Triple)3 Transactional (org.springframework.transaction.annotation.Transactional)3 TestConfiguration (alfio.TestConfiguration)2 DataSourceConfiguration (alfio.config.DataSourceConfiguration)2 Initializer (alfio.config.Initializer)2 RepositoryConfiguration (alfio.config.RepositoryConfiguration)2 UserManager (alfio.manager.user.UserManager)2 alfio.model.modification (alfio.model.modification)2 Attendee (alfio.model.modification.AdminReservationModification.Attendee)2 alfio.repository (alfio.repository)2 OrganizationRepository (alfio.repository.user.OrganizationRepository)2 IntegrationTestUtil (alfio.test.util.IntegrationTestUtil)2