1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.gbif.ws.client;
15
16 import org.gbif.api.annotation.PartialDate;
17
18 import java.lang.annotation.Annotation;
19 import java.lang.reflect.Method;
20 import java.util.Collection;
21
22 import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
23
24 import feign.MethodMetadata;
25 import feign.Util;
26
27
28
29
30
31
32 public class PartialDateParameterProcessor implements AnnotatedParameterProcessor {
33
34 private static final Class<PartialDate> ANNOTATION = PartialDate.class;
35
36 private PartialDateExpandereExpander">PartialDateExpander partialDateExpander = new PartialDateExpander();
37
38 @Override
39 public Class<? extends Annotation> getAnnotationType() {
40 return ANNOTATION;
41 }
42
43 @Override
44 public boolean processArgument(
45 AnnotatedParameterContext context, Annotation annotation, Method method) {
46 int parameterIndex = context.getParameterIndex();
47 MethodMetadata data = context.getMethodMetadata();
48 PartialDate requestParam = ANNOTATION.cast(annotation);
49 String name = requestParam.value();
50
51 Util.checkState(Util.emptyToNull(name) != null, "PartialDate.value() was null");
52
53 context.setParameterName(name);
54
55 data.indexToExpander().put(parameterIndex, partialDateExpander);
56 Collection<String> query =
57 context.setTemplateParameter(name, data.template().queries().get(name));
58 data.template().query(name, query);
59
60 return true;
61 }
62 }