1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.role; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
20 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
21 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
22 | |
import org.kuali.rice.core.api.CoreConstants; |
23 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
24 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
25 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
26 | |
import org.kuali.rice.kim.api.KimConstants; |
27 | |
import org.w3c.dom.Element; |
28 | |
|
29 | |
import javax.xml.bind.annotation.XmlAccessType; |
30 | |
import javax.xml.bind.annotation.XmlAccessorType; |
31 | |
import javax.xml.bind.annotation.XmlAnyElement; |
32 | |
import javax.xml.bind.annotation.XmlElement; |
33 | |
import javax.xml.bind.annotation.XmlRootElement; |
34 | |
import javax.xml.bind.annotation.XmlType; |
35 | |
import java.util.Collection; |
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
@XmlRootElement(name = Role.Constants.ROOT_ELEMENT_NAME) |
44 | |
@XmlAccessorType(XmlAccessType.NONE) |
45 | |
@XmlType(name = Role.Constants.TYPE_NAME, propOrder = { |
46 | |
Role.Elements.ID, |
47 | |
Role.Elements.NAME, |
48 | |
Role.Elements.NAMESPACE_CODE, |
49 | |
Role.Elements.DESCRIPTION, |
50 | |
Role.Elements.KIM_TYPE_ID, |
51 | |
Role.Elements.ACTIVE, |
52 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
53 | |
CoreConstants.CommonElements.OBJECT_ID, |
54 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
55 | |
}) |
56 | 0 | public final class Role extends AbstractDataTransferObject implements RoleContract { |
57 | |
private static final long serialVersionUID = 1L; |
58 | |
|
59 | |
@XmlElement(name = Role.Elements.ID, required = true) |
60 | |
private final String id; |
61 | |
|
62 | |
@XmlElement(name = Role.Elements.NAME, required = true) |
63 | |
private final String name; |
64 | |
|
65 | |
@XmlElement(name = Role.Elements.NAMESPACE_CODE, required = true) |
66 | |
private final String namespaceCode; |
67 | |
|
68 | |
@XmlElement(name = Role.Elements.DESCRIPTION) |
69 | |
private final String description; |
70 | |
|
71 | |
@XmlElement(name = Role.Elements.KIM_TYPE_ID, required = true) |
72 | |
private final String kimTypeId; |
73 | |
|
74 | |
@XmlElement(name = CoreConstants.CommonElements.ACTIVE, required = true) |
75 | |
private final boolean active; |
76 | |
|
77 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER) |
78 | |
private final Long versionNumber; |
79 | |
|
80 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
81 | |
private final String objectId; |
82 | |
|
83 | 0 | @SuppressWarnings("unused") |
84 | |
@XmlAnyElement |
85 | |
private final Collection<Element> _futureElements = null; |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
@SuppressWarnings("unused") |
92 | 0 | private Role() { |
93 | 0 | id = null; |
94 | 0 | name = null; |
95 | 0 | namespaceCode = null; |
96 | 0 | description = null; |
97 | 0 | kimTypeId = null; |
98 | 0 | active = false; |
99 | 0 | objectId = null; |
100 | 0 | versionNumber = null; |
101 | 0 | } |
102 | |
|
103 | 0 | private Role(Builder builder) { |
104 | 0 | id = builder.getId(); |
105 | 0 | name = builder.getName(); |
106 | 0 | namespaceCode = builder.getNamespaceCode(); |
107 | 0 | description = builder.getDescription(); |
108 | 0 | kimTypeId = builder.getKimTypeId(); |
109 | 0 | active = builder.isActive(); |
110 | 0 | versionNumber = builder.getVersionNumber(); |
111 | 0 | objectId = builder.getObjectId(); |
112 | 0 | } |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
@Override |
119 | |
public String getId() { |
120 | 0 | return id; |
121 | |
} |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
@Override |
127 | |
public String getNamespaceCode() { |
128 | 0 | return namespaceCode; |
129 | |
} |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
@Override |
135 | |
public String getName() { |
136 | 0 | return name; |
137 | |
} |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
@Override |
143 | |
public String getDescription() { |
144 | 0 | return description; |
145 | |
} |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
@Override |
151 | |
public String getKimTypeId() { |
152 | 0 | return kimTypeId; |
153 | |
} |
154 | |
|
155 | |
@Override |
156 | |
public Long getVersionNumber() { |
157 | 0 | return versionNumber; |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public String getObjectId() { |
162 | 0 | return objectId; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
public boolean isActive() { |
167 | 0 | return active; |
168 | |
} |
169 | |
|
170 | 0 | public static final class Builder implements RoleContract, ModelBuilder, ModelObjectComplete { |
171 | |
|
172 | |
private String id; |
173 | |
private String name; |
174 | |
private String namespaceCode; |
175 | |
private String description; |
176 | |
private String kimTypeId; |
177 | |
private boolean active; |
178 | |
private Long versionNumber; |
179 | |
private String objectId; |
180 | |
|
181 | 0 | private Builder() { |
182 | 0 | } |
183 | |
|
184 | |
public static Builder create() { |
185 | 0 | return new Builder(); |
186 | |
} |
187 | |
|
188 | |
public static Builder create(String id, String name, String namespaceCode, String description, String kimTypeId) { |
189 | 0 | Builder b = new Builder(); |
190 | 0 | b.setId(id); |
191 | 0 | b.setName(name); |
192 | 0 | b.setNamespaceCode(namespaceCode); |
193 | 0 | b.setDescription(description); |
194 | 0 | b.setKimTypeId(kimTypeId); |
195 | 0 | b.setActive(true); |
196 | |
|
197 | 0 | return b; |
198 | |
} |
199 | |
|
200 | |
public static Builder create(RoleContract roleContract) { |
201 | 0 | Builder b = new Builder(); |
202 | 0 | b.setId(roleContract.getId()); |
203 | 0 | b.setName(roleContract.getName()); |
204 | 0 | b.setNamespaceCode(roleContract.getNamespaceCode()); |
205 | 0 | b.setDescription(roleContract.getDescription()); |
206 | 0 | b.setKimTypeId(roleContract.getKimTypeId()); |
207 | 0 | b.setActive(roleContract.isActive()); |
208 | 0 | b.setVersionNumber(roleContract.getVersionNumber()); |
209 | 0 | b.setObjectId(roleContract.getObjectId()); |
210 | 0 | return b; |
211 | |
} |
212 | |
|
213 | |
@Override |
214 | |
public Role build() { |
215 | 0 | return new Role(this); |
216 | |
} |
217 | |
|
218 | |
public void setId(String id) { |
219 | 0 | if (StringUtils.isBlank(id)) { |
220 | 0 | throw new IllegalArgumentException("id cannot be blank or null"); |
221 | |
} |
222 | 0 | this.id = id; |
223 | 0 | } |
224 | |
|
225 | |
@Override |
226 | |
public String getId() { |
227 | 0 | return id; |
228 | |
} |
229 | |
|
230 | |
public void setNamespaceCode(String namespaceCode) { |
231 | 0 | if (StringUtils.isBlank(namespaceCode)) { |
232 | 0 | throw new IllegalArgumentException("namespaceCode cannot be blank or null"); |
233 | |
} |
234 | 0 | this.namespaceCode = namespaceCode; |
235 | 0 | } |
236 | |
|
237 | |
@Override |
238 | |
public String getNamespaceCode() { |
239 | 0 | return namespaceCode; |
240 | |
} |
241 | |
|
242 | |
public void setName(String name) { |
243 | 0 | if (StringUtils.isBlank(name)) { |
244 | 0 | throw new IllegalArgumentException("name cannot be blank or null"); |
245 | |
} |
246 | 0 | this.name = name; |
247 | 0 | } |
248 | |
|
249 | |
@Override |
250 | |
public String getName() { |
251 | 0 | return name; |
252 | |
} |
253 | |
|
254 | |
public void setDescription(String description) { |
255 | 0 | this.description = description; |
256 | 0 | } |
257 | |
|
258 | |
@Override |
259 | |
public String getDescription() { |
260 | 0 | return description; |
261 | |
} |
262 | |
|
263 | |
public void setKimTypeId(String kimTypeId) { |
264 | 0 | if (StringUtils.isBlank(kimTypeId)) { |
265 | 0 | throw new IllegalArgumentException("kimTypeId cannot be blank or null"); |
266 | |
} |
267 | 0 | this.kimTypeId = kimTypeId; |
268 | 0 | } |
269 | |
|
270 | |
@Override |
271 | |
public String getKimTypeId() { |
272 | 0 | return kimTypeId; |
273 | |
} |
274 | |
|
275 | |
public void setActive(boolean active) { |
276 | 0 | this.active = active; |
277 | 0 | } |
278 | |
|
279 | |
@Override |
280 | |
public boolean isActive() { |
281 | 0 | return active; |
282 | |
} |
283 | |
|
284 | |
public void setVersionNumber(Long versionNumber) { |
285 | 0 | this.versionNumber = versionNumber; |
286 | 0 | } |
287 | |
|
288 | |
@Override |
289 | |
public Long getVersionNumber() { |
290 | 0 | return versionNumber; |
291 | |
} |
292 | |
|
293 | |
public void setObjectId(String objectId) { |
294 | 0 | this.objectId = objectId; |
295 | 0 | } |
296 | |
|
297 | |
@Override |
298 | |
public String getObjectId() { |
299 | 0 | return objectId; |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public int hashCode() { |
304 | 0 | return HashCodeBuilder.reflectionHashCode(this); |
305 | |
} |
306 | |
|
307 | |
@Override |
308 | |
public boolean equals(Object obj) { |
309 | 0 | return EqualsBuilder.reflectionEquals(obj, this); |
310 | |
} |
311 | |
|
312 | |
@Override |
313 | |
public String toString() { |
314 | 0 | return ToStringBuilder.reflectionToString(this); |
315 | |
} |
316 | |
} |
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | 0 | static class Elements { |
323 | |
final static String ID = "id"; |
324 | |
final static String NAME = "name"; |
325 | |
final static String DESCRIPTION = "description"; |
326 | |
final static String KIM_TYPE_ID = "kimTypeId"; |
327 | |
final static String NAMESPACE_CODE = "namespaceCode"; |
328 | |
final static String ACTIVE = "active"; |
329 | |
} |
330 | |
|
331 | |
|
332 | |
|
333 | |
|
334 | 0 | static class Constants { |
335 | |
final static String ROOT_ELEMENT_NAME = "role"; |
336 | |
final static String TYPE_NAME = "RoleType"; |
337 | |
} |
338 | |
|
339 | 0 | public static class Cache { |
340 | |
public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + Role.Constants.TYPE_NAME; |
341 | |
} |
342 | |
} |