use of alfio.model.modification.AdminReservationModification.Attendee in project alf.io by alfio-event.
the class AdminReservationManager method reserveForTicketsInfo.
private Result<List<Ticket>> reserveForTicketsInfo(Event event, AdminReservationModification arm, String reservationId, 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.isEmpty() || reservedForUpdate.size() != attendees.size()) {
return Result.error(ErrorCode.CategoryError.NOT_ENOUGH_SEATS);
}
var currencyCode = category.getCurrencyCode();
ticketRepository.reserveTickets(reservationId, reservedForUpdate, category, arm.getLanguage(), event.getVatStatus(), i -> null);
Ticket ticket = ticketRepository.findById(reservedForUpdate.get(0), categoryId);
TicketPriceContainer priceContainer = TicketPriceContainer.from(ticket, null, event.getVat(), event.getVatStatus(), null);
ticketRepository.updateTicketPrice(reservedForUpdate, categoryId, event.getId(), category.getSrcPriceCts(), unitToCents(priceContainer.getFinalPrice(), currencyCode), unitToCents(priceContainer.getVAT(), currencyCode), unitToCents(priceContainer.getAppliedDiscount(), currencyCode), currencyCode, priceContainer.getVatStatus());
List<SpecialPrice> codes = category.isAccessRestricted() ? bindSpecialPriceTokens(categoryId, attendees) : Collections.emptyList();
if (category.isAccessRestricted() && codes.size() < attendees.size()) {
return Result.error(ErrorCode.CategoryError.NOT_ENOUGH_SEATS);
}
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.Attendee in project alf.io by alfio-event.
the class AdminReservationManager method assignTickets.
private void assignTickets(Event event, List<Attendee> attendees, int categoryId, List<Integer> reservedForUpdate, List<SpecialPrice> codes, String reservationId, String userLanguage, int srcPriceCts) {
Optional<Iterator<SpecialPrice>> specialPriceIterator = Optional.of(codes).filter(c -> !c.isEmpty()).map(Collection::iterator);
for (int i = 0; i < reservedForUpdate.size(); i++) {
Attendee attendee = attendees.get(i);
Integer ticketId = reservedForUpdate.get(i);
if (!attendee.isEmpty()) {
ticketRepository.updateTicketOwnerById(ticketId, attendee.getEmailAddress(), attendee.getFullName(), attendee.getFirstName(), attendee.getLastName());
if (StringUtils.isNotBlank(attendee.getReference()) || attendee.isReassignmentForbidden()) {
updateExtRefAndLocking(categoryId, attendee, ticketId);
}
if (!attendee.getAdditionalInfo().isEmpty()) {
ticketFieldRepository.updateOrInsert(attendee.getAdditionalInfo(), ticketId, event.getId());
}
}
specialPriceIterator.map(Iterator::next).ifPresent(code -> ticketRepository.reserveTicket(reservationId, ticketId, code.getId(), userLanguage, srcPriceCts, event.getCurrency(), event.getVatStatus(), null));
}
}
use of alfio.model.modification.AdminReservationModification.Attendee in project alf.io by alfio-event.
the class AdminReservationManagerIntegrationTest method validateSuccess.
private void validateSuccess(boolean bounded, List<Integer> attendeesNr, Event event, String username, List<TicketCategory> existingCategories, Result<Pair<TicketReservation, List<Ticket>>> result, List<Attendee> allAttendees, int expectedEventSeats, int reservedTickets) {
assertTrue(result.isSuccess());
Pair<TicketReservation, List<Ticket>> data = result.getData();
assertTrue(data.getRight().size() == attendeesNr.stream().mapToInt(i -> i).sum());
assertNotNull(data.getLeft());
Event modified = eventManager.getSingleEvent(event.getShortName(), username);
assertEquals(expectedEventSeats, eventRepository.countExistingTickets(event.getId()).intValue());
List<Ticket> tickets = ticketRepository.findPendingTicketsInCategories(existingCategories.stream().map(TicketCategory::getId).collect(toList()));
assertEquals(attendeesNr.stream().mapToInt(i -> i).sum(), tickets.size() - reservedTickets);
if (bounded) {
final Iterator<Integer> iterator = attendeesNr.iterator();
existingCategories.forEach(existingCategory -> {
TicketCategory categoryModified = ticketCategoryRepository.getByIdAndActive(existingCategory.getId(), event.getId());
assertEquals(categoryModified.getMaxTickets(), iterator.next().intValue());
});
}
for (int i = 0; i < tickets.size() - reservedTickets; i++) {
Attendee attendee = allAttendees.get(i);
if (!attendee.isEmpty()) {
Ticket ticket = data.getRight().get(i);
assertTrue(ticket.getAssigned());
assertNotNull(ticket.getFullName());
assertEquals(attendee.getFullName(), ticket.getFullName());
assertEquals(attendee.getEmailAddress(), ticket.getEmail());
assertEquals(Ticket.TicketStatus.PENDING, ticket.getStatus());
assertEquals(data.getLeft().getId(), ticket.getTicketsReservationId());
}
}
ticketCategoryRepository.findByEventId(modified.getId()).forEach(tc -> assertTrue(specialPriceRepository.findAllByCategoryId(tc.getId()).stream().allMatch(sp -> sp.getStatus() == SpecialPrice.Status.PENDING)));
assertFalse(ticketRepository.findAllReservationsConfirmedButNotAssigned(event.getId()).contains(data.getLeft().getId()));
}
use of alfio.model.modification.AdminReservationModification.Attendee 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(), existing.getTicketAccessType(), 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())), 0, existing.getTicketCheckInStrategy(), null, AlfioMetadata.empty());
return eventManager.updateCategory(existingCategoryId, modified, tcm, username, true);
}
return Result.success(existing);
}
use of alfio.model.modification.AdminReservationModification.Attendee 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(event.now(clockProvider));
int tickets = attendees.size();
var accessType = event.getFormat() != Event.EventFormat.HYBRID ? TicketCategory.TicketAccessType.INHERIT : Objects.requireNonNull(category.getTicketAccessType());
TicketCategoryModification tcm = new TicketCategoryModification(category.getExistingCategoryId(), category.getName(), accessType, tickets, inception, reservation.getExpiration(), Collections.emptyMap(), category.getPrice(), true, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
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()));
}
Aggregations