Search in sources :

Example 1 with CANCEL_TICKET

use of alfio.model.Audit.EventType.CANCEL_TICKET in project alf.io by alfio-event.

the class AdminReservationManager method removeTicketsFromReservation.

private void removeTicketsFromReservation(TicketReservation reservation, Event event, List<Integer> ticketIds, boolean notify, String username, boolean removeReservation) {
    String reservationId = reservation.getId();
    if (notify && !ticketIds.isEmpty()) {
        Organization o = eventManager.loadOrganizer(event, username);
        ticketRepository.findByIds(ticketIds).forEach(t -> {
            if (StringUtils.isNotBlank(t.getEmail())) {
                sendTicketHasBeenRemoved(event, o, t);
            }
        });
    }
    Integer userId = userRepository.findIdByUserName(username).orElse(null);
    Date date = new Date();
    ticketIds.forEach(id -> auditingRepository.insert(reservationId, userId, event.getId(), CANCEL_TICKET, date, TICKET, id.toString()));
    ticketRepository.resetCategoryIdForUnboundedCategoriesWithTicketIds(ticketIds);
    ticketFieldRepository.deleteAllValuesForTicketIds(ticketIds);
    MapSqlParameterSource[] args = ticketIds.stream().map(id -> new MapSqlParameterSource("ticketId", id).addValue("reservationId", reservationId).addValue("eventId", event.getId()).addValue("newUuid", UUID.randomUUID().toString())).toArray(MapSqlParameterSource[]::new);
    jdbc.batchUpdate(ticketRepository.batchReleaseTickets(), args);
    if (!removeReservation) {
        // #407 update invoice/receipt model only if the reservation is still "PENDING", otherwise we could lead to accountancy problems
        if (UPDATE_INVOICE_STATUSES.contains(reservation.getStatus())) {
            updateInvoiceReceiptModel(event, reservation.getUserLanguage(), reservationId);
        }
        extensionManager.handleTicketCancelledForEvent(event, ticketRepository.findUUIDs(ticketIds));
    } else {
        extensionManager.handleReservationsCancelledForEvent(event, ticketRepository.findReservationIds(ticketIds));
    }
}
Also used : alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) ZonedDateTime(java.time.ZonedDateTime) BiFunction(java.util.function.BiFunction) RequiredArgsConstructor(lombok.RequiredArgsConstructor) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) ResultStatus(alfio.model.result.Result.ResultStatus) BigDecimal(java.math.BigDecimal) Json(alfio.util.Json) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) TemplateResource(alfio.util.TemplateResource) TICKET(alfio.model.Audit.EntityType.TICKET) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Organization(alfio.model.user.Organization) TemplateManager(alfio.util.TemplateManager) Collectors(java.util.stream.Collectors) CANCEL_TICKET(alfio.model.Audit.EventType.CANCEL_TICKET) Stream(java.util.stream.Stream) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) java.util(java.util) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Function(java.util.function.Function) Attendee(alfio.model.modification.AdminReservationModification.Attendee) DateTimeModification(alfio.model.modification.DateTimeModification) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) MessageSource(org.springframework.context.MessageSource) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) MonetaryUtil(alfio.util.MonetaryUtil) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) Category(alfio.model.modification.AdminReservationModification.Category) EventUtil.generateEmptyTickets(alfio.util.EventUtil.generateEmptyTickets) AdminReservationModification(alfio.model.modification.AdminReservationModification) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Organization(alfio.model.user.Organization) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Aggregations

DuplicateReferenceException (alfio.manager.support.DuplicateReferenceException)1 alfio.model (alfio.model)1 TICKET (alfio.model.Audit.EntityType.TICKET)1 CANCEL_TICKET (alfio.model.Audit.EventType.CANCEL_TICKET)1 TicketReservationStatus (alfio.model.TicketReservation.TicketReservationStatus)1 TicketPriceContainer (alfio.model.decorator.TicketPriceContainer)1 AdminReservationModification (alfio.model.modification.AdminReservationModification)1 Attendee (alfio.model.modification.AdminReservationModification.Attendee)1 Category (alfio.model.modification.AdminReservationModification.Category)1 TicketsInfo (alfio.model.modification.AdminReservationModification.TicketsInfo)1 DateTimeModification (alfio.model.modification.DateTimeModification)1 DateTimeModification.fromZonedDateTime (alfio.model.modification.DateTimeModification.fromZonedDateTime)1 TicketCategoryModification (alfio.model.modification.TicketCategoryModification)1 ErrorCode (alfio.model.result.ErrorCode)1 Result (alfio.model.result.Result)1 ResultStatus (alfio.model.result.Result.ResultStatus)1 PaymentProxy (alfio.model.transaction.PaymentProxy)1 Organization (alfio.model.user.Organization)1 alfio.repository (alfio.repository)1 UserRepository (alfio.repository.user.UserRepository)1