Search in sources :

Example 6 with PurchaseContext

use of alfio.model.PurchaseContext in project alf.io by alfio-event.

the class PublicUserManager method buildAdditionalInfoWithLabels.

private Map<String, AdditionalInfoWithLabel> buildAdditionalInfoWithLabels(PublicUserProfile existingProfile, PurchaseContext purchaseContext, UpdateTicketOwnerForm form) {
    var event = purchaseContext.event().orElseThrow();
    var fields = ticketFieldRepository.findAdditionalFieldsOfTypeForEvent(event.getId(), "input:text");
    var fieldsById = fields.stream().collect(toMap(TicketFieldConfiguration::getId, Function.identity()));
    var userLanguage = form.getUserLanguage();
    var filteredItems = extensionManager.filterAdditionalInfoToSave(purchaseContext, form.getAdditional(), existingProfile);
    final Map<String, AdditionalInfoItem> filteredItemsByKey;
    filteredItemsByKey = filteredItems.map(additionalInfoItems -> additionalInfoItems.stream().collect(toMap(AdditionalInfoItem::getKey, Function.identity()))).orElse(null);
    var labels = ticketFieldRepository.findDescriptions(event.getId(), userLanguage).stream().filter(f -> fieldsById.containsKey(f.getTicketFieldConfigurationId())).map(f -> Map.entry(fieldsById.get(f.getTicketFieldConfigurationId()).getName(), f)).filter(f -> filteredItemsByKey == null || filteredItemsByKey.containsKey(f.getKey())).map(e -> {
        if (filteredItemsByKey != null) {
            return Map.entry(e.getKey(), filteredItemsByKey.get(e.getKey()).getLabel());
        }
        return Map.entry(e.getKey(), e.getValue().getLabelDescription());
    }).collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
    Map<String, AdditionalInfoWithLabel> result = new HashMap<>(Optional.ofNullable(existingProfile).map(PublicUserProfile::getAdditionalData).orElse(Map.of()));
    // override existing values (if any) with new values.
    result.putAll(form.getAdditional().entrySet().stream().filter(e -> labels.containsKey(e.getKey())).map(e -> {
        var label = labels.get(e.getKey());
        return Map.entry(e.getKey(), new AdditionalInfoWithLabel(Map.of(userLanguage, label), e.getValue()));
    }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
    return result;
}
Also used : java.util(java.util) PublicUserProfile(alfio.model.user.PublicUserProfile) PurchaseContext(alfio.model.PurchaseContext) AdditionalInfoWithLabel(alfio.model.user.AdditionalInfoWithLabel) BindingResult(org.springframework.validation.BindingResult) OpenIdAlfioAuthentication(alfio.config.authentication.support.OpenIdAlfioAuthentication) TicketReservationAdditionalInfo(alfio.model.TicketReservationAdditionalInfo) Function(java.util.function.Function) TicketFieldRepository(alfio.repository.TicketFieldRepository) Pair(org.apache.commons.lang3.tuple.Pair) Collectors.toMap(java.util.stream.Collectors.toMap) TicketReservationInvoicingAdditionalInfo(alfio.model.TicketReservationInvoicingAdditionalInfo) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) User(alfio.model.user.User) AdditionalInfoItem(alfio.model.extension.AdditionalInfoItem) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) Principal(java.security.Principal) ContactAndTicketsForm(alfio.controller.form.ContactAndTicketsForm) UserRepository(alfio.repository.user.UserRepository) UpdateProfileForm(alfio.controller.form.UpdateProfileForm) TicketFieldConfiguration(alfio.model.TicketFieldConfiguration) ExtensionManager(alfio.manager.ExtensionManager) AllArgsConstructor(lombok.AllArgsConstructor) Authentication(org.springframework.security.core.Authentication) Transactional(org.springframework.transaction.annotation.Transactional) AdditionalInfoItem(alfio.model.extension.AdditionalInfoItem) Collectors.toMap(java.util.stream.Collectors.toMap) AdditionalInfoWithLabel(alfio.model.user.AdditionalInfoWithLabel) PublicUserProfile(alfio.model.user.PublicUserProfile)

Aggregations

PurchaseContext (alfio.model.PurchaseContext)6 java.util (java.util)4 PaymentResult (alfio.manager.support.PaymentResult)3 ConfigurationManager (alfio.manager.system.ConfigurationManager)3 PaymentInformation (alfio.model.PaymentInformation)3 ConfigurationKeys (alfio.model.system.ConfigurationKeys)3 ZonedDateTime (java.time.ZonedDateTime)3 AllArgsConstructor (lombok.AllArgsConstructor)3 Log4j2 (lombok.extern.log4j.Log4j2)3 Validate (org.apache.commons.lang3.Validate)3 Component (org.springframework.stereotype.Component)3 FeeCalculator (alfio.manager.support.FeeCalculator)2 PaymentWebhookResult (alfio.manager.support.PaymentWebhookResult)2 ConfigurationLevel (alfio.manager.system.ConfigurationLevel)2 TicketReservation (alfio.model.TicketReservation)2 EXTERNAL_PROCESSING_PAYMENT (alfio.model.TicketReservation.TicketReservationStatus.EXTERNAL_PROCESSING_PAYMENT)2 WAITING_EXTERNAL_CONFIRMATION (alfio.model.TicketReservation.TicketReservationStatus.WAITING_EXTERNAL_CONFIRMATION)2 alfio.model.transaction (alfio.model.transaction)2 TicketRepository (alfio.repository.TicketRepository)2 OpenIdAlfioAuthentication (alfio.config.authentication.support.OpenIdAlfioAuthentication)1