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