1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package de.smartics.properties.impl.config.domain.key.rtaware; |
17 |
|
|
18 |
|
import static org.apache.commons.lang.StringUtils.defaultIfBlank; |
19 |
|
import de.smartics.properties.api.config.domain.key.ApplicationId; |
20 |
|
import de.smartics.properties.api.config.domain.key.ConfigurationKey; |
21 |
|
import de.smartics.properties.api.config.domain.key.ConfigurationKeyFactory; |
22 |
|
import de.smartics.properties.api.config.domain.key.EnvironmentId; |
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
0 |
final class TenantUserConfigurationKeyFactory implements |
28 |
|
ConfigurationKeyFactory<TenantUserConfigurationKey> |
29 |
|
{ |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
0 |
private static final TenantUserConfigurationKey DEFAULT = |
38 |
|
new TenantUserConfigurationKey(EnvironmentId.ANY_ENV, |
39 |
|
ApplicationId.ANY_APP, TenantId.ANY_TENANT, UserId.ANY_USER); |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
TenantUserConfigurationKeyFactory() |
51 |
0 |
{ |
52 |
0 |
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@Override |
65 |
|
public TenantUserConfigurationKey createDefaultKey() |
66 |
|
{ |
67 |
0 |
return DEFAULT; |
68 |
|
} |
69 |
|
|
70 |
|
@Override |
71 |
|
public ConfigurationKey<?> createKey(final ApplicationId applicationId) |
72 |
|
{ |
73 |
0 |
final RuntimeAdapter adapter = RuntimeAdapterManager.INSTANCE.adapter(); |
74 |
0 |
final ConfigurationKey<?> key = |
75 |
|
new TenantUserConfigurationKey(EnvironmentId.ANY_ENV, applicationId, |
76 |
|
adapter.getTenantId(), adapter.getUserId()); |
77 |
0 |
return key; |
78 |
|
} |
79 |
|
|
80 |
|
@Override |
81 |
|
public ConfigurationKey<?> createUniqueKey(final String id) |
82 |
|
{ |
83 |
0 |
final RuntimeAdapter adapter = RuntimeAdapterManager.INSTANCE.adapter(); |
84 |
0 |
return new TenantUserConfigurationKey(new EnvironmentId(id), |
85 |
|
ApplicationId.ANY_APP, adapter.getTenantId(), adapter.getUserId()); |
86 |
|
} |
87 |
|
|
88 |
|
@Override |
89 |
|
public ConfigurationKey<?> createKey(final ConfigurationKey<?> key, |
90 |
|
final ApplicationId appId) |
91 |
|
{ |
92 |
0 |
final ConfigurationKey<?> newKey = |
93 |
|
new TenantUserConfigurationKey((TenantUserConfigurationKey) key, appId); |
94 |
0 |
return newKey; |
95 |
|
} |
96 |
|
|
97 |
|
@Override |
98 |
|
public ConfigurationKey<?> createKeyFromString(final String key) |
99 |
|
throws IllegalArgumentException |
100 |
|
{ |
101 |
0 |
if (key == null) |
102 |
|
{ |
103 |
0 |
throw new IllegalArgumentException(String.format( |
104 |
|
"Cannot parse key '%s', since key is null", key)); |
105 |
|
|
106 |
|
} |
107 |
0 |
final String[] keyArray = key.split("/", -1); |
108 |
0 |
final int count = keyArray.length; |
109 |
0 |
final int expectedCount = 4; |
110 |
0 |
if (count != expectedCount) |
111 |
|
{ |
112 |
0 |
throw new IllegalArgumentException(String.format( |
113 |
|
"Cannot parse key '%s', since %s slash-separated elements are expected," |
114 |
|
+ " but found only %s.", key, expectedCount, count)); |
115 |
|
} |
116 |
|
|
117 |
0 |
final UserId userId = UserId.valueOf(defaultIfBlank(keyArray[0], null)); |
118 |
0 |
final TenantId tenantId = |
119 |
|
TenantId.valueOf(defaultIfBlank(keyArray[1], null)); |
120 |
|
|
121 |
0 |
final EnvironmentId environmentId = |
122 |
|
EnvironmentId.valueOf(defaultIfBlank(keyArray[2], null)); |
123 |
0 |
final ApplicationId applicationId = |
124 |
|
ApplicationId.valueOf(defaultIfBlank(keyArray[3], null)); |
125 |
|
|
126 |
0 |
final ConfigurationKey<?> newKey = |
127 |
|
new TenantUserConfigurationKey(environmentId, applicationId, tenantId, |
128 |
|
userId); |
129 |
0 |
return newKey; |
130 |
|
} |
131 |
|
|
132 |
|
@Override |
133 |
|
public ConfigurationKey<?> createStaticKey(final ConfigurationKey<?> key) |
134 |
|
{ |
135 |
0 |
final TenantUserConfigurationKey typedKey = |
136 |
|
(TenantUserConfigurationKey) key; |
137 |
0 |
return new TenantUserConfigurationKey(typedKey.getEnvironmentId(), |
138 |
|
typedKey.getApplicationId()); |
139 |
|
} |
140 |
|
|
141 |
|
|
142 |
|
|
143 |
|
} |