1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kim.api.role; |
18 | |
|
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.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.io.Serializable; |
35 | |
import java.util.Collection; |
36 | |
|
37 | |
|
38 | |
@XmlRootElement(name = RolePermission.Constants.ROOT_ELEMENT_NAME) |
39 | |
@XmlAccessorType(XmlAccessType.NONE) |
40 | |
@XmlType(name = RolePermission.Constants.TYPE_NAME, propOrder = { |
41 | |
RolePermission.Elements.ID, |
42 | |
RolePermission.Elements.ROLE_ID, |
43 | |
RolePermission.Elements.PERMISSION_ID, |
44 | |
RolePermission.Elements.ACTIVE, |
45 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
46 | |
CoreConstants.CommonElements.OBJECT_ID, |
47 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
48 | |
}) |
49 | |
public class RolePermission implements RolePermissionContract, ModelObjectComplete { |
50 | |
@XmlElement(name = Elements.ID, required = false) |
51 | |
private final String id; |
52 | |
|
53 | |
@XmlElement(name = RolePermission.Elements.ROLE_ID, required = false) |
54 | |
private final String roleId; |
55 | |
|
56 | |
@XmlElement(name = RolePermission.Elements.PERMISSION_ID, required = false) |
57 | |
private final String permissionId; |
58 | |
|
59 | |
@XmlElement(name = RolePermission.Elements.ACTIVE, required = false) |
60 | |
private final boolean active; |
61 | |
|
62 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
63 | |
private final Long versionNumber; |
64 | |
|
65 | |
@XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false) |
66 | |
private final String objectId; |
67 | |
|
68 | 5 | @SuppressWarnings("unused") |
69 | |
@XmlAnyElement |
70 | |
private final Collection<Element> _futureElements = null; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | 2 | private RolePermission() { |
76 | 2 | this.id = null; |
77 | 2 | this.roleId = null; |
78 | 2 | this.permissionId = null; |
79 | 2 | this.active = false; |
80 | 2 | this.versionNumber = null; |
81 | 2 | this.objectId = null; |
82 | 2 | } |
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | 3 | public RolePermission(Builder builder) { |
90 | 3 | this.id = builder.getId(); |
91 | 3 | this.roleId = builder.getRoleId(); |
92 | 3 | this.permissionId = builder.getPermissionId(); |
93 | 3 | this.active = builder.isActive(); |
94 | 3 | this.versionNumber = builder.getVersionNumber(); |
95 | 3 | this.objectId = builder.getObjectId(); |
96 | 3 | } |
97 | |
|
98 | |
@Override |
99 | |
public String getId() { |
100 | 1 | return id; |
101 | |
} |
102 | |
|
103 | |
@Override |
104 | |
public String getPermissionId() { |
105 | 1 | return permissionId; |
106 | |
} |
107 | |
|
108 | |
@Override |
109 | |
public String getRoleId() { |
110 | 1 | return roleId; |
111 | |
} |
112 | |
|
113 | |
@Override |
114 | |
public boolean isActive() { |
115 | 1 | return active; |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public Long getVersionNumber() { |
120 | 1 | return versionNumber; |
121 | |
} |
122 | |
|
123 | |
@Override |
124 | |
public String getObjectId() { |
125 | 1 | return objectId; |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
public int hashCode() { |
130 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
131 | |
} |
132 | |
|
133 | |
@Override |
134 | |
public boolean equals(Object obj) { |
135 | 2 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
136 | |
} |
137 | |
|
138 | |
@Override |
139 | |
public String toString() { |
140 | 0 | return ToStringBuilder.reflectionToString(this); |
141 | |
} |
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | 3 | public static final class Builder implements RolePermissionContract, ModelBuilder, Serializable { |
147 | |
private String id; |
148 | |
private String roleId; |
149 | |
private String permissionId; |
150 | 4 | private Long versionNumber = 1L; |
151 | |
private String objectId; |
152 | |
private boolean active; |
153 | |
|
154 | 4 | private Builder(String id, String roleId, String permissionId) { |
155 | 4 | setId(id); |
156 | 4 | setRoleId(roleId); |
157 | 4 | setPermissionId(permissionId); |
158 | 4 | } |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
public static Builder create(String id, String roleId, String permissionId) { |
164 | 2 | return new Builder(id, roleId, permissionId); |
165 | |
} |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
public static Builder create(RolePermissionContract contract) { |
171 | 2 | Builder builder = new Builder(contract.getId(), contract.getRoleId(), contract.getPermissionId()); |
172 | 2 | builder.setActive(contract.isActive()); |
173 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
174 | 2 | builder.setObjectId(contract.getObjectId()); |
175 | |
|
176 | 2 | return builder; |
177 | |
} |
178 | |
|
179 | |
@Override |
180 | |
public String getId() { |
181 | 3 | return id; |
182 | |
} |
183 | |
|
184 | |
public void setId(final String id) { |
185 | 4 | if (StringUtils.isWhitespace(id)) { |
186 | 0 | throw new IllegalArgumentException("id is blank"); |
187 | |
} |
188 | 4 | this.id = id; |
189 | 4 | } |
190 | |
|
191 | |
@Override |
192 | |
public String getPermissionId() { |
193 | 3 | return permissionId; |
194 | |
} |
195 | |
|
196 | |
public void setPermissionId(final String permissionId) { |
197 | 4 | this.permissionId = permissionId; |
198 | 4 | } |
199 | |
|
200 | |
@Override |
201 | |
public String getRoleId() { |
202 | 3 | return roleId; |
203 | |
} |
204 | |
|
205 | |
public void setRoleId(final String roleId) { |
206 | 4 | this.roleId = roleId; |
207 | 4 | } |
208 | |
|
209 | |
@Override |
210 | |
public Long getVersionNumber() { |
211 | 3 | return versionNumber; |
212 | |
} |
213 | |
|
214 | |
public void setVersionNumber(Long versionNumber) { |
215 | 2 | if (versionNumber == null || versionNumber <= 0) { |
216 | 0 | throw new IllegalArgumentException("versionNumber is invalid"); |
217 | |
} |
218 | 2 | this.versionNumber = versionNumber; |
219 | 2 | } |
220 | |
|
221 | |
@Override |
222 | |
public String getObjectId() { |
223 | 3 | return objectId; |
224 | |
} |
225 | |
|
226 | |
public void setObjectId(final String objectId) { |
227 | 2 | this.objectId = objectId; |
228 | 2 | } |
229 | |
|
230 | |
@Override |
231 | |
public boolean isActive() { |
232 | 3 | return active; |
233 | |
} |
234 | |
|
235 | |
public void setActive(final boolean active) { |
236 | 2 | this.active = active; |
237 | 2 | } |
238 | |
|
239 | |
@Override |
240 | |
public RolePermission build() { |
241 | 3 | if (versionNumber == null || versionNumber <= 0) { |
242 | 0 | throw new IllegalStateException("versionNumber is invalid"); |
243 | |
} |
244 | 3 | if (StringUtils.isWhitespace(id)) { |
245 | 0 | throw new IllegalStateException("id is blank"); |
246 | |
} |
247 | 3 | return new RolePermission(this); |
248 | |
} |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
|
254 | 0 | static class Constants { |
255 | |
final static String ROOT_ELEMENT_NAME = "rolePermission"; |
256 | |
final static String TYPE_NAME = "RolePermissionType"; |
257 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
258 | |
} |
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | 0 | static class Elements { |
265 | |
final static String ID = "id"; |
266 | |
final static String PERMISSION_ID = "permissionId"; |
267 | |
final static String ROLE_ID = "roleId"; |
268 | |
final static String ACTIVE = "active"; |
269 | |
} |
270 | |
} |