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 import java.util.ArrayList;
20 import java.util.List;
21
22 import javax.xml.bind.Marshaller;
23 import javax.xml.bind.UnmarshalException;
24 import javax.xml.bind.Unmarshaller;
25 import javax.xml.bind.annotation.XmlAccessType;
26 import javax.xml.bind.annotation.XmlAccessorType;
27 import javax.xml.bind.annotation.XmlElement;
28 import javax.xml.bind.annotation.XmlTransient;
29 import javax.xml.bind.annotation.XmlType;
30
31 import org.kuali.rice.core.util.jaxb.RiceXmlExportList;
32 import org.kuali.rice.core.util.jaxb.RiceXmlImportList;
33 import org.kuali.rice.core.util.jaxb.RiceXmlListAdditionListener;
34 import org.kuali.rice.core.util.jaxb.RiceXmlListGetterListener;
35 import org.kuali.rice.kim.api.permission.PermissionContract;
36 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
37
38
39
40
41
42
43
44
45
46
47 @XmlTransient
48 public abstract class RolePermissionsXmlDTO<T extends RolePermissionXmlDTO> implements RiceXmlListAdditionListener<T>, Serializable {
49
50 private static final long serialVersionUID = 1L;
51
52 public abstract List<T> getRolePermissions();
53
54 public abstract void setRolePermissions(List<T> rolePermissions);
55
56 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
57 setRolePermissions(new RiceXmlImportList<T>(this));
58 }
59
60 void afterUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
61 setRolePermissions(null);
62 }
63
64
65
66
67
68
69
70
71 @XmlAccessorType(XmlAccessType.FIELD)
72 @XmlType(name="StandaloneRolePermissionsType", propOrder={"rolePermissions"})
73 public static class OutsideOfRole extends RolePermissionsXmlDTO<RolePermissionXmlDTO.OutsideOfRole> {
74
75 private static final long serialVersionUID = 1L;
76
77 @XmlElement(name="rolePermission")
78 private List<RolePermissionXmlDTO.OutsideOfRole> rolePermissions;
79
80 public List<RolePermissionXmlDTO.OutsideOfRole> getRolePermissions() {
81 return rolePermissions;
82 }
83
84 public void setRolePermissions(List<RolePermissionXmlDTO.OutsideOfRole> rolePermissions) {
85 this.rolePermissions = rolePermissions;
86 }
87
88 public void newItemAdded(RolePermissionXmlDTO.OutsideOfRole item) {
89 try {
90 RoleXmlUtil.validateAndPersistNewRolePermission(item);
91 } catch (UnmarshalException e) {
92 throw new RuntimeException(e);
93 }
94 }
95
96 }
97
98
99
100
101
102
103
104
105 @XmlAccessorType(XmlAccessType.FIELD)
106 @XmlType(name="RolePermissionsType", propOrder={"rolePermissions"})
107 public static class WithinRole extends RolePermissionsXmlDTO<RolePermissionXmlDTO.WithinRole>
108 implements RiceXmlListGetterListener<RolePermissionXmlDTO.WithinRole,String> {
109
110 private static final long serialVersionUID = 1L;
111
112 @XmlElement(name="rolePermission")
113 private List<RolePermissionXmlDTO.WithinRole> rolePermissions;
114
115 @XmlTransient
116 private String roleId;
117
118 public WithinRole() {}
119
120 public WithinRole(String roleId) {
121 this.roleId = roleId;
122 }
123
124 public List<RolePermissionXmlDTO.WithinRole> getRolePermissions() {
125 return rolePermissions;
126 }
127
128 public void setRolePermissions(List<RolePermissionXmlDTO.WithinRole> rolePermissions) {
129 this.rolePermissions = rolePermissions;
130 }
131
132 public String getRoleId() {
133 return roleId;
134 }
135
136 @Override
137 void beforeUnmarshal(Unmarshaller unmarshaller, Object parent) throws UnmarshalException {
138 if (parent instanceof RoleXmlDTO) {
139
140 RoleXmlDTO parentRole = (RoleXmlDTO) parent;
141 if (!parentRole.isAlreadyPersisted()) {
142 RoleXmlUtil.validateAndPersistNewRole(parentRole);
143 }
144 roleId = parentRole.getRoleId();
145 }
146 super.beforeUnmarshal(unmarshaller, parent);
147 }
148
149 public void newItemAdded(RolePermissionXmlDTO.WithinRole item) {
150 try {
151 RoleXmlUtil.validateAndPersistNewRolePermission(item);
152 } catch (UnmarshalException e) {
153 throw new RuntimeException(e);
154 }
155 }
156
157 void beforeMarshal(Marshaller marshaller) {
158
159 List<String> permissionIds = new ArrayList<String>();
160 if (permissionIds != null && !permissionIds.isEmpty()) {
161 setRolePermissions(new RiceXmlExportList<RolePermissionXmlDTO.WithinRole,String>(permissionIds, this));
162 }
163 }
164
165 void afterMarshal(Marshaller marshaller) {
166 setRolePermissions(null);
167 }
168
169 public RolePermissionXmlDTO.WithinRole gettingNextItem(String nextItem, int index) {
170 PermissionContract permission = KimApiServiceLocator.getPermissionService().getPermission(nextItem);
171 if (permission == null) {
172 throw new RuntimeException("Cannot find permission with ID \"" + nextItem + "\"");
173 }
174 return new RolePermissionXmlDTO.WithinRole(permission, false);
175 }
176 }
177 }