1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.api.common.delegate; |
17 | |
|
18 | |
import org.apache.commons.collections.CollectionUtils; |
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
21 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
22 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
23 | |
import org.kuali.rice.core.api.CoreConstants; |
24 | |
import org.kuali.rice.core.api.delegation.DelegationType; |
25 | |
import org.kuali.rice.core.api.mo.AbstractDataTransferObject; |
26 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
27 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
28 | |
import org.kuali.rice.kim.api.KimConstants; |
29 | |
import org.w3c.dom.Element; |
30 | |
|
31 | |
import javax.xml.bind.annotation.XmlAccessType; |
32 | |
import javax.xml.bind.annotation.XmlAccessorType; |
33 | |
import javax.xml.bind.annotation.XmlAnyElement; |
34 | |
import javax.xml.bind.annotation.XmlElement; |
35 | |
import javax.xml.bind.annotation.XmlRootElement; |
36 | |
import javax.xml.bind.annotation.XmlType; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Collection; |
39 | |
import java.util.Collections; |
40 | |
import java.util.List; |
41 | |
|
42 | |
|
43 | |
@XmlRootElement(name = DelegateType.Constants.ROOT_ELEMENT_NAME) |
44 | |
@XmlAccessorType(XmlAccessType.NONE) |
45 | |
@XmlType(name = DelegateType.Constants.TYPE_NAME, propOrder = { |
46 | |
DelegateType.Elements.ROLE_ID, |
47 | |
DelegateType.Elements.DELEGATION_ID, |
48 | |
DelegateType.Elements.DELEGATION_TYPE_CODE, |
49 | |
DelegateType.Elements.KIM_TYPE_ID, |
50 | |
DelegateType.Elements.MEMBERS, |
51 | |
DelegateType.Elements.ACTIVE, |
52 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
53 | |
}) |
54 | 0 | public final class DelegateType extends AbstractDataTransferObject implements DelegateTypeContract { |
55 | |
|
56 | |
private static final long serialVersionUID = 1L; |
57 | |
|
58 | |
@XmlElement(name = Elements.ROLE_ID) |
59 | |
private final String roleId; |
60 | |
|
61 | |
@XmlElement(name = Elements.DELEGATION_ID) |
62 | |
private final String delegationId; |
63 | |
|
64 | |
@XmlElement(name = Elements.DELEGATION_TYPE_CODE) |
65 | |
private final String delegationTypeCode; |
66 | |
|
67 | |
@XmlElement(name = Elements.KIM_TYPE_ID) |
68 | |
private final String kimTypeId; |
69 | |
|
70 | |
@XmlElement(name = Elements.MEMBERS) |
71 | |
private final List<DelegateMember> members; |
72 | |
|
73 | |
@XmlElement(name = Elements.ACTIVE) |
74 | |
private final boolean active; |
75 | |
|
76 | 0 | @SuppressWarnings("unused") |
77 | |
@XmlAnyElement |
78 | |
private final Collection<Element> _futureElements = null; |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
@SuppressWarnings("unused") |
84 | 0 | private DelegateType() { |
85 | 0 | roleId = null; |
86 | 0 | delegationId = null; |
87 | 0 | delegationTypeCode = null; |
88 | 0 | kimTypeId = null; |
89 | 0 | members = null; |
90 | 0 | active = false; |
91 | 0 | } |
92 | |
|
93 | 0 | private DelegateType(Builder b) { |
94 | 0 | roleId = b.getRoleId(); |
95 | 0 | delegationId = b.getDelegationId(); |
96 | 0 | delegationTypeCode = b.getDelegationType() != null ? b.getDelegationType().getCode() : null; |
97 | 0 | kimTypeId = b.getKimTypeId(); |
98 | 0 | active = b.isActive(); |
99 | |
|
100 | 0 | List<DelegateMember> delegateMembers = new ArrayList<DelegateMember>(); |
101 | 0 | if (!CollectionUtils.isEmpty(b.getMembers())) { |
102 | 0 | for (DelegateMember.Builder delgateBuilder : b.getMembers()) { |
103 | 0 | delegateMembers.add(delgateBuilder.build()); |
104 | |
} |
105 | |
} |
106 | 0 | members = delegateMembers; |
107 | 0 | } |
108 | |
|
109 | |
@Override |
110 | |
public String getKimTypeId() { |
111 | 0 | return this.kimTypeId; |
112 | |
} |
113 | |
|
114 | |
@Override |
115 | |
public boolean isActive() { |
116 | 0 | return this.active; |
117 | |
} |
118 | |
|
119 | |
@Override |
120 | |
public DelegationType getDelegationType() { |
121 | 0 | return DelegationType.fromCode(this.delegationTypeCode); |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public String getDelegationId() { |
126 | 0 | return this.delegationId; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public String getRoleId() { |
131 | 0 | return this.roleId; |
132 | |
} |
133 | |
|
134 | |
@Override |
135 | |
public List<DelegateMember> getMembers() { |
136 | 0 | return Collections.unmodifiableList(this.members); |
137 | |
} |
138 | |
|
139 | 0 | public static final class Builder implements DelegateTypeContract, ModelBuilder, ModelObjectComplete { |
140 | |
private String roleId; |
141 | |
private String delegationId; |
142 | |
private DelegationType delegationType; |
143 | |
private String kimTypeId; |
144 | |
private List<DelegateMember.Builder> members; |
145 | |
private boolean active; |
146 | |
|
147 | |
public static Builder create(DelegateTypeContract dtc) { |
148 | 0 | Builder b = new Builder(); |
149 | 0 | b.setRoleId(dtc.getRoleId()); |
150 | 0 | b.setDelegationId(dtc.getDelegationId()); |
151 | 0 | b.setDelegationType(dtc.getDelegationType()); |
152 | 0 | b.setActive(dtc.isActive()); |
153 | |
|
154 | 0 | ArrayList<DelegateMember.Builder> delegateBuilders = new ArrayList<DelegateMember.Builder>(); |
155 | 0 | for (DelegateMemberContract delegate : dtc.getMembers()) { |
156 | 0 | delegateBuilders.add(DelegateMember.Builder.create(delegate)); |
157 | |
} |
158 | 0 | b.setMembers(delegateBuilders); |
159 | |
|
160 | 0 | return b; |
161 | |
} |
162 | |
|
163 | |
public static Builder create(String roleId, String delegationId, DelegationType delegationType, List<DelegateMember.Builder> members) { |
164 | 0 | Builder b = new Builder(); |
165 | 0 | b.setRoleId(roleId); |
166 | 0 | b.setDelegationId(delegationId); |
167 | 0 | b.setDelegationType(delegationType); |
168 | 0 | b.setMembers(members); |
169 | 0 | b.setActive(true); |
170 | |
|
171 | 0 | return b; |
172 | |
} |
173 | |
|
174 | |
@Override |
175 | |
public DelegateType build() { |
176 | 0 | return new DelegateType(this); |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
public String getRoleId() { |
181 | 0 | return roleId; |
182 | |
} |
183 | |
|
184 | |
public void setRoleId(String roleId) { |
185 | 0 | if (StringUtils.isBlank(roleId)) { |
186 | 0 | throw new IllegalArgumentException("roleId cannot be null or blank"); |
187 | |
} |
188 | 0 | this.roleId = roleId; |
189 | 0 | } |
190 | |
|
191 | |
@Override |
192 | |
public String getDelegationId() { |
193 | 0 | return delegationId; |
194 | |
} |
195 | |
|
196 | |
public void setDelegationId(String delegationId) { |
197 | 0 | if (StringUtils.isBlank(delegationId)) { |
198 | 0 | throw new IllegalArgumentException("delegationId cannot be null or blank"); |
199 | |
} |
200 | |
|
201 | 0 | this.delegationId = delegationId; |
202 | 0 | } |
203 | |
|
204 | |
@Override |
205 | |
public DelegationType getDelegationType() { |
206 | 0 | return delegationType; |
207 | |
} |
208 | |
|
209 | |
public void setDelegationType(DelegationType delegationType) { |
210 | 0 | if (delegationType == null) { |
211 | 0 | throw new IllegalArgumentException("delegationTypeCode cannot be null"); |
212 | |
} |
213 | 0 | this.delegationType = delegationType; |
214 | 0 | } |
215 | |
|
216 | |
@Override |
217 | |
public String getKimTypeId() { |
218 | 0 | return kimTypeId; |
219 | |
} |
220 | |
|
221 | |
public void setKimTypeId(String kimTypeId) { |
222 | 0 | this.kimTypeId = kimTypeId; |
223 | 0 | } |
224 | |
|
225 | |
@Override |
226 | |
public List<DelegateMember.Builder> getMembers() { |
227 | 0 | return members; |
228 | |
} |
229 | |
|
230 | |
public void setMembers(List<DelegateMember.Builder> members) { |
231 | 0 | this.members = members; |
232 | 0 | } |
233 | |
|
234 | |
@Override |
235 | |
public boolean isActive() { |
236 | 0 | return active; |
237 | |
} |
238 | |
|
239 | |
public void setActive(Boolean active) { |
240 | 0 | this.active = active; |
241 | 0 | } |
242 | |
|
243 | |
@Override |
244 | |
public int hashCode() { |
245 | 0 | return HashCodeBuilder.reflectionHashCode(this); |
246 | |
} |
247 | |
|
248 | |
@Override |
249 | |
public boolean equals(Object obj) { |
250 | 0 | return EqualsBuilder.reflectionEquals(obj, this); |
251 | |
} |
252 | |
|
253 | |
@Override |
254 | |
public String toString() { |
255 | 0 | return ToStringBuilder.reflectionToString(this); |
256 | |
} |
257 | |
} |
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | 0 | static class Elements { |
265 | |
static final String ROLE_ID = "roleId"; |
266 | |
static final String DELEGATION_ID = "delegationId"; |
267 | |
static final String DELEGATION_TYPE_CODE = "delegationTypeCode"; |
268 | |
static final String KIM_TYPE_ID = "kimTypeId"; |
269 | |
static final String MEMBERS = "members"; |
270 | |
static final String ACTIVE = "active"; |
271 | |
} |
272 | |
|
273 | |
|
274 | |
|
275 | |
|
276 | 0 | static class Constants { |
277 | |
final static String ROOT_ELEMENT_NAME = "delegateType"; |
278 | |
final static String TYPE_NAME = "DelegateTypeType"; |
279 | |
} |
280 | |
|
281 | 0 | public static class Cache { |
282 | |
public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + DelegateType.Constants.TYPE_NAME; |
283 | |
} |
284 | |
} |