-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathConfigurationMaps.java
50 lines (38 loc) · 1.43 KB
/
ConfigurationMaps.java
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
package io.zeebe.http;
import io.camunda.zeebe.client.api.response.ActivatedJob;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class ConfigurationMaps {
private final Map<String, String> customHeaders;
private final Map<String, Object> variables;
private final Map<String, String> environmentVariables;
private final Map<String, Object> config;
public ConfigurationMaps(ActivatedJob job, Map<String, String> environmentVariables) {
this.customHeaders = job.getCustomHeaders();
this.variables = job.getVariablesAsMap();
this.environmentVariables = environmentVariables;
config = new HashMap<>();
config.putAll(customHeaders);
config.putAll(variables);
config.putAll(environmentVariables);
config.put("jobKey", job.getKey());
config.put("processInstanceKey", job.getProcessInstanceKey());
}
public Optional<Object> get(String key) {
return Optional.<Object>ofNullable(config.get(key));
}
public Optional<String> getString(String key) {
return get(key).map(String::valueOf).filter(v -> !v.isEmpty());
}
public Optional<String> getStringIgnoreCase(String key) {
return config.entrySet().stream()
.filter(entry -> entry.getKey().equalsIgnoreCase(key))
.map(entry -> String.valueOf(entry.getValue()))
.filter(value -> !value.isEmpty())
.findFirst();
}
public Map<String, Object> getConfig() {
return config;
}
}