1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.rundeck.api;
26
27 import java.text.SimpleDateFormat;
28 import java.util.*;
29
30
31
32
33
34
35
36 abstract class QueryParameterBuilder implements ApiPathBuilder.BuildsParameters {
37 public static final String W3C_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
38 static final SimpleDateFormat format = new SimpleDateFormat(W3C_DATE_FORMAT);
39 static {
40 format.setTimeZone(TimeZone.getTimeZone("GMT"));
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54 protected boolean visit(String key, Object value, boolean doPost, ApiPathBuilder builder) {
55 if (null != value) {
56 if (doPost) {
57 if (value instanceof Collection) {
58 builder.field(key, (Collection<String>) value);
59 } else {
60 builder.field(key, stringVal(value));
61 }
62 return true;
63 } else {
64 if (value instanceof Collection) {
65 builder.param(key, (Collection<String>) value);
66 } else {
67 builder.param(key, stringVal(value));
68 }
69 return true;
70 }
71 }
72 return false;
73 }
74
75 private String stringVal(Object value) {
76 return value instanceof String ? (String) value :
77 value instanceof Boolean ? Boolean.toString((Boolean) value) :
78 value instanceof Date ? formatDate((Date) value)
79
80 : value.toString();
81 }
82
83 private String formatDate(Date value) {
84 return format.format(value);
85 }
86 }