Search in sources :

Example 1 with DuplicateReferenceException

use of alfio.manager.support.DuplicateReferenceException in project alf.io by alfio-event.

the class AdminReservationManager method createReservation.

public Result<Pair<TicketReservation, List<Ticket>>> createReservation(AdminReservationModification input, String eventName, String username) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_NESTED);
    TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
    return template.execute(status -> {
        var savepoint = status.createSavepoint();
        try {
            Result<Pair<TicketReservation, List<Ticket>>> result = eventRepository.findOptionalByShortNameForUpdate(eventName).map(e -> validateTickets(input, e)).map(r -> r.flatMap(p -> transactionalCreateReservation(p.getRight(), p.getLeft(), username))).orElse(Result.error(ErrorCode.EventError.NOT_FOUND));
            if (!result.isSuccess()) {
                log.debug("Error during update of reservation eventName: {}, username: {}, reservation: {}", eventName, username, AdminReservationModification.summary(input));
                status.rollbackToSavepoint(savepoint);
            }
            return result;
        } catch (Exception e) {
            log.error("Error during update of reservation eventName: {}, username: {}, reservation: {}", eventName, username, AdminReservationModification.summary(input));
            status.rollbackToSavepoint(savepoint);
            return Result.error(singletonList(ErrorCode.custom(e instanceof DuplicateReferenceException ? "duplicate-reference" : "", e.getMessage())));
        }
    });
}
Also used : 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) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException) Pair(org.apache.commons.lang3.tuple.Pair)

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