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