View Javadoc
1   /*
2    * Copyright 2019-2026 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.bremersee.comparator.spring.boot;
18  
19  import java.util.Optional;
20  import lombok.extern.slf4j.Slf4j;
21  import org.bremersee.comparator.model.SortOrderTextSeparators;
22  import org.bremersee.comparator.spring.web.ReactiveSortOrderHandlerMethodArgumentResolver;
23  import org.springframework.boot.autoconfigure.AutoConfiguration;
24  import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
25  import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
26  import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
27  import org.springframework.boot.context.event.ApplicationReadyEvent;
28  import org.springframework.boot.context.properties.EnableConfigurationProperties;
29  import org.springframework.context.event.EventListener;
30  import org.springframework.util.ClassUtils;
31  import org.springframework.util.StringUtils;
32  import org.springframework.web.reactive.config.WebFluxConfigurer;
33  import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
34  
35  /**
36   * The sort order autoconfiguration for webflux.
37   *
38   * @author Christian Bremer
39   */
40  @ConditionalOnWebApplication(type = Type.REACTIVE)
41  @ConditionalOnClass(name = {
42      "org.bremersee.comparator.model.SortOrderTextSeparators",
43      "org.bremersee.comparator.spring.web.ReactiveSortOrderHandlerMethodArgumentResolver"
44  })
45  @AutoConfiguration
46  @EnableConfigurationProperties(SortOrderConverterProperties.class)
47  @Slf4j
48  public class SortOrderWebFluxAutoConfiguration implements WebFluxConfigurer {
49  
50    private final SortOrderTextSeparators separators;
51  
52    /**
53     * Instantiates a new sort order autoconfiguration for webflux.
54     *
55     * @param properties the properties
56     */
57    public SortOrderWebFluxAutoConfiguration(SortOrderConverterProperties properties) {
58      SortOrderTextSeparators defaults = SortOrderTextSeparators.defaults();
59      this.separators = SortOrderTextSeparators.builder()
60          .argumentSeparator(Optional.ofNullable(properties.getArgumentSeparator())
61              .filter(StringUtils::hasText)
62              .orElse(defaults.getArgumentSeparator()))
63          .chainSeparator(Optional.ofNullable(properties.getChainSeparator())
64              .filter(StringUtils::hasText)
65              .orElse(defaults.getChainSeparator()))
66          .build();
67    }
68  
69    /**
70     * Init.
71     */
72    @EventListener(ApplicationReadyEvent.class)
73    public void init() {
74      log.info("""
75              
76              *********************************************************************************
77              * {}
78              *********************************************************************************""",
79          ClassUtils.getUserClass(getClass()).getSimpleName());
80    }
81  
82    @Override
83    public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
84      var resolver = new ReactiveSortOrderHandlerMethodArgumentResolver();
85      resolver.setTextSeparators(separators);
86      configurer.addCustomResolver(resolver);
87    }
88  
89  }