Search in sources :

Example 1 with Notification

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

the class AdminReservationManager method confirmReservation.

// the following methods have an explicit transaction handling, therefore the @Transactional annotation is not helpful here
Result<Triple<TicketReservation, List<Ticket>, PurchaseContext>> confirmReservation(PurchaseContextType purchaseContextType, String eventName, String reservationId, String username, Notification notification, UUID subscriptionId) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
    return template.execute(status -> {
        try {
            Result<Triple<TicketReservation, List<Ticket>, PurchaseContext>> result = purchaseContextManager.findBy(purchaseContextType, eventName).map(purchaseContext -> ticketReservationRepository.findOptionalReservationById(reservationId).filter(r -> r.getStatus() == TicketReservationStatus.PENDING || r.getStatus() == TicketReservationStatus.STUCK).map(r -> performConfirmation(reservationId, purchaseContext, r, notification, username, subscriptionId)).orElseGet(() -> Result.error(ErrorCode.ReservationError.UPDATE_FAILED))).orElseGet(() -> Result.error(ErrorCode.ReservationError.NOT_FOUND));
            if (!result.isSuccess()) {
                log.debug("Reservation confirmation failed for eventName: {} reservationId: {}, username: {}", eventName, reservationId, username);
                status.setRollbackOnly();
            }
            return result;
        } catch (Exception e) {
            log.error("Error during confirmation of reservation eventName: {} reservationId: {}, username: {}", eventName, reservationId, username);
            status.setRollbackOnly();
            return Result.error(singletonList(ErrorCode.custom("", e.getMessage())));
        }
    });
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) TemplateProcessor(alfio.controller.support.TemplateProcessor) StringUtils.firstNonBlank(org.apache.commons.lang3.StringUtils.firstNonBlank) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AlfioMetadata(alfio.model.metadata.AlfioMetadata) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) UPDATE_TICKET(alfio.model.Audit.EventType.UPDATE_TICKET) ResultStatus(alfio.model.result.Result.ResultStatus) BigDecimal(java.math.BigDecimal) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) DefaultMessageSourceResolvable(org.springframework.context.support.DefaultMessageSourceResolvable) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) 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) MapBindingResult(org.springframework.validation.MapBindingResult) java.util(java.util) MonetaryUtil.unitToCents(alfio.util.MonetaryUtil.unitToCents) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) TransactionDefinition(org.springframework.transaction.TransactionDefinition) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Function(java.util.function.Function) alfio.util(alfio.util) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) Attendee(alfio.model.modification.AdminReservationModification.Attendee) DateTimeModification(alfio.model.modification.DateTimeModification) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Collections.singletonMap(java.util.Collections.singletonMap) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) DateTimeModification.fromZonedDateTime(alfio.model.modification.DateTimeModification.fromZonedDateTime) TicketCategoryModification(alfio.model.modification.TicketCategoryModification) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) Notification(alfio.model.modification.AdminReservationModification.Notification) TicketsInfo(alfio.model.modification.AdminReservationModification.TicketsInfo) User(alfio.model.user.User) Result(alfio.model.result.Result) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) Category(alfio.model.modification.AdminReservationModification.Category) Wrappers.optionally(alfio.util.Wrappers.optionally) EventUtil.generateEmptyTickets(alfio.util.EventUtil.generateEmptyTickets) AdminReservationModification(alfio.model.modification.AdminReservationModification) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException)

Aggregations

TemplateProcessor (alfio.controller.support.TemplateProcessor)1 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)1 PaymentSpecification (alfio.manager.payment.PaymentSpecification)1 DuplicateReferenceException (alfio.manager.support.DuplicateReferenceException)1 ReservationPriceCalculator (alfio.manager.system.ReservationPriceCalculator)1 alfio.model (alfio.model)1 RESERVATION (alfio.model.Audit.EntityType.RESERVATION)1 TICKET (alfio.model.Audit.EntityType.TICKET)1 CANCEL_TICKET (alfio.model.Audit.EventType.CANCEL_TICKET)1 UPDATE_TICKET (alfio.model.Audit.EventType.UPDATE_TICKET)1 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)1 TicketReservationStatus (alfio.model.TicketReservation.TicketReservationStatus)1 TicketPriceContainer (alfio.model.decorator.TicketPriceContainer)1 AlfioMetadata (alfio.model.metadata.AlfioMetadata)1 AdminReservationModification (alfio.model.modification.AdminReservationModification)1 Attendee (alfio.model.modification.AdminReservationModification.Attendee)1 Category (alfio.model.modification.AdminReservationModification.Category)1 Notification (alfio.model.modification.AdminReservationModification.Notification)1 TicketsInfo (alfio.model.modification.AdminReservationModification.TicketsInfo)1 DateTimeModification (alfio.model.modification.DateTimeModification)1