Search in sources :

Example 1 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION 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)

Example 2 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class AdminReservationManager method updateReservation.

public Result<Boolean> updateReservation(PurchaseContextType purchaseContextType, String publicIdentifier, String reservationId, AdminReservationModification adminReservationModification, String username) {
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    TransactionTemplate template = new TransactionTemplate(transactionManager, definition);
    return template.execute(status -> {
        try {
            Result<Boolean> result = purchaseContextManager.findBy(purchaseContextType, publicIdentifier).map(event -> ticketReservationRepository.findOptionalReservationById(reservationId).map(r -> performUpdate(reservationId, event, r, adminReservationModification, username)).orElseGet(() -> Result.error(ErrorCode.ReservationError.UPDATE_FAILED))).orElseGet(() -> Result.error(ErrorCode.ReservationError.NOT_FOUND));
            if (!result.isSuccess()) {
                log.debug("Application error detected eventName: {} reservationId: {}, username: {}, reservation: {}", publicIdentifier, reservationId, username, AdminReservationModification.summary(adminReservationModification));
                status.setRollbackOnly();
            }
            return result;
        } catch (Exception e) {
            log.error("Error during update of reservation eventName: {} reservationId: {}, username: {}, reservation: {}", publicIdentifier, reservationId, username, AdminReservationModification.summary(adminReservationModification));
            status.setRollbackOnly();
            return Result.error(singletonList(ErrorCode.custom("", 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) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DuplicateReferenceException(alfio.manager.support.DuplicateReferenceException)

Example 3 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION 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)

Example 4 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class TicketReservationManager method createTicketReservation.

/**
 * Create a ticket reservation. It will create a reservation _only_ if it can find enough tickets. Note that it will not do date/validity validation. This must be ensured by the
 * caller.
 *
 * @param event
 * @param list
 * @param reservationExpiration
 * @param forWaitingQueue
 * @return
 */
public String createTicketReservation(Event event, List<TicketReservationWithOptionalCodeModification> list, List<ASReservationWithOptionalCodeModification> additionalServices, Date reservationExpiration, Optional<String> promotionCodeDiscount, Locale locale, boolean forWaitingQueue, Principal principal) throws NotEnoughTicketsException, MissingSpecialPriceTokenException, InvalidSpecialPriceTokenException {
    String reservationId = UUID.randomUUID().toString();
    Optional<PromoCodeDiscount> discount = promotionCodeDiscount.flatMap(promoCodeDiscount -> promoCodeDiscountRepository.findPromoCodeInEventOrOrganization(event.getId(), promoCodeDiscount));
    Optional<PromoCodeDiscount> dynamicDiscount = createDynamicPromoCode(discount, event, list, reservationId);
    ticketReservationRepository.createNewReservation(reservationId, event.now(clockProvider), reservationExpiration, dynamicDiscount.or(() -> discount).map(PromoCodeDiscount::getId).orElse(null), locale.getLanguage(), event.getId(), event.getVat(), event.isVatIncluded(), event.getCurrency(), event.getOrganizationId(), retrievePublicUserId(principal));
    list.forEach(t -> reserveTicketsForCategory(event, reservationId, t, locale, forWaitingQueue, discount.orElse(null), dynamicDiscount.orElse(null)));
    int ticketCount = list.stream().map(TicketReservationWithOptionalCodeModification::getQuantity).mapToInt(Integer::intValue).sum();
    // apply valid additional service with supplement policy mandatory one for ticket
    additionalServiceRepository.findAllInEventWithPolicy(event.getId(), AdditionalService.SupplementPolicy.MANDATORY_ONE_FOR_TICKET).stream().filter(AdditionalService::getSaleable).forEach(as -> {
        AdditionalServiceReservationModification asrm = new AdditionalServiceReservationModification();
        asrm.setAdditionalServiceId(as.getId());
        asrm.setQuantity(ticketCount);
        reserveAdditionalServicesForReservation(event.getId(), reservationId, new ASReservationWithOptionalCodeModification(asrm, Optional.empty()), discount.orElse(null));
    });
    additionalServices.forEach(as -> reserveAdditionalServicesForReservation(event.getId(), reservationId, as, discount.orElse(null)));
    var totalPrice = totalReservationCostWithVAT(reservationId).getLeft();
    var vatStatus = event.getVatStatus();
    ticketReservationRepository.updateBillingData(event.getVatStatus(), calculateSrcPrice(vatStatus, totalPrice), totalPrice.getPriceWithVAT(), totalPrice.getVAT(), Math.abs(totalPrice.getDiscount()), event.getCurrency(), null, null, false, reservationId);
    auditingRepository.insert(reservationId, null, event.getId(), Audit.EventType.RESERVATION_CREATE, new Date(), Audit.EntityType.RESERVATION, reservationId);
    if (isDiscountCodeUsageExceeded(reservationId)) {
        throw new TooManyTicketsForDiscountCodeException();
    }
    if (!canProceedWithPayment(event, totalPrice, reservationId)) {
        throw new CannotProceedWithPayment("No payment method applicable for categories " + list.stream().map(t -> String.valueOf(t.getTicketCategoryId())).collect(Collectors.joining(", ")));
    }
    return reservationId;
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification)

Example 5 with RESERVATION

use of alfio.model.Audit.EntityType.RESERVATION in project alf.io by alfio-event.

the class TicketReservationManager method sendAssignmentReminder.

private void sendAssignmentReminder(Pair<Event, Set<String>> p) {
    try {
        nestedTransactionTemplate.execute(ts -> {
            Event event = p.getLeft();
            var messageSource = messageSourceManager.getMessageSourceFor(event);
            ZoneId eventZoneId = event.getZoneId();
            int quietPeriod = configurationManager.getFor(ASSIGNMENT_REMINDER_INTERVAL, ConfigurationLevel.event(event)).getValueAsIntOrDefault(3);
            p.getRight().stream().map(id -> findByIdForNotification(id, clockProvider.withZone(eventZoneId), quietPeriod)).filter(Optional::isPresent).map(Optional::get).forEach(reservation -> {
                Map<String, Object> model = prepareModelForReservationEmail(event, reservation);
                ticketReservationRepository.updateLatestReminderTimestamp(reservation.getId(), ZonedDateTime.now(clockProvider.withZone(eventZoneId)));
                Locale locale = findReservationLanguage(reservation.getId());
                notificationManager.sendSimpleEmail(event, reservation.getId(), reservation.getEmail(), messageSource.getMessage("reminder.ticket-not-assigned.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.REMINDER_TICKETS_ASSIGNMENT_EMAIL, model, locale));
            });
            return null;
        });
    } catch (Exception ex) {
        log.warn("cannot send reminder message", ex);
    }
}
Also used : alfio.repository(alfio.repository) TicketMetadataContainer(alfio.model.metadata.TicketMetadataContainer) ZonedDateTime(java.time.ZonedDateTime) TicketCheckInUtil.ticketOnlineCheckInUrl(alfio.util.checkin.TicketCheckInUtil.ticketOnlineCheckInUrl) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException) StringUtils(org.apache.commons.lang3.StringUtils) TransactionSynchronizationManager(org.springframework.transaction.support.TransactionSynchronizationManager) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) ErrorCode(alfio.model.result.ErrorCode) Pair(org.apache.commons.lang3.tuple.Pair) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) Triple(org.apache.commons.lang3.tuple.Triple) TICKET(alfio.model.Audit.EntityType.TICKET) Organization(alfio.model.user.Organization) UserIdAndOrganizationId(alfio.model.support.UserIdAndOrganizationId) ZoneId(java.time.ZoneId) SubscriptionTimeUnit(alfio.model.subscription.SubscriptionDescriptor.SubscriptionTimeUnit) EventType(alfio.model.Audit.EventType) Stream(java.util.stream.Stream) Type(alfio.model.BillingDocument.Type) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) PromoCodeDiscount.categoriesOrNull(alfio.model.PromoCodeDiscount.categoriesOrNull) java.util(java.util) TicketHelper(alfio.controller.api.support.TicketHelper) ConfigurationLevel(alfio.manager.system.ConfigurationLevel) MessageSourceManager(alfio.manager.i18n.MessageSourceManager) SummaryType(alfio.model.SummaryRow.SummaryType) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) BindingResult(org.springframework.validation.BindingResult) ConfigurationManager(alfio.manager.system.ConfigurationManager) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) RESERVATION(alfio.model.Audit.EntityType.RESERVATION) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) WebhookHandler(alfio.model.transaction.capabilities.WebhookHandler) Status(alfio.model.SpecialPrice.Status) DateUtils(org.apache.commons.lang3.time.DateUtils) Result(alfio.model.result.Result) LinkedGroup(alfio.model.group.LinkedGroup) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) MonetaryUtil(alfio.util.MonetaryUtil) UserManager(alfio.manager.user.UserManager) WarningMessage(alfio.model.result.WarningMessage) Wrappers.optionally(alfio.util.Wrappers.optionally) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) ServerInitiatedTransaction(alfio.model.transaction.capabilities.ServerInitiatedTransaction) TemplateProcessor(alfio.controller.support.TemplateProcessor) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) TicketCheckInUtil(alfio.util.checkin.TicketCheckInUtil) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) OfflineProcessor(alfio.model.transaction.capabilities.OfflineProcessor) OrganizationRepository(alfio.repository.user.OrganizationRepository) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) Role(alfio.model.user.Role) Principal(java.security.Principal) Entry(java.util.Map.Entry) CodeType(alfio.model.PromoCodeDiscount.CodeType) OnlineCheckInFullInfo(alfio.model.checkin.OnlineCheckInFullInfo) IntStream(java.util.stream.IntStream) CustomEmailText(alfio.model.extension.CustomEmailText) ChronoField(java.time.temporal.ChronoField) TransactionDefinition(org.springframework.transaction.TransactionDefinition) PurchaseContextType(alfio.model.PurchaseContext.PurchaseContextType) Function(java.util.function.Function) alfio.util(alfio.util) ReservationPriceCalculator(alfio.manager.system.ReservationPriceCalculator) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) ObjectUtils(org.apache.commons.lang3.ObjectUtils) alfio.model.transaction(alfio.model.transaction) UserDetails(org.springframework.security.core.userdetails.UserDetails) alfio.model.subscription(alfio.model.subscription) Collections.singletonMap(java.util.Collections.singletonMap) VatStatus(alfio.model.PriceContainer.VatStatus) ONCE_PER_EVENT(alfio.model.subscription.SubscriptionDescriptor.SubscriptionUsageType.ONCE_PER_EVENT) alfio.manager.support(alfio.manager.support) BankTransferManager(alfio.manager.payment.BankTransferManager) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) TicketMetadata(alfio.model.metadata.TicketMetadata) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) PaymentSpecification(alfio.manager.payment.PaymentSpecification) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) PaymentMethodStatus(alfio.manager.PaymentManager.PaymentMethodDTO.PaymentMethodStatus) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) ZoneId(java.time.ZoneId) UncategorizedSQLException(org.springframework.jdbc.UncategorizedSQLException)

Aggregations

PaymentSpecification (alfio.manager.payment.PaymentSpecification)9 alfio.model (alfio.model)9 RESERVATION (alfio.model.Audit.EntityType.RESERVATION)9 PurchaseContextType (alfio.model.PurchaseContext.PurchaseContextType)9 Organization (alfio.model.user.Organization)9 alfio.repository (alfio.repository)9 UserRepository (alfio.repository.user.UserRepository)9 java.util (java.util)9 Collections.singletonList (java.util.Collections.singletonList)9 Collections.singletonMap (java.util.Collections.singletonMap)9 Log4j2 (lombok.extern.log4j.Log4j2)9 ObjectUtils (org.apache.commons.lang3.ObjectUtils)9 StringUtils (org.apache.commons.lang3.StringUtils)9 Component (org.springframework.stereotype.Component)9 Transactional (org.springframework.transaction.annotation.Transactional)9 TemplateProcessor (alfio.controller.support.TemplateProcessor)8 MessageSourceManager (alfio.manager.i18n.MessageSourceManager)8 ReservationPriceCalculator (alfio.manager.system.ReservationPriceCalculator)8 TICKET (alfio.model.Audit.EntityType.TICKET)8 TicketReservationStatus (alfio.model.TicketReservation.TicketReservationStatus)5