1
- package org .springdoc .data . rest . customisers ;
1
+ package org .springdoc .core . customizers ;
2
2
3
3
import java .lang .annotation .Annotation ;
4
4
import java .lang .reflect .Field ;
24
24
import org .slf4j .Logger ;
25
25
import org .slf4j .LoggerFactory ;
26
26
import org .springdoc .core .DelegatingMethodParameter ;
27
- import org .springdoc .core .customizers .DelegatingMethodParameterCustomizer ;
27
+ import org .springdoc .core .providers .RepositoryRestConfigurationProvider ;
28
+ import org .springdoc .core .providers .SpringDataWebPropertiesProvider ;
28
29
29
- import org .springframework .boot .autoconfigure .data .web .SpringDataWebProperties ;
30
30
import org .springframework .core .MethodParameter ;
31
- import org .springframework .data .rest .core .config .RepositoryRestConfiguration ;
32
31
import org .springframework .data .web .PageableDefault ;
33
32
34
33
/**
@@ -41,39 +40,42 @@ public class DataRestDelegatingMethodParameterCustomizer implements DelegatingMe
41
40
*/
42
41
private static final Logger LOGGER = LoggerFactory .getLogger (DataRestDelegatingMethodParameterCustomizer .class );
43
42
43
+
44
44
/**
45
- * The Optional spring data web properties.
45
+ * The Optional spring data web properties provider .
46
46
*/
47
- private final Optional <SpringDataWebProperties > optionalSpringDataWebProperties ;
47
+ private final Optional <SpringDataWebPropertiesProvider > optionalSpringDataWebPropertiesProvider ;
48
+
48
49
49
50
/**
50
- * The Optional repository rest configuration.
51
+ * The Optional repository rest configuration provider .
51
52
*/
52
- private final Optional <RepositoryRestConfiguration > optionalRepositoryRestConfiguration ;
53
+ private final Optional <RepositoryRestConfigurationProvider > optionalRepositoryRestConfigurationProvider ;
54
+
53
55
54
56
/**
55
57
* Instantiates a new Data rest delegating method parameter customizer.
56
58
*
57
- * @param optionalSpringDataWebProperties the optional spring data web properties
58
- * @param optionalRepositoryRestConfiguration the optional repository rest configuration
59
+ * @param optionalSpringDataWebPropertiesProvider the optional spring data web properties provider
60
+ * @param optionalRepositoryRestConfigurationProvider the optional repository rest configuration provider
59
61
*/
60
- public DataRestDelegatingMethodParameterCustomizer (Optional <SpringDataWebProperties > optionalSpringDataWebProperties , Optional <RepositoryRestConfiguration > optionalRepositoryRestConfiguration ) {
61
- this .optionalSpringDataWebProperties = optionalSpringDataWebProperties ;
62
- this .optionalRepositoryRestConfiguration = optionalRepositoryRestConfiguration ;
62
+ public DataRestDelegatingMethodParameterCustomizer (Optional <SpringDataWebPropertiesProvider > optionalSpringDataWebPropertiesProvider , Optional <RepositoryRestConfigurationProvider > optionalRepositoryRestConfigurationProvider ) {
63
+ this .optionalSpringDataWebPropertiesProvider = optionalSpringDataWebPropertiesProvider ;
64
+ this .optionalRepositoryRestConfigurationProvider = optionalRepositoryRestConfigurationProvider ;
63
65
}
64
66
65
67
@ Override
66
68
public void customize (MethodParameter originalParameter , MethodParameter methodParameter ) {
67
69
PageableDefault pageableDefault = originalParameter .getParameterAnnotation (PageableDefault .class );
68
- if (pageableDefault != null || (org .springframework .data .domain .Pageable .class .isAssignableFrom (originalParameter .getParameterType ()) && (optionalSpringDataWebProperties . isPresent () || optionalRepositoryRestConfiguration . isPresent ()))) {
70
+ if (pageableDefault != null || (org .springframework .data .domain .Pageable .class .isAssignableFrom (originalParameter .getParameterType ()) && (isSpringDataWebPropertiesPresent () || isRepositoryRestConfigurationPresent ()))) {
69
71
Field field = FieldUtils .getDeclaredField (DelegatingMethodParameter .class , "additionalParameterAnnotations" , true );
70
72
try {
71
73
Annotation [] parameterAnnotations = (Annotation []) field .get (methodParameter );
72
74
if (ArrayUtils .isNotEmpty (parameterAnnotations ))
73
75
for (int i = 0 ; i < parameterAnnotations .length ; i ++) {
74
- if (Parameter .class .equals (parameterAnnotations [i ].annotationType ())){
75
- Optional <Annotation > annotationForField = getNewParameterAnnotationForField (methodParameter , pageableDefault );
76
- if (annotationForField .isPresent ())
76
+ if (Parameter .class .equals (parameterAnnotations [i ].annotationType ())) {
77
+ Optional <Annotation > annotationForField = getNewParameterAnnotationForField (methodParameter , pageableDefault );
78
+ if (annotationForField .isPresent ())
77
79
parameterAnnotations [i ] = annotationForField .get ();
78
80
}
79
81
}
@@ -637,26 +639,26 @@ private String getName(String parameterName, String originalName) {
637
639
String name = null ;
638
640
switch (parameterName ) {
639
641
case "size" :
640
- if (optionalRepositoryRestConfiguration . isPresent ())
641
- name = optionalRepositoryRestConfiguration .get ().getLimitParamName ();
642
- else if (optionalSpringDataWebProperties . isPresent ())
643
- name = optionalSpringDataWebProperties .get ().getPageable ().getSizeParameter ();
642
+ if (isRepositoryRestConfigurationPresent ())
643
+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getLimitParamName ();
644
+ else if (isSpringDataWebPropertiesPresent ())
645
+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getSizeParameter ();
644
646
else
645
647
name = originalName ;
646
648
break ;
647
649
case "sort" :
648
- if (optionalRepositoryRestConfiguration . isPresent ())
649
- name = optionalRepositoryRestConfiguration .get ().getSortParamName ();
650
- else if (optionalSpringDataWebProperties . isPresent ())
651
- name = optionalSpringDataWebProperties .get ().getSort ().getSortParameter ();
650
+ if (isRepositoryRestConfigurationPresent ())
651
+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getSortParamName ();
652
+ else if (isSpringDataWebPropertiesPresent ())
653
+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getSort ().getSortParameter ();
652
654
else
653
655
name = originalName ;
654
656
break ;
655
657
case "page" :
656
- if (optionalRepositoryRestConfiguration . isPresent ())
657
- name = optionalRepositoryRestConfiguration .get ().getPageParamName ();
658
- else if (optionalSpringDataWebProperties . isPresent ())
659
- name = optionalSpringDataWebProperties .get ().getPageable ().getPageParameter ();
658
+ if (isRepositoryRestConfigurationPresent ())
659
+ name = optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getPageParamName ();
660
+ else if (isSpringDataWebPropertiesPresent ())
661
+ name = optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getPageParameter ();
660
662
else
661
663
name = originalName ;
662
664
break ;
@@ -684,10 +686,10 @@ private String getDefaultValue(String parameterName, PageableDefault pageableDef
684
686
case "size" :
685
687
if (pageableDefault != null )
686
688
defaultValue = String .valueOf (pageableDefault .size ());
687
- else if (optionalRepositoryRestConfiguration . isPresent ())
688
- defaultValue = String .valueOf (optionalRepositoryRestConfiguration .get ().getDefaultPageSize ());
689
- else if (optionalSpringDataWebProperties . isPresent ())
690
- defaultValue = String .valueOf (optionalSpringDataWebProperties .get ().getPageable ().getDefaultPageSize ());
689
+ else if (isRepositoryRestConfigurationPresent ())
690
+ defaultValue = String .valueOf (optionalRepositoryRestConfigurationProvider .get (). getRepositoryRestConfiguration ().getDefaultPageSize ());
691
+ else if (isSpringDataWebPropertiesPresent ())
692
+ defaultValue = String .valueOf (optionalSpringDataWebPropertiesProvider .get (). getSpringDataWebProperties ().getPageable ().getDefaultPageSize ());
691
693
else
692
694
defaultValue = defaultSchemaVal ;
693
695
break ;
@@ -730,4 +732,21 @@ private String getArrayDefaultValue(String parameterName, PageableDefault pageab
730
732
return defaultValue ;
731
733
}
732
734
735
+ /**
736
+ * Spring data web properties is present boolean.
737
+ *
738
+ * @return the boolean
739
+ */
740
+ private boolean isSpringDataWebPropertiesPresent () {
741
+ return optionalSpringDataWebPropertiesProvider .isPresent () && optionalSpringDataWebPropertiesProvider .get ().isSpringDataWebPropertiesPresent ();
742
+ }
743
+
744
+ /**
745
+ * Repository rest configuration is present boolean.
746
+ *
747
+ * @return the boolean
748
+ */
749
+ private boolean isRepositoryRestConfigurationPresent () {
750
+ return optionalRepositoryRestConfigurationProvider .isPresent () && optionalRepositoryRestConfigurationProvider .get ().isRepositoryRestConfigurationPresent ();
751
+ }
733
752
}
0 commit comments