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