1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kim.api.common.assignee; |
18 | |
|
19 | |
import org.apache.commons.collections.CollectionUtils; |
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
22 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
23 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
24 | |
import org.kuali.rice.core.api.CoreConstants; |
25 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
26 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
27 | |
import org.kuali.rice.kim.api.common.delegate.Delegate; |
28 | |
import org.kuali.rice.kim.api.common.delegate.DelegateContract; |
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.XmlElementWrapper; |
36 | |
import javax.xml.bind.annotation.XmlRootElement; |
37 | |
import javax.xml.bind.annotation.XmlType; |
38 | |
import java.io.Serializable; |
39 | |
import java.util.ArrayList; |
40 | |
import java.util.Collection; |
41 | |
import java.util.Collections; |
42 | |
import java.util.List; |
43 | |
|
44 | |
|
45 | |
@XmlRootElement(name = Assignee.Constants.ROOT_ELEMENT_NAME) |
46 | |
@XmlAccessorType(XmlAccessType.NONE) |
47 | |
@XmlType(name = Assignee.Constants.TYPE_NAME, propOrder = { |
48 | |
Assignee.Elements.PRINCIPAL_ID, |
49 | |
Assignee.Elements.GROUP_ID, |
50 | |
Assignee.Elements.DELEGATES, |
51 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
52 | |
}) |
53 | |
public class Assignee implements AssigneeContract, ModelObjectComplete { |
54 | |
@XmlElement(name = Elements.PRINCIPAL_ID, required = false) |
55 | |
private final String principalId; |
56 | |
|
57 | |
@XmlElement(name = Elements.GROUP_ID, required = true) |
58 | |
private final String groupId; |
59 | |
|
60 | |
@XmlElementWrapper(name = Elements.DELEGATES, required = false) |
61 | |
@XmlElement(name = Elements.DELEGATE, required = false) |
62 | |
|
63 | |
private final List<Delegate> delegates; |
64 | |
|
65 | 0 | @SuppressWarnings("unused") |
66 | |
@XmlAnyElement |
67 | |
private final Collection<Element> _futureElements = null; |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | 0 | private Assignee() { |
74 | 0 | this.principalId = null; |
75 | 0 | this.groupId = null; |
76 | 0 | this.delegates = null; |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | 0 | public Assignee(Builder builder) { |
85 | 0 | this.principalId = builder.getPrincipalId(); |
86 | 0 | this.groupId = builder.getGroupId(); |
87 | 0 | final List<Delegate> temp = new ArrayList<Delegate>(); |
88 | 0 | if (!CollectionUtils.isEmpty(builder.getDelegates())) { |
89 | 0 | for (Delegate.Builder delegate: builder.getDelegates()) { |
90 | 0 | temp.add(delegate.build()); |
91 | |
} |
92 | |
} |
93 | 0 | this.delegates = Collections.unmodifiableList(temp); |
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
@Override |
100 | |
public String getPrincipalId() { |
101 | 0 | return this.principalId; |
102 | |
} |
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
@Override |
108 | |
public String getGroupId() { |
109 | 0 | return this.groupId; |
110 | |
} |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
@Override |
116 | |
public List<Delegate> getDelegates() { |
117 | 0 | return this.delegates; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public int hashCode() { |
122 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public boolean equals(Object obj) { |
127 | 0 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public String toString() { |
132 | 0 | return ToStringBuilder.reflectionToString(this); |
133 | |
} |
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | 0 | public static final class Builder implements AssigneeContract, ModelBuilder, Serializable { |
139 | |
private String principalId; |
140 | |
private String groupId; |
141 | |
private List<Delegate.Builder> delegates; |
142 | |
|
143 | 0 | private Builder(String principalId, String groupId, List<Delegate.Builder> delegates) { |
144 | 0 | setPrincipalId(principalId); |
145 | 0 | setGroupId(groupId); |
146 | 0 | setDelegates(delegates); |
147 | 0 | } |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
public static Builder create(String principalId, String groupId, List<Delegate.Builder> delegates) { |
153 | 0 | return new Builder(principalId, groupId, delegates); |
154 | |
} |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public static Builder create(AssigneeContract contract) { |
160 | 0 | final List<Delegate.Builder> builders = new ArrayList<Delegate.Builder>(); |
161 | 0 | for (DelegateContract d : contract.getDelegates()) { |
162 | 0 | builders.add(Delegate.Builder.create(d)); |
163 | |
} |
164 | |
|
165 | 0 | Builder builder = new Builder(contract.getPrincipalId(), contract.getGroupId(), builders); |
166 | 0 | return builder; |
167 | |
} |
168 | |
|
169 | |
@Override |
170 | |
public String getPrincipalId() { |
171 | 0 | return principalId; |
172 | |
} |
173 | |
|
174 | |
public void setPrincipalId(final String principalId) { |
175 | 0 | if (StringUtils.isBlank(principalId)) { |
176 | 0 | throw new IllegalArgumentException("principalId is blank"); |
177 | |
} |
178 | 0 | this.principalId = principalId; |
179 | 0 | } |
180 | |
|
181 | |
@Override |
182 | |
public String getGroupId() { |
183 | 0 | return groupId; |
184 | |
} |
185 | |
|
186 | |
public void setGroupId(final String groupId) { |
187 | 0 | if (StringUtils.isBlank(groupId)) { |
188 | 0 | throw new IllegalArgumentException("groupId is blank"); |
189 | |
} |
190 | 0 | this.groupId = groupId; |
191 | 0 | } |
192 | |
|
193 | |
@Override |
194 | |
public List<Delegate.Builder> getDelegates() { |
195 | 0 | return delegates; |
196 | |
} |
197 | |
|
198 | |
public void setDelegates(final List<Delegate.Builder> delegates) { |
199 | 0 | if (delegates == null || delegates.isEmpty()) { |
200 | 0 | throw new IllegalArgumentException("delegates is null or empty"); |
201 | |
} |
202 | 0 | this.delegates = Collections.unmodifiableList(new ArrayList<Delegate.Builder>(delegates)); |
203 | 0 | } |
204 | |
|
205 | |
@Override |
206 | |
public Assignee build() { |
207 | 0 | return new Assignee(this); |
208 | |
} |
209 | |
|
210 | |
} |
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | 0 | static class Constants { |
216 | |
final static String ROOT_ELEMENT_NAME = "assignee"; |
217 | |
final static String TYPE_NAME = "assigneeType"; |
218 | 0 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
219 | |
} |
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | 0 | static class Elements { |
226 | |
final static String PRINCIPAL_ID = "principalId"; |
227 | |
final static String GROUP_ID = "groupId"; |
228 | |
final static String DELEGATES = "delegates"; |
229 | |
final static String DELEGATE = "delegate"; |
230 | |
} |
231 | |
} |