1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.jaxb;
17
18 import java.io.Serializable;
19
20 import javax.xml.bind.Unmarshaller;
21 import javax.xml.bind.annotation.XmlAccessType;
22 import javax.xml.bind.annotation.XmlAccessorType;
23 import javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlTransient;
25 import javax.xml.bind.annotation.XmlType;
26 import javax.xml.bind.annotation.adapters.NormalizedStringAdapter;
27 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
28
29 import org.kuali.rice.core.util.jaxb.NameAndNamespacePair;
30 import org.kuali.rice.core.util.jaxb.NameAndNamespacePairValidatingAdapter;
31 import org.kuali.rice.kim.api.permission.PermissionContract;
32 import org.kuali.rice.kim.api.role.RoleContract;
33 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
34
35
36
37
38
39
40
41
42 @XmlTransient
43 public abstract class RolePermissionXmlDTO implements Serializable {
44
45 private static final long serialVersionUID = 1L;
46
47 @XmlElement(name="permissionId")
48 @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
49 private String permissionId;
50
51 @XmlElement(name="permissionName")
52 @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
53 private NameAndNamespacePair permissionNameAndNamespace;
54
55
56
57
58 public RolePermissionXmlDTO() {}
59
60
61
62
63
64
65
66 public RolePermissionXmlDTO(PermissionContract permission, boolean populateIds) {
67 if (permission == null) {
68 throw new IllegalArgumentException("Cannot construct a role permission with a null permission");
69 }
70 if (populateIds) {
71 this.permissionId = permission.getId();
72 }
73 this.permissionNameAndNamespace = new NameAndNamespacePair(permission.getNamespaceCode(), permission.getName());
74 }
75
76
77
78
79 public String getPermissionId() {
80 return this.permissionId;
81 }
82
83
84
85
86 public void setPermissionId(String permissionId) {
87 this.permissionId = permissionId;
88 }
89
90
91
92
93 public NameAndNamespacePair getPermissionNameAndNamespace() {
94 return this.permissionNameAndNamespace;
95 }
96
97
98
99
100 public void setPermissionNameAndNamespace(NameAndNamespacePair permissionNameAndNamespace) {
101 this.permissionNameAndNamespace = permissionNameAndNamespace;
102 }
103
104
105
106
107
108
109 public String getPermissionName() {
110 return (permissionNameAndNamespace != null) ? permissionNameAndNamespace.getName() : null;
111 }
112
113
114
115
116
117
118 public String getPermissionNamespaceCode() {
119 return (permissionNameAndNamespace != null) ? permissionNameAndNamespace.getNamespaceCode() : null;
120 }
121
122
123
124
125
126
127
128 public abstract String getRoleId();
129
130
131
132
133
134
135
136
137 @XmlAccessorType(XmlAccessType.FIELD)
138 @XmlType(name="StandaloneRolePermissionType", propOrder={
139 "roleId", "roleNameAndNamespace", "permissionId", "permissionNameAndNamespace"
140 })
141 public static class OutsideOfRole extends RolePermissionXmlDTO {
142
143 private static final long serialVersionUID = 1L;
144
145 @XmlElement(name="roleId")
146 @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
147 private String roleId;
148
149 @XmlElement(name="roleName")
150 @XmlJavaTypeAdapter(NameAndNamespacePairValidatingAdapter.class)
151 private NameAndNamespacePair roleNameAndNamespace;
152
153 public OutsideOfRole() {
154 super();
155 }
156
157 public OutsideOfRole(PermissionContract permission, String roleId, boolean populateIds) {
158 super(permission, populateIds);
159 if (populateIds) {
160 this.roleId = roleId;
161 }
162 RoleContract tempRole = KimApiServiceLocator.getRoleService().getRole(roleId);
163 if (tempRole == null) {
164 throw new IllegalArgumentException("Cannot find role with ID \"" + roleId + "\"");
165 }
166 this.roleNameAndNamespace = new NameAndNamespacePair(tempRole.getNamespaceCode(), tempRole.getName());
167 }
168
169
170
171
172 @Override
173 public String getRoleId() {
174 return this.roleId;
175 }
176
177
178
179
180 public void setRoleId(String roleId) {
181 this.roleId = roleId;
182 }
183
184
185
186
187 public NameAndNamespacePair getRoleNameAndNamespace() {
188 return this.roleNameAndNamespace;
189 }
190
191
192
193
194 public void setRoleNameAndNamespace(NameAndNamespacePair roleNameAndNamespace) {
195 this.roleNameAndNamespace = roleNameAndNamespace;
196 }
197
198
199
200
201
202
203 public String getRoleName() {
204 return (roleNameAndNamespace != null) ? roleNameAndNamespace.getName() : null;
205 }
206
207
208
209
210
211
212 public String getRoleNamespaceCode() {
213 return (roleNameAndNamespace != null) ? roleNameAndNamespace.getNamespaceCode() : null;
214 }
215 }
216
217
218
219
220
221
222
223
224 @XmlAccessorType(XmlAccessType.FIELD)
225 @XmlType(name="RolePermissionType", propOrder={
226 "permissionId", "permissionNameAndNamespace"
227 })
228 public static class WithinRole extends RolePermissionXmlDTO {
229
230 private static final long serialVersionUID = 1L;
231
232 @XmlTransient
233 private String roleId;
234
235 public WithinRole() {
236 super();
237 }
238
239 public WithinRole(PermissionContract permission, boolean populateIds) {
240 super(permission, populateIds);
241 }
242
243 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) {
244 if (parent instanceof RolePermissionsXmlDTO) {
245 this.roleId = ((RolePermissionXmlDTO)parent).getRoleId();
246 }
247 }
248
249
250
251
252 @Override
253 public String getRoleId() {
254 return this.roleId;
255 }
256 }
257 }