1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.comparator.spring.boot;
18
19 import java.util.Optional;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.bremersee.comparator.model.SortOrderTextSeparators;
23 import org.bremersee.comparator.spring.web.ReactiveSortOrderHandlerMethodArgumentResolver;
24 import org.springframework.boot.autoconfigure.AutoConfiguration;
25 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
26 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
27 import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type;
28 import org.springframework.boot.context.event.ApplicationReadyEvent;
29 import org.springframework.boot.context.properties.EnableConfigurationProperties;
30 import org.springframework.context.event.EventListener;
31 import org.springframework.util.ClassUtils;
32 import org.springframework.util.StringUtils;
33 import org.springframework.web.reactive.config.WebFluxConfigurer;
34 import org.springframework.web.reactive.result.method.annotation.ArgumentResolverConfigurer;
35
36
37
38
39
40
41 @ConditionalOnWebApplication(type = Type.REACTIVE)
42 @ConditionalOnClass(name = {
43 "org.bremersee.comparator.model.SortOrderTextSeparators",
44 "org.bremersee.comparator.spring.web.ReactiveSortOrderHandlerMethodArgumentResolver"
45 })
46 @AutoConfiguration
47 @EnableConfigurationProperties(SortOrderConverterProperties.class)
48 public class SortOrderWebFluxAutoConfiguration implements WebFluxConfigurer {
49
50 private static final Log log = LogFactory.getLog(SortOrderWebFluxAutoConfiguration.class);
51
52 private final SortOrderTextSeparators separators;
53
54
55
56
57
58
59 public SortOrderWebFluxAutoConfiguration(SortOrderConverterProperties properties) {
60 SortOrderTextSeparators defaults = SortOrderTextSeparators.defaults();
61 this.separators = SortOrderTextSeparators.builder()
62 .argumentSeparator(Optional.ofNullable(properties.getArgumentSeparator())
63 .filter(StringUtils::hasText)
64 .orElse(defaults.getArgumentSeparator()))
65 .chainSeparator(Optional.ofNullable(properties.getChainSeparator())
66 .filter(StringUtils::hasText)
67 .orElse(defaults.getChainSeparator()))
68 .build();
69 }
70
71
72
73
74 @EventListener(ApplicationReadyEvent.class)
75 public void init() {
76 log.info(String.format("""
77
78 *********************************************************************************
79 * %s
80 *********************************************************************************""",
81 ClassUtils.getUserClass(getClass()).getSimpleName()));
82 }
83
84 @Override
85 public void configureArgumentResolvers(ArgumentResolverConfigurer configurer) {
86 var resolver = new ReactiveSortOrderHandlerMethodArgumentResolver();
87 resolver.setTextSeparators(separators);
88 configurer.addCustomResolver(resolver);
89 }
90
91 }