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