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