-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwitcherProperties.java
More file actions
232 lines (173 loc) · 6.07 KB
/
SwitcherProperties.java
File metadata and controls
232 lines (173 loc) · 6.07 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package com.github.switcherapi.client;
import java.lang.reflect.Field;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import com.github.switcherapi.client.exception.SwitcherContextException;
import com.github.switcherapi.client.model.ContextKey;
import com.github.switcherapi.client.utils.SwitcherUtils;
/**
* The configuration definition object contains all necessary SDK properties to
* control the API client behaviors, access and snapshot location.
*
* @author Roger Floriano (petruki)
*/
class SwitcherProperties {
public static final String DEFAULT_ENV = "default";
public static final String DEFAULT_REGEX_TIMEOUT = "3000";
public static final String DEFAULT_TIMEOUT_MS = "3000";
private String contextLocation;
private String url;
private String apiKey;
private String domain;
private String component;
private String environment;
private String snapshotLocation;
private String snapshotAutoUpdateInterval;
private String regexTimeout;
private String silentMode;
private boolean snapshotAutoLoad;
private boolean snapshotSkipValidation;
private boolean offlineMode;
private String truststorePath;
private String truststorePassword;
private String timeoutMs;
public SwitcherProperties() {
this.environment = DEFAULT_ENV;
this.regexTimeout = DEFAULT_REGEX_TIMEOUT;
this.timeoutMs = DEFAULT_TIMEOUT_MS;
}
public void loadFromProperties(Properties prop) {
setContextLocation(SwitcherUtils.resolveProperties(ContextKey.CONTEXT_LOCATION.getParam(), prop));
setUrl(SwitcherUtils.resolveProperties(ContextKey.URL.getParam(), prop));
setApiKey(SwitcherUtils.resolveProperties(ContextKey.APIKEY.getParam(), prop));
setDomain(SwitcherUtils.resolveProperties(ContextKey.DOMAIN.getParam(), prop));
setComponent(SwitcherUtils.resolveProperties(ContextKey.COMPONENT.getParam(), prop));
setEnvironment(SwitcherUtils.resolveProperties(ContextKey.ENVIRONMENT.getParam(), prop));
setSnapshotLocation(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_LOCATION.getParam(), prop));
setSnapshotSkipValidation(Boolean.parseBoolean(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_SKIP_VALIDATION.getParam(), prop)));
setSnapshotAutoLoad(Boolean.parseBoolean(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_AUTO_LOAD.getParam(), prop)));
setSnapshotAutoUpdateInterval(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_AUTO_UPDATE_INTERVAL.getParam(), prop));
setSilentMode(SwitcherUtils.resolveProperties(ContextKey.SILENT_MODE.getParam(), prop));
setOfflineMode(Boolean.parseBoolean(SwitcherUtils.resolveProperties(ContextKey.OFFLINE_MODE.getParam(), prop)));
setRegexTimeout(SwitcherUtils.resolveProperties(ContextKey.REGEX_TIMEOUT.getParam(), prop));
setTruststorePath(SwitcherUtils.resolveProperties(ContextKey.TRUSTSTORE_PATH.getParam(), prop));
setTruststorePassword(SwitcherUtils.resolveProperties(ContextKey.TRUSTSTORE_PASSWORD.getParam(), prop));
setTimeoutMs(SwitcherUtils.resolveProperties(ContextKey.TIMEOUT_MS.getParam(), prop));
}
public <T> T getValue(ContextKey contextKey, Class<T> type) {
try {
final Field field = SwitcherProperties.class.getDeclaredField(contextKey.getPropField());
return type.cast(field.get(this));
} catch (Exception e) {
throw new SwitcherContextException(e.getMessage());
}
}
public String getContextLocation() {
return contextLocation;
}
public void setContextLocation(String contextLocation) {
this.contextLocation = contextLocation;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getApiKey() {
return apiKey;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
}
public String getDomain() {
return domain;
}
public void setDomain(String domain) {
this.domain = domain;
}
public String getComponent() {
return component;
}
public void setComponent(String component) {
this.component = component;
}
public String getEnvironment() {
return environment;
}
public void setEnvironment(String environment) {
if (StringUtils.isNotBlank(environment)) {
this.environment = environment;
} else {
this.environment = DEFAULT_ENV;
}
}
public String getSnapshotLocation() {
return snapshotLocation;
}
public void setSnapshotLocation(String snapshotLocation) {
this.snapshotLocation = snapshotLocation;
}
public String getSnapshotAutoUpdateInterval() {
return snapshotAutoUpdateInterval;
}
public void setSnapshotAutoUpdateInterval(String snapshotAutoUpdateInterval) {
this.snapshotAutoUpdateInterval = snapshotAutoUpdateInterval;
}
public String getRegexTimeout() {
return regexTimeout;
}
public void setRegexTimeout(String regexTimeout) {
if (StringUtils.isNotBlank(regexTimeout)) {
this.regexTimeout = regexTimeout;
} else {
this.regexTimeout = DEFAULT_REGEX_TIMEOUT;
}
}
public boolean isSnapshotAutoLoad() {
return snapshotAutoLoad;
}
public void setSnapshotAutoLoad(boolean snapshotAutoLoad) {
this.snapshotAutoLoad = snapshotAutoLoad;
}
public boolean isSnapshotSkipValidation() {
return snapshotSkipValidation;
}
public void setSnapshotSkipValidation(boolean snapshotSkipValidation) {
this.snapshotSkipValidation = snapshotSkipValidation;
}
public String getSilentMode() {
return silentMode;
}
public void setSilentMode(String silentMode) {
this.silentMode = silentMode;
}
public boolean isOfflineMode() {
return offlineMode;
}
public void setOfflineMode(boolean offlineMode) {
this.offlineMode = offlineMode;
}
public String getTruststorePath() {
return truststorePath;
}
public void setTruststorePath(String truststorePath) {
this.truststorePath = truststorePath;
}
public String getTruststorePassword() {
return truststorePassword;
}
public void setTruststorePassword(String truststorePassword) {
this.truststorePassword = truststorePassword;
}
public String getTimeoutMs() {
return timeoutMs;
}
public void setTimeoutMs(String timeoutMs) {
if (StringUtils.isNotBlank(timeoutMs)) {
this.timeoutMs = timeoutMs;
} else {
this.timeoutMs = DEFAULT_TIMEOUT_MS;
}
}
}