View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * This is a description of what this class does - shyu don't forget to fill this in. 
39   * 
40   * @author Kuali Rice Team (rice.collab@kuali.org)
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  
56      //kim type id
57      protected String id;
58  
59  	protected KimDocumentRoleMember member;
60  	{
61  		member = new KimDocumentRoleMember();
62  		member.getQualifiers().add(new KimDocumentRoleQualifier());
63  
64  	}
65  	protected KimDocumentRolePermission permission = new KimDocumentRolePermission();
66      protected KimDocumentRoleResponsibility responsibility = new KimDocumentRoleResponsibility();
67      protected RoleDocumentDelegationMember delegationMember;
68  	{
69  		delegationMember = new RoleDocumentDelegationMember();
70  		delegationMember.getQualifiers().add(new RoleDocumentDelegationMemberQualifier());
71  	}
72  	protected String roleId;
73  
74  
75  	public IdentityManagementRoleDocumentForm() {
76          super();
77  
78          setFormatterType("document.members.activeFromDate", DateDisplayTimestampObjectFormatter.class);
79          setFormatterType("document.delegationMembers.activeFromDate", DateDisplayTimestampObjectFormatter.class);
80          setFormatterType("document.members.activeToDate", DateDisplayTimestampObjectFormatter.class);
81          setFormatterType("document.delegationMembers.activeToDate", DateDisplayTimestampObjectFormatter.class);
82      }
83  
84  	
85      /**
86  	 * @return the delegationMember
87  	 */
88  	public RoleDocumentDelegationMember getDelegationMember() {
89  		return this.delegationMember;
90  	}
91  
92  	/**
93  	 * @param delegationMember the delegationMember to set
94  	 */
95  	public void setDelegationMember(RoleDocumentDelegationMember delegationMember) {
96  		this.delegationMember = delegationMember;
97  	}
98  
99  	@Override
100 	public String getDefaultDocumentTypeName(){
101 		return "IdentityManagementRoleDocument";
102 	}
103 	
104 	public IdentityManagementRoleDocument getRoleDocument() {
105         return (IdentityManagementRoleDocument) this.getDocument();
106     }
107 
108 	/**
109 	 * @return the member
110 	 */
111 	public KimDocumentRoleMember getMember() {
112 		return this.member;
113 	}
114 
115 	/**
116 	 * @param member the member to set
117 	 */
118 	public void setMember(KimDocumentRoleMember member) {
119 		this.member = member;
120 	}
121 
122     public String getId() {
123         return id;
124     }
125 
126     public void setId(String id) {
127         this.id = id;
128         setKimType(KimApiServiceLocator.getKimTypeInfoService().getKimType(this.id));
129     }
130 
131 	/**
132 	 * @return the permission
133 	 */
134 	public KimDocumentRolePermission getPermission() {
135 		return this.permission;
136 	}
137 
138 	/**
139 	 * @param permission the permission to set
140 	 */
141 	public void setPermission(KimDocumentRolePermission permission) {
142 		this.permission = permission;
143 	}
144 
145 	/**
146 	 * @return the responsibility
147 	 */
148 	public KimDocumentRoleResponsibility getResponsibility() {
149 		return this.responsibility;
150 	}
151 
152 	/**
153 	 * @param responsibility the responsibility to set
154 	 */
155 	public void setResponsibility(KimDocumentRoleResponsibility responsibility) {
156 		this.responsibility = responsibility;
157 	}
158 
159 	public String getMemberFieldConversions(){
160 		if(member==null) {
161 			return "";
162         }
163 		return getMemberFieldConversions(member.getMemberTypeCode());
164 	}
165 
166 	public String getMemberBusinessObjectName(){
167 		if(member==null) {
168 			return "";
169         }
170 		return getMemberBusinessObjectName(member.getMemberTypeCode());
171 	}
172 
173 	public String getDelegationMemberFieldConversions(){
174 		if(getDelegationMember()==null) {
175 			return "";
176         }
177 		String memberTypeCode = getDelegationMember().getMemberTypeCode();
178 		if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
179 			return "principalId:delegationMember.memberId,principalName:delegationMember.memberName";
180         }
181 		else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
182 			return "id:delegationMember.memberId,name:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
183         }
184 		else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
185 			return "id:delegationMember.memberId,name:delegationMember.memberName,namespaceCode:delegationMember.memberNamespaceCode";
186         }
187 		return "";
188 	}
189 
190 	public String getDelegationMemberBusinessObjectName(){
191 		if(getDelegationMember()==null) {
192 			return "";
193         }
194 		return getMemberBusinessObjectName(getDelegationMember().getMemberTypeCode());
195 	}
196 
197 	protected String getMemberFieldConversions(String memberTypeCode){
198 		if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
199 			return "principalId:member.memberId,principalName:member.memberName";
200         }
201 		else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
202 			return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode";
203         }
204 		else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
205 			return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode";
206         }
207 		return "";
208 	}
209 
210 	protected String getMemberBusinessObjectName(String memberTypeCode){
211 		if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
212 			return PersonImpl.class.getName();
213         }
214 		else if(MemberType.ROLE.getCode().equals(memberTypeCode)) {
215 			return RoleBo.class.getName();
216         }
217 		else if(MemberType.GROUP.getCode().equals(memberTypeCode)) {
218 			return GroupBo.class.getName();
219         }
220 		return "";
221 	}
222 
223 	/**
224 	 * @return the kimType
225 	 */
226 	public KimType getKimType() {
227 		return this.kimType;
228 	}
229 
230 	/**
231 	 * @param kimType the kimType to set
232 	 */
233 	public void setKimType(KimType kimType) {
234 		this.kimType = kimType;
235 		if ( kimType != null && getRoleDocument() != null ) {
236 			getRoleDocument().setKimType(kimType);
237 		}
238 	}
239 
240 	/**
241 	 * @return the canAssignRole
242 	 */
243 	public boolean isCanAssignRole() {
244 		return this.canAssignRole;
245 	}
246 
247 	/**
248 	 * @param canAssignRole the canAssignRole to set
249 	 */
250 	public void setCanAssignRole(boolean canAssignRole) {
251 		this.canAssignRole = canAssignRole;
252 	}
253 
254 	/**
255 	 * @return the canModifyAssignees
256 	 */
257 	public boolean isCanModifyAssignees() {
258 		return this.canModifyAssignees;
259 	}
260 
261 	/**
262 	 * @param canModifyAssignees the canModifyAssignees to set
263 	 */
264 	public void setCanModifyAssignees(boolean canModifyAssignees) {
265 		this.canModifyAssignees = canModifyAssignees;
266 	}
267 	
268 	public List<KimDocumentRoleMember> getMemberRows() {
269 		return getRoleDocument().getMembers();
270 	}
271 
272 	public int getIndexOfRoleMemberFromMemberRows(String roleMemberId){
273 		int index = 0;
274 		for(KimDocumentRoleMember roleMember: getMemberRows()){
275 			if(StringUtils.equals(roleMember.getRoleMemberId(), roleMemberId)){
276 				break;
277 			}
278 			index++;
279 		}
280 		return index;
281 	}
282 
283 	public int getPageNumberOfRoleMemberId(String roleMemberId){
284 		if(StringUtils.isEmpty(roleMemberId)) {return 1;}
285 		int index = getIndexOfRoleMemberFromMemberRows(roleMemberId);
286 		return TableRenderUtil.computeTotalNumberOfPages(index + 1, getRecordsPerPage())-1;
287 	}
288 	
289 	/**
290 	 * @return the roleId
291 	 */
292 	public String getRoleId() {
293 		return this.roleId;
294 	}
295 
296 	/**
297 	 * @param roleId the roleId to set
298 	 */
299 	public void setRoleId(String roleId) {
300 		this.roleId = roleId;
301 	}
302 
303 	/**
304 	 * @return the delegationMemberRoleMemberId
305 	 */
306 	public String getDelegationMemberRoleMemberId() {
307 		return this.delegationMemberRoleMemberId;
308 	}
309 
310 	/**
311 	 * @param delegationMemberRoleMemberId the delegationMemberRoleMemberId to set
312 	 */
313 	public void setDelegationMemberRoleMemberId(String delegationMemberRoleMemberId) {
314 		this.delegationMemberRoleMemberId = delegationMemberRoleMemberId;
315 		getDelegationMember().setRoleMemberId(delegationMemberRoleMemberId);
316 		KimDocumentRoleMember roleMember = getRoleDocument().getMember(delegationMemberRoleMemberId);
317 		if(roleMember!=null){
318 			delegationMember.setRoleMemberId(roleMember.getRoleMemberId());
319 			delegationMember.setRoleMemberName(roleMember.getMemberName());
320 			delegationMember.setRoleMemberNamespaceCode(roleMember.getMemberNamespaceCode());
321 			RoleDocumentDelegationMemberQualifier delegationMemberQualifier;
322 			for(KimDocumentRoleQualifier roleQualifier: roleMember.getQualifiers()){
323 				delegationMemberQualifier = getDelegationMember().getQualifier(roleQualifier.getKimAttrDefnId());
324 				delegationMemberQualifier.setAttrVal(roleQualifier.getAttrVal());
325 			}
326 		}
327 	}
328 
329 	/**
330 	 * @return the dmrmi
331 	 */
332 	public String getDmrmi() {
333 		return this.dmrmi;
334 	}
335 
336 	/**
337 	 * @param dmrmi the dmrmi to set
338 	 */
339 	public void setDmrmi(String dmrmi) {
340 		this.dmrmi = dmrmi;
341 	}
342 
343 }