1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.web.struts.form;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.membership.MemberType;
20 import org.kuali.rice.core.web.format.DateDisplayTimestampObjectFormatter;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.kim.api.type.KimType;
23 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
24 import org.kuali.rice.kim.bo.ui.KimDocumentRolePermission;
25 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
26 import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibility;
27 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
28 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
29 import org.kuali.rice.kim.document.IdentityManagementRoleDocument;
30 import org.kuali.rice.kim.impl.group.GroupBo;
31 import org.kuali.rice.kim.impl.identity.PersonImpl;
32 import org.kuali.rice.kim.impl.role.RoleBo;
33 import org.kuali.rice.kns.util.TableRenderUtil;
34
35 import java.util.List;
36
37
38
39
40
41
42
43 public class IdentityManagementRoleDocumentForm extends IdentityManagementDocumentFormBase {
44 protected static final long serialVersionUID = 7099079353241080483L;
45 {
46 requiredNonEditableProperties.add("methodToCall");
47 requiredNonEditableProperties.add("roleCommand");
48 }
49
50 protected String delegationMemberRoleMemberId;
51 protected String dmrmi;
52 protected boolean canAssignRole = true;
53 protected boolean canModifyAssignees = true;
54 protected KimType kimType;
55 protected String memberSearchValue;
56
57
58 protected String id;
59
60 protected KimDocumentRoleMember member;
61 {
62 member = new KimDocumentRoleMember();
63 member.getQualifiers().add(new KimDocumentRoleQualifier());
64
65 }
66 protected KimDocumentRolePermission permission = new KimDocumentRolePermission();
67 protected KimDocumentRoleResponsibility responsibility = new KimDocumentRoleResponsibility();
68 protected RoleDocumentDelegationMember delegationMember;
69 {
70 delegationMember = new RoleDocumentDelegationMember();
71 delegationMember.getQualifiers().add(new RoleDocumentDelegationMemberQualifier());
72 }
73 protected String roleId;
74
75
76 public IdentityManagementRoleDocumentForm() {
77 super();
78
79 setFormatterType("document.members.activeFromDate", DateDisplayTimestampObjectFormatter.class);
80 setFormatterType("document.delegationMembers.activeFromDate", DateDisplayTimestampObjectFormatter.class);
81 setFormatterType("document.members.activeToDate", DateDisplayTimestampObjectFormatter.class);
82 setFormatterType("document.delegationMembers.activeToDate", DateDisplayTimestampObjectFormatter.class);
83 }
84
85
86
87
88
89 public RoleDocumentDelegationMember getDelegationMember() {
90 return this.delegationMember;
91 }
92
93
94
95
96 public void setDelegationMember(RoleDocumentDelegationMember delegationMember) {
97 this.delegationMember = delegationMember;
98 }
99
100 @Override
101 public String getDefaultDocumentTypeName(){
102 return "IdentityManagementRoleDocument";
103 }
104
105 public IdentityManagementRoleDocument getRoleDocument() {
106 return (IdentityManagementRoleDocument) this.getDocument();
107 }
108
109
110
111
112 public KimDocumentRoleMember getMember() {
113 return this.member;
114 }
115
116
117
118
119 public void setMember(KimDocumentRoleMember member) {
120 this.member = member;
121 }
122
123 public String getId() {
124 return id;
125 }
126
127 public void setId(String id) {
128 this.id = id;
129 setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(this.id));
130 }
131
132
133
134
135 public KimDocumentRolePermission getPermission() {
136 return this.permission;
137 }
138
139
140
141
142 public void setPermission(KimDocumentRolePermission permission) {
143 this.permission = permission;
144 }
145
146
147
148
149 public KimDocumentRoleResponsibility getResponsibility() {
150 return this.responsibility;
151 }
152
153
154
155
156 public void setResponsibility(KimDocumentRoleResponsibility responsibility) {
157 this.responsibility = responsibility;
158 }
159
160 public String getMemberFieldConversions(){
161 if(member==null) {
162 return "";
163 }
164 return getMemberFieldConversions(member.getMemberTypeCode());
165 }
166
167 public String getMemberBusinessObjectName(){
168 if(member==null) {
169 return "";
170 }
171 return getMemberBusinessObjectName(member.getMemberTypeCode());
172 }
173
174 public String getDelegationMemberFieldConversions(){
175 if(getDelegationMember()==null) {
176 return "";
177 }
178 String memberTypeCode = getDelegationMember().getMemberTypeCode();
179 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
180 return "principalId:delegationMember.memberId,principalName:delegationMember.memberName";
181 }
182 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
183 return "id:delegationMember.memberId,name:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
184 }
185 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
186 return "id:delegationMember.memberId,name:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
187 }
188 return "";
189 }
190
191 public String getDelegationMemberBusinessObjectName(){
192 if(getDelegationMember()==null) {
193 return "";
194 }
195 return getMemberBusinessObjectName(getDelegationMember().getMemberTypeCode());
196 }
197
198 protected String getMemberFieldConversions(String memberTypeCode){
199 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
200 return "principalId:member.memberId,principalName:member.memberName";
201 }
202 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
203 return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode";
204 }
205 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
206 return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode";
207 }
208 return "";
209 }
210
211 protected String getMemberBusinessObjectName(String memberTypeCode){
212 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
213 return PersonImpl.class.getName();
214 }
215 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
216 return RoleBo.class.getName();
217 }
218 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
219 return GroupBo.class.getName();
220 }
221 return "";
222 }
223
224
225
226
227 public KimType getKimType() {
228 return this.kimType;
229 }
230
231
232
233
234 public void setKimType(KimType kimType) {
235 this.kimType = kimType;
236 if ( kimType != null && getRoleDocument() != null ) {
237 getRoleDocument().setKimType(kimType);
238 }
239 }
240
241
242
243
244 public boolean isCanAssignRole() {
245 return this.canAssignRole;
246 }
247
248
249
250
251 public void setCanAssignRole(boolean canAssignRole) {
252 this.canAssignRole = canAssignRole;
253 }
254
255
256
257
258 public boolean isCanModifyAssignees() {
259 return this.canModifyAssignees;
260 }
261
262
263
264
265 public void setCanModifyAssignees(boolean canModifyAssignees) {
266 this.canModifyAssignees = canModifyAssignees;
267 }
268
269 public List<KimDocumentRoleMember> getMemberRows() {
270 return getRoleDocument().getMembers();
271 }
272
273 public int getIndexOfRoleMemberFromMemberRows(String roleMemberId){
274 int index = 0;
275 for(KimDocumentRoleMember roleMember: getMemberRows()){
276 if(StringUtils.equals(roleMember.getRoleMemberId(), roleMemberId)){
277 break;
278 }
279 index++;
280 }
281 return index;
282 }
283
284 public int getPageNumberOfRoleMemberId(String roleMemberId){
285 if(StringUtils.isEmpty(roleMemberId)) {return 1;}
286 int index = getIndexOfRoleMemberFromMemberRows(roleMemberId);
287 return TableRenderUtil.computeTotalNumberOfPages(index + 1, getRecordsPerPage())-1;
288 }
289
290
291
292
293 public String getRoleId() {
294 return this.roleId;
295 }
296
297
298
299
300 public void setRoleId(String roleId) {
301 this.roleId = roleId;
302 }
303
304
305
306
307 public String getDelegationMemberRoleMemberId() {
308 return this.delegationMemberRoleMemberId;
309 }
310
311
312
313
314 public void setDelegationMemberRoleMemberId(String delegationMemberRoleMemberId) {
315 this.delegationMemberRoleMemberId = delegationMemberRoleMemberId;
316 getDelegationMember().setRoleMemberId(delegationMemberRoleMemberId);
317 KimDocumentRoleMember roleMember = getRoleDocument().getMember(delegationMemberRoleMemberId);
318 if(roleMember!=null){
319 delegationMember.setRoleMemberId(roleMember.getRoleMemberId());
320 delegationMember.setRoleMemberName(roleMember.getMemberName());
321 delegationMember.setRoleMemberNamespaceCode(roleMember.getMemberNamespaceCode());
322 RoleDocumentDelegationMemberQualifier delegationMemberQualifier;
323 for(KimDocumentRoleQualifier roleQualifier: roleMember.getQualifiers()){
324 delegationMemberQualifier = getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId());
325 delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal());
326 }
327 }
328 }
329
330
331
332
333 public String getDmrmi() {
334 return this.dmrmi;
335 }
336
337
338
339
340 public void setDmrmi(String dmrmi) {
341 this.dmrmi = dmrmi;
342 }
343
344
345
346
347 public String getMemberSearchValue() {
348 return this.memberSearchValue;
349 }
350
351
352
353
354 public void setMemberSearchValue(String memberSearchValue) {
355 this.memberSearchValue = memberSearchValue;
356 }
357
358 }