use of alfio.model.modification.AdminReservationModification.TicketsInfo 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()));
}
use of alfio.model.modification.AdminReservationModification.TicketsInfo 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()));
}
use of alfio.model.modification.AdminReservationModification.TicketsInfo in project alf.io by alfio-event.
the class AdminReservationManager method reserveForTicketsInfo.
private Result<List<Ticket>> reserveForTicketsInfo(Event event, AdminReservationModification arm, String reservationId, String specialPriceSessionId, Pair<TicketCategory, TicketsInfo> pair) {
TicketCategory category = pair.getLeft();
TicketsInfo ticketsInfo = pair.getRight();
int categoryId = category.getId();
List<Attendee> attendees = ticketsInfo.getAttendees();
List<Integer> reservedForUpdate = ticketReservationManager.reserveTickets(event.getId(), categoryId, attendees.size(), singletonList(Ticket.TicketStatus.FREE));
if (reservedForUpdate.size() != attendees.size()) {
return Result.error(ErrorCode.CategoryError.NOT_ENOUGH_SEATS);
}
ticketRepository.reserveTickets(reservationId, reservedForUpdate, categoryId, arm.getLanguage(), category.getSrcPriceCts());
Ticket ticket = ticketRepository.findById(reservedForUpdate.get(0), categoryId);
TicketPriceContainer priceContainer = TicketPriceContainer.from(ticket, null, event, null);
ticketRepository.updateTicketPrice(reservedForUpdate, categoryId, event.getId(), category.getSrcPriceCts(), MonetaryUtil.unitToCents(priceContainer.getFinalPrice()), MonetaryUtil.unitToCents(priceContainer.getVAT()), MonetaryUtil.unitToCents(priceContainer.getAppliedDiscount()));
List<SpecialPrice> codes = category.isAccessRestricted() ? bindSpecialPriceTokens(specialPriceSessionId, categoryId, attendees) : Collections.emptyList();
assignTickets(event, attendees, categoryId, reservedForUpdate, codes, reservationId, arm.getLanguage(), category.getSrcPriceCts());
List<Ticket> tickets = reservedForUpdate.stream().map(id -> ticketRepository.findById(id, categoryId)).collect(toList());
return Result.success(tickets);
}
use of alfio.model.modification.AdminReservationModification.TicketsInfo in project alf.io by alfio-event.
the class AdminReservationManager method createReservation.
private Result<Pair<TicketReservation, List<Ticket>>> createReservation(Result<List<TicketsInfo>> input, Event event, AdminReservationModification arm) {
final TicketsInfo empty = new TicketsInfo(null, null, false, false);
return input.flatMap(t -> {
String reservationId = UUID.randomUUID().toString();
String specialPriceSessionId = UUID.randomUUID().toString();
Date validity = Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant());
ticketReservationRepository.createNewReservation(reservationId, validity, null, arm.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded());
AdminReservationModification.CustomerData customerData = arm.getCustomerData();
ticketReservationRepository.updateTicketReservation(reservationId, TicketReservationStatus.PENDING.name(), customerData.getEmailAddress(), customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(), arm.getLanguage(), null, null, null);
Result<List<Ticket>> result = flattenTicketsInfo(event, empty, t).map(pair -> reserveForTicketsInfo(event, arm, reservationId, specialPriceSessionId, pair)).reduce(this::reduceReservationResults).orElseGet(() -> Result.error(ErrorCode.custom("", "unknown error")));
updateInvoiceReceiptModel(event, arm.getLanguage(), reservationId);
return result.map(list -> Pair.of(ticketReservationRepository.findReservationById(reservationId), list));
});
}
use of alfio.model.modification.AdminReservationModification.TicketsInfo 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());
}
Aggregations