View Javadoc

1   /*
2    * Copyright 2007-2009 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.web.format.DateDisplayTimestampObjectFormatter;
20  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
21  import org.kuali.rice.kim.api.type.KimType;
22  import org.kuali.rice.kim.bo.impl.PersonImpl;
23  import org.kuali.rice.kim.impl.role.RoleBo;
24  import org.kuali.rice.kim.bo.ui.GroupDocumentMember;
25  import org.kuali.rice.kim.document.IdentityManagementGroupDocument;
26  import org.kuali.rice.kim.impl.group.GroupBo;
27  import org.kuali.rice.kim.impl.type.KimTypeBo;
28  import org.kuali.rice.kim.util.KimConstants;
29  
30  import java.util.List;
31  
32  /**
33   * This is a description of what this class does - shyu don't forget to fill this in. 
34   * 
35   * @author Kuali Rice Team (rice.collab@kuali.org)
36   *
37   */
38  public class IdentityManagementGroupDocumentForm extends IdentityManagementDocumentFormBase {
39  	protected static final long serialVersionUID = -107836689162363400L;
40  	
41  	{
42  		requiredNonEditableProperties.add("methodToCall");
43  	}
44  	
45  	protected boolean canAssignGroup = true;
46  	
47  	protected KimType kimType;
48  	protected GroupDocumentMember member = new GroupDocumentMember();
49  	protected String groupId;
50      
51  	public IdentityManagementGroupDocumentForm() {
52          super();
53          setFormatterType("document.members.activeFromDate", DateDisplayTimestampObjectFormatter.class);
54          setFormatterType("document.members.activeToDate", DateDisplayTimestampObjectFormatter.class);
55      }
56  
57  	@Override
58  	public String getDefaultDocumentTypeName(){
59  		return "IdentityManagementGroupDocument";
60  	}
61  	
62  	public IdentityManagementGroupDocument getGroupDocument() {
63          return (IdentityManagementGroupDocument) this.getDocument();
64      }
65  
66  	public String getMemberFieldConversions(){
67  		if(member==null) {
68  			return "";
69  		}
70  		return getMemberFieldConversions(member.getMemberTypeCode());
71  	}
72  
73  	public String getMemberBusinessObjectName(){
74  		if(member==null) {
75  			return "";
76  		}
77  		return getMemberBusinessObjectName(member.getMemberTypeCode());
78  	}
79  
80  	protected String getMemberFieldConversions(String memberTypeCode){
81  		if(KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(memberTypeCode)) {
82  			return "principalId:member.memberId,principalName:member.memberName";
83          }
84  		else if(KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)) {
85  			return "roleId:member.memberId,roleName:member.memberName";
86          }
87  		else if(KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)) {
88  			return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode";
89          }
90  		return "";
91  	}
92  
93  	protected String getMemberBusinessObjectName(String memberTypeCode){
94  		if(KimConstants.KimUIConstants.MEMBER_TYPE_PRINCIPAL_CODE.equals(memberTypeCode)) {
95  			return PersonImpl.class.getName();
96          }
97  		else if(KimConstants.KimUIConstants.MEMBER_TYPE_ROLE_CODE.equals(memberTypeCode)) {
98  			return RoleBo.class.getName();
99          }
100 		else if(KimConstants.KimUIConstants.MEMBER_TYPE_GROUP_CODE.equals(memberTypeCode)) {
101 			return GroupBo.class.getName();
102         }
103 		return "";
104 	}
105 
106 	/**
107 	 * @return the kimType
108 	 */
109 	public KimType getKimType() {
110 		if(StringUtils.isNotBlank(getGroupDocument().getGroupTypeId())) {
111 			return KimApiServiceLocator.getKimTypeInfoService().getKimType(getGroupDocument().getGroupTypeId());
112         }
113 		else {return kimType;}
114 	}
115 
116 	public String getKimTypeClass(){
117 		return KimTypeBo.class.getName();
118 	}
119 	/**
120 	 * @return the canAssignGroup
121 	 */
122 	public boolean isCanAssignGroup() {
123 		return this.canAssignGroup;
124 	}
125 
126 	/**
127 	 * @param canAssignGroup the canAssignGroup to set
128 	 */
129 	public void setCanAssignGroup(boolean canAssignGroup) {
130 		this.canAssignGroup = canAssignGroup;
131 	}
132 
133 	/**
134 	 * @return the member
135 	 */
136 	public GroupDocumentMember getMember() {
137 		return this.member;
138 	}
139 
140 	/**
141 	 * @param member the member to set
142 	 */
143 	public void setMember(GroupDocumentMember member) {
144 		this.member = member;
145 	}
146 	
147 	/**
148 	 * This overridden method ...
149 	 * 
150 	 * @see org.kuali.rice.kim.web.struts.form.IdentityManagementDocumentFormBase#getMemberRows()
151 	 */
152 	@SuppressWarnings("unchecked")
153 	@Override
154 	public List getMemberRows() {
155 		return getGroupDocument().getMembers();
156 	}
157 
158 	/**
159 	 * @return the groupId
160 	 */
161 	public String getGroupId() {
162 		return this.groupId;
163 	}
164 
165 	/**
166 	 * @param groupId the groupId to set
167 	 */
168 	public void setGroupId(String groupId) {
169 		this.groupId = groupId;
170 	}
171 
172 	/**
173 	 * @param kimType the kimType to set
174 	 */
175 	public void setKimType(KimType kimType) {
176 		this.kimType = kimType;
177 	}
178 
179 }