|
2 | 2 |
|
3 | 3 | import com.github.switcherapi.client.exception.SwitcherContextException; |
4 | 4 | import com.github.switcherapi.client.model.ContextKey; |
5 | | -import com.github.switcherapi.client.utils.SwitcherUtils; |
6 | 5 | import org.apache.commons.lang3.StringUtils; |
7 | 6 |
|
8 | 7 | import java.util.HashMap; |
9 | 8 | import java.util.Map; |
10 | 9 | import java.util.Properties; |
11 | 10 |
|
12 | 11 | import static com.github.switcherapi.client.remote.Constants.*; |
| 12 | +import static com.github.switcherapi.client.utils.SwitcherUtils.*; |
13 | 13 |
|
14 | 14 | public class SwitcherPropertiesImpl implements SwitcherProperties { |
15 | 15 |
|
16 | 16 | private final Map<String, Object> properties = new HashMap<>(); |
17 | 17 |
|
18 | 18 | public SwitcherPropertiesImpl() { |
| 19 | + initDefaults(); |
| 20 | + } |
| 21 | + |
| 22 | + private void initDefaults() { |
19 | 23 | setValue(ContextKey.ENVIRONMENT, DEFAULT_ENV); |
20 | 24 | setValue(ContextKey.REGEX_TIMEOUT, DEFAULT_REGEX_TIMEOUT); |
21 | 25 | setValue(ContextKey.TIMEOUT_MS, DEFAULT_TIMEOUT); |
22 | 26 | setValue(ContextKey.POOL_CONNECTION_SIZE, DEFAULT_POOL_SIZE); |
23 | 27 | setValue(ContextKey.SNAPSHOT_AUTO_LOAD, false); |
24 | 28 | setValue(ContextKey.SNAPSHOT_SKIP_VALIDATION, false); |
| 29 | + setValue(ContextKey.SNAPSHOT_WATCHER, false); |
25 | 30 | setValue(ContextKey.LOCAL_MODE, false); |
26 | 31 | setValue(ContextKey.CHECK_SWITCHERS, false); |
27 | 32 | setValue(ContextKey.RESTRICT_RELAY, true); |
28 | 33 | } |
29 | 34 |
|
30 | 35 | @Override |
31 | 36 | public void loadFromProperties(Properties prop) { |
32 | | - setValue(ContextKey.CONTEXT_LOCATION, SwitcherUtils.resolveProperties(ContextKey.CONTEXT_LOCATION.getParam(), prop)); |
33 | | - setValue(ContextKey.URL, SwitcherUtils.resolveProperties(ContextKey.URL.getParam(), prop)); |
34 | | - setValue(ContextKey.APIKEY, SwitcherUtils.resolveProperties(ContextKey.APIKEY.getParam(), prop)); |
35 | | - setValue(ContextKey.DOMAIN, SwitcherUtils.resolveProperties(ContextKey.DOMAIN.getParam(), prop)); |
36 | | - setValue(ContextKey.COMPONENT, SwitcherUtils.resolveProperties(ContextKey.COMPONENT.getParam(), prop)); |
37 | | - setValue(ContextKey.ENVIRONMENT, getValueDefault(SwitcherUtils.resolveProperties(ContextKey.ENVIRONMENT.getParam(), prop), DEFAULT_ENV)); |
38 | | - setValue(ContextKey.SNAPSHOT_LOCATION, SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_LOCATION.getParam(), prop)); |
39 | | - setValue(ContextKey.SNAPSHOT_SKIP_VALIDATION, getBoolDefault(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_SKIP_VALIDATION.getParam(), prop), false)); |
40 | | - setValue(ContextKey.SNAPSHOT_AUTO_LOAD, getBoolDefault(SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_AUTO_LOAD.getParam(), prop), false)); |
41 | | - setValue(ContextKey.SNAPSHOT_AUTO_UPDATE_INTERVAL, SwitcherUtils.resolveProperties(ContextKey.SNAPSHOT_AUTO_UPDATE_INTERVAL.getParam(), prop)); |
42 | | - setValue(ContextKey.SILENT_MODE, SwitcherUtils.resolveProperties(ContextKey.SILENT_MODE.getParam(), prop)); |
43 | | - setValue(ContextKey.LOCAL_MODE, getBoolDefault(SwitcherUtils.resolveProperties(ContextKey.LOCAL_MODE.getParam(), prop), false)); |
44 | | - setValue(ContextKey.CHECK_SWITCHERS, getBoolDefault(SwitcherUtils.resolveProperties(ContextKey.CHECK_SWITCHERS.getParam(), prop), false)); |
45 | | - setValue(ContextKey.RESTRICT_RELAY, getBoolDefault(SwitcherUtils.resolveProperties(ContextKey.RESTRICT_RELAY.getParam(), prop), true)); |
46 | | - setValue(ContextKey.REGEX_TIMEOUT, getIntDefault(SwitcherUtils.resolveProperties(ContextKey.REGEX_TIMEOUT.getParam(), prop), DEFAULT_REGEX_TIMEOUT)); |
47 | | - setValue(ContextKey.TRUSTSTORE_PATH, SwitcherUtils.resolveProperties(ContextKey.TRUSTSTORE_PATH.getParam(), prop)); |
48 | | - setValue(ContextKey.TRUSTSTORE_PASSWORD, SwitcherUtils.resolveProperties(ContextKey.TRUSTSTORE_PASSWORD.getParam(), prop)); |
49 | | - setValue(ContextKey.TIMEOUT_MS, getIntDefault(SwitcherUtils.resolveProperties(ContextKey.TIMEOUT_MS.getParam(), prop), DEFAULT_TIMEOUT)); |
50 | | - setValue(ContextKey.POOL_CONNECTION_SIZE, getIntDefault(SwitcherUtils.resolveProperties(ContextKey.POOL_CONNECTION_SIZE.getParam(), prop), DEFAULT_POOL_SIZE)); |
| 37 | + setValue(ContextKey.CONTEXT_LOCATION, resolveProperties(ContextKey.CONTEXT_LOCATION.getParam(), prop)); |
| 38 | + setValue(ContextKey.URL, resolveProperties(ContextKey.URL.getParam(), prop)); |
| 39 | + setValue(ContextKey.APIKEY, resolveProperties(ContextKey.APIKEY.getParam(), prop)); |
| 40 | + setValue(ContextKey.DOMAIN, resolveProperties(ContextKey.DOMAIN.getParam(), prop)); |
| 41 | + setValue(ContextKey.COMPONENT, resolveProperties(ContextKey.COMPONENT.getParam(), prop)); |
| 42 | + setValue(ContextKey.ENVIRONMENT, getValueDefault(resolveProperties(ContextKey.ENVIRONMENT.getParam(), prop), DEFAULT_ENV)); |
| 43 | + setValue(ContextKey.SNAPSHOT_LOCATION, resolveProperties(ContextKey.SNAPSHOT_LOCATION.getParam(), prop)); |
| 44 | + setValue(ContextKey.SNAPSHOT_SKIP_VALIDATION, getBoolDefault(resolveProperties(ContextKey.SNAPSHOT_SKIP_VALIDATION.getParam(), prop), false)); |
| 45 | + setValue(ContextKey.SNAPSHOT_AUTO_LOAD, getBoolDefault(resolveProperties(ContextKey.SNAPSHOT_AUTO_LOAD.getParam(), prop), false)); |
| 46 | + setValue(ContextKey.SNAPSHOT_AUTO_UPDATE_INTERVAL, resolveProperties(ContextKey.SNAPSHOT_AUTO_UPDATE_INTERVAL.getParam(), prop)); |
| 47 | + setValue(ContextKey.SNAPSHOT_WATCHER, getBoolDefault(resolveProperties(ContextKey.SNAPSHOT_WATCHER.getParam(), prop), false)); |
| 48 | + setValue(ContextKey.SILENT_MODE, resolveProperties(ContextKey.SILENT_MODE.getParam(), prop)); |
| 49 | + setValue(ContextKey.LOCAL_MODE, getBoolDefault(resolveProperties(ContextKey.LOCAL_MODE.getParam(), prop), false)); |
| 50 | + setValue(ContextKey.CHECK_SWITCHERS, getBoolDefault(resolveProperties(ContextKey.CHECK_SWITCHERS.getParam(), prop), false)); |
| 51 | + setValue(ContextKey.RESTRICT_RELAY, getBoolDefault(resolveProperties(ContextKey.RESTRICT_RELAY.getParam(), prop), true)); |
| 52 | + setValue(ContextKey.REGEX_TIMEOUT, getIntDefault(resolveProperties(ContextKey.REGEX_TIMEOUT.getParam(), prop), DEFAULT_REGEX_TIMEOUT)); |
| 53 | + setValue(ContextKey.TRUSTSTORE_PATH, resolveProperties(ContextKey.TRUSTSTORE_PATH.getParam(), prop)); |
| 54 | + setValue(ContextKey.TRUSTSTORE_PASSWORD, resolveProperties(ContextKey.TRUSTSTORE_PASSWORD.getParam(), prop)); |
| 55 | + setValue(ContextKey.TIMEOUT_MS, getIntDefault(resolveProperties(ContextKey.TIMEOUT_MS.getParam(), prop), DEFAULT_TIMEOUT)); |
| 56 | + setValue(ContextKey.POOL_CONNECTION_SIZE, getIntDefault(resolveProperties(ContextKey.POOL_CONNECTION_SIZE.getParam(), prop), DEFAULT_POOL_SIZE)); |
51 | 57 | } |
52 | 58 |
|
53 | 59 | @Override |
|
0 commit comments