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 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
37
38
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
54
55
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
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 }