Search in sources :

Example 1 with CheckInOutputColorConfiguration

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

the class EventManager method saveBadgeColorConfiguration.

void saveBadgeColorConfiguration(String badgeColor, Event event, Integer categoryId) {
    if (StringUtils.isNotBlank(badgeColor)) {
        var chosenColor = badgeColor.toLowerCase();
        var colorConfiguration = CheckInManager.getOutputColorConfiguration(event, configurationManager);
        boolean existingConfiguration = colorConfiguration != null;
        if (!existingConfiguration) {
            colorConfiguration = new CheckInOutputColorConfiguration("success", List.of(new ColorConfiguration(chosenColor, List.of(categoryId))));
        } else {
            var configurationWithoutCategory = colorConfiguration.getConfigurations().stream().map(cc -> new ColorConfiguration(cc.getColorName(), cc.getCategories().stream().filter(c -> !c.equals(categoryId)).collect(toUnmodifiableList()))).filter(cc -> !cc.getCategories().isEmpty()).collect(toList());
            boolean colorExists = configurationWithoutCategory.stream().anyMatch(cc -> cc.getColorName().equals(chosenColor));
            if (colorExists) {
                colorConfiguration = new CheckInOutputColorConfiguration(colorConfiguration.getDefaultColorName(), configurationWithoutCategory.stream().map(cc -> {
                    if (cc.getColorName().equals(chosenColor)) {
                        var newList = new ArrayList<>(cc.getCategories());
                        newList.add(categoryId);
                        return new ColorConfiguration(chosenColor, newList);
                    }
                    return cc;
                }).collect(toUnmodifiableList()));
            } else {
                var newList = new ArrayList<>(configurationWithoutCategory);
                newList.add(new ColorConfiguration(chosenColor, List.of(categoryId)));
                colorConfiguration = new CheckInOutputColorConfiguration(colorConfiguration.getDefaultColorName(), newList);
            }
        }
        if (existingConfiguration) {
            configurationRepository.updateEventLevel(event.getId(), event.getOrganizationId(), CHECK_IN_COLOR_CONFIGURATION.name(), Json.toJson(colorConfiguration));
        } else {
            configurationRepository.insertEventLevel(event.getOrganizationId(), event.getId(), CHECK_IN_COLOR_CONFIGURATION.name(), Json.toJson(colorConfiguration), null);
        }
    }
}
Also used : AdditionalField(alfio.model.modification.EventModification.AdditionalField) alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) AffectedRowCountAndKey(ch.digitalfondue.npjt.AffectedRowCountAndKey) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) ZonedDateTime(java.time.ZonedDateTime) NamedParameterJdbcTemplate(org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate) AlfioMetadata(alfio.model.metadata.AlfioMetadata) TicketStatus(alfio.model.Ticket.TicketStatus) StringUtils(org.apache.commons.lang3.StringUtils) IntPredicate(java.util.function.IntPredicate) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) Json(alfio.util.Json) ErrorCode(alfio.model.result.ErrorCode) Arrays.asList(java.util.Arrays.asList) Profiles(org.springframework.core.env.Profiles) Triple(org.apache.commons.lang3.tuple.Triple) OrganizationRepository(alfio.repository.user.OrganizationRepository) RequestUtils(alfio.util.RequestUtils) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) CheckInOutputColorConfiguration(alfio.model.support.CheckInOutputColorConfiguration) EventCreationRequest(alfio.model.api.v1.admin.EventCreationRequest) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) String.format(java.lang.String.format) ConfigurationRepository(alfio.repository.system.ConfigurationRepository) SearchOptions(alfio.controller.form.SearchOptions) ColorConfiguration(alfio.model.support.CheckInOutputColorConfiguration.ColorConfiguration) Initializer(alfio.config.Initializer) Principal(java.security.Principal) Stream(java.util.stream.Stream) alfio.model(alfio.model) Environment(org.springframework.core.env.Environment) DateTimeModification.atZone(alfio.model.modification.DateTimeModification.atZone) ClockProvider(alfio.util.ClockProvider) alfio.model.modification(alfio.model.modification) IntStream(java.util.stream.IntStream) java.util(java.util) EventFormat(alfio.model.Event.EventFormat) ONCE_PER_EVENT(alfio.model.TicketCategory.TicketCheckInStrategy.ONCE_PER_EVENT) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConfigurationManager(alfio.manager.system.ConfigurationManager) Function(java.util.function.Function) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Objects.requireNonNullElse(java.util.Objects.requireNonNullElse) IterableUtils(org.apache.commons.collections4.IterableUtils) TicketAccessType(alfio.model.TicketCategory.TicketAccessType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Context(alfio.model.TicketFieldConfiguration.Context) Objects.requireNonNullElseGet(java.util.Objects.requireNonNullElseGet) Result(alfio.model.result.Result) Consumer(java.util.function.Consumer) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) CategoryEvaluator(alfio.manager.support.CategoryEvaluator) MonetaryUtil(alfio.util.MonetaryUtil) ExtensionCapability(alfio.manager.support.extension.ExtensionCapability) UserManager(alfio.manager.user.UserManager) Log4j2(lombok.extern.log4j.Log4j2) EventUtil(alfio.util.EventUtil) Flyway(org.flywaydb.core.Flyway) Wrappers.optionally(alfio.util.Wrappers.optionally) AllArgsConstructor(lombok.AllArgsConstructor) ConfigurationKeys(alfio.model.system.ConfigurationKeys) CHECK_IN_COLOR_CONFIGURATION(alfio.model.system.ConfigurationKeys.CHECK_IN_COLOR_CONFIGURATION) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) CheckInOutputColorConfiguration(alfio.model.support.CheckInOutputColorConfiguration) CheckInOutputColorConfiguration(alfio.model.support.CheckInOutputColorConfiguration) ColorConfiguration(alfio.model.support.CheckInOutputColorConfiguration.ColorConfiguration)

Aggregations

Initializer (alfio.config.Initializer)1 SearchOptions (alfio.controller.form.SearchOptions)1 CategoryEvaluator (alfio.manager.support.CategoryEvaluator)1 ExtensionCapability (alfio.manager.support.extension.ExtensionCapability)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1 UserManager (alfio.manager.user.UserManager)1 alfio.model (alfio.model)1 EventFormat (alfio.model.Event.EventFormat)1 DiscountType (alfio.model.PromoCodeDiscount.DiscountType)1 TicketStatus (alfio.model.Ticket.TicketStatus)1 TicketAccessType (alfio.model.TicketCategory.TicketAccessType)1 ONCE_PER_EVENT (alfio.model.TicketCategory.TicketCheckInStrategy.ONCE_PER_EVENT)1 Context (alfio.model.TicketFieldConfiguration.Context)1 EventCreationRequest (alfio.model.api.v1.admin.EventCreationRequest)1 AlfioMetadata (alfio.model.metadata.AlfioMetadata)1 alfio.model.modification (alfio.model.modification)1 DateTimeModification.atZone (alfio.model.modification.DateTimeModification.atZone)1 AdditionalField (alfio.model.modification.EventModification.AdditionalField)1 ErrorCode (alfio.model.result.ErrorCode)1 Result (alfio.model.result.Result)1