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 org.apache.commons.lang.StringUtils;
19
20 import de.smartics.properties.api.config.domain.key.ApplicationId;
21 import de.smartics.properties.api.config.domain.key.EnvironmentId;
22 import de.smartics.properties.impl.config.domain.key.envapp.AbstractConfigurationKey;
23 import de.smartics.util.lang.Arg;
24
25
26
27
28
29
30 public final class TenantUserConfigurationKey extends
31 AbstractConfigurationKey<TenantUserConfigurationKey>
32 {
33
34
35
36
37
38
39
40
41
42
43 private static final long serialVersionUID = 1L;
44
45
46
47
48
49
50
51
52 private final TenantId tenantId;
53
54
55
56
57
58
59 private final UserId userId;
60
61
62
63
64
65
66 private final int hashCodeValue;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public TenantUserConfigurationKey(final EnvironmentId environmentId,
83 final ApplicationId applicationId) throws NullPointerException
84 {
85 this(environmentId, applicationId, TenantId.ANY_TENANT, UserId.ANY_USER);
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 public TenantUserConfigurationKey(final EnvironmentId environmentId,
102 final ApplicationId applicationId, final TenantId tenantId,
103 final UserId userId) throws NullPointerException
104 {
105 super(environmentId, applicationId);
106 this.tenantId = Arg.checkNotNull("tenantId", tenantId);
107 this.userId = Arg.checkNotNull("userId", userId);
108 this.hashCodeValue = calcHashCode();
109 }
110
111
112
113
114
115
116
117
118
119 public TenantUserConfigurationKey(final TenantUserConfigurationKey key,
120 final ApplicationId appId) throws NullPointerException
121 {
122 this(key.getEnvironmentId(), appId, key.tenantId, key.userId);
123 }
124
125
126
127
128
129
130
131 private int calcHashCode()
132 {
133 int result = super.hashCodeValue;
134 result = 37 * result + tenantId.hashCode();
135 result = 37 * result + userId.hashCode();
136
137 return result;
138 }
139
140
141
142
143
144
145
146
147 public TenantId getTenantId()
148 {
149 return tenantId;
150 }
151
152
153
154
155
156
157 public UserId getUserId()
158 {
159 return userId;
160 }
161
162
163
164 @Override
165 public boolean hasActiveDynamicParts()
166 {
167 return !(TenantId.ANY_TENANT.equals(this.tenantId) && UserId.ANY_USER
168 .equals(this.userId));
169 }
170
171
172
173
174
175
176
177
178 @Override
179 public int hashCode()
180 {
181 return hashCodeValue;
182 }
183
184
185
186
187
188
189
190
191
192 @Override
193 public boolean equals(final Object object)
194 {
195 if (this == object)
196 {
197 return true;
198 }
199 else if (!super.equals(object))
200 {
201 return false;
202 }
203
204 final TenantUserConfigurationKey other =
205 (TenantUserConfigurationKey) object;
206
207 return (tenantId.equals(other.tenantId) && userId.equals(other.userId));
208 }
209
210 @Override
211 public int compareTo(final TenantUserConfigurationKey o)
212 {
213 int result = super.compareTo(o);
214 if (result == 0)
215 {
216 result = tenantId.compareTo(o.tenantId);
217 }
218 if (result == 0)
219 {
220 result = userId.compareTo(o.userId);
221 }
222 return result;
223 }
224
225 @Override
226 public String toString()
227 {
228 final StringBuilder buffer = new StringBuilder();
229
230 final String userIdString = userId.toString();
231 if (StringUtils.isNotBlank(userIdString))
232 {
233 buffer.append(userIdString);
234 }
235 buffer.append('/');
236
237 final String tenantIdString = tenantId.toString();
238 if (StringUtils.isNotBlank(tenantIdString))
239 {
240 buffer.append(tenantIdString);
241 }
242 buffer.append('/');
243
244 buffer.append(super.toString());
245
246 if (buffer.length() == 0)
247 {
248 buffer.append("<no named key>");
249 }
250 return buffer.toString();
251 }
252 }