001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.web.struts.form; 017 018import org.apache.commons.lang.StringUtils; 019import org.kuali.rice.core.api.membership.MemberType; 020import org.kuali.rice.core.web.format.DateDisplayTimestampObjectFormatter; 021import org.kuali.rice.kim.api.KimConstants; 022import org.kuali.rice.kim.api.services.KimApiServiceLocator; 023import org.kuali.rice.kim.api.type.KimType; 024import org.kuali.rice.kim.bo.ui.GroupDocumentMember; 025import org.kuali.rice.kim.document.IdentityManagementGroupDocument; 026import org.kuali.rice.kim.impl.group.GroupBo; 027import org.kuali.rice.kim.impl.identity.PersonImpl; 028import org.kuali.rice.kim.impl.role.RoleBo; 029import org.kuali.rice.kim.impl.type.KimTypeBo; 030 031import java.util.List; 032 033/** 034 * This is a description of what this class does - shyu don't forget to fill this in. 035 * 036 * @author Kuali Rice Team (rice.collab@kuali.org) 037 * 038 */ 039public class IdentityManagementGroupDocumentForm extends IdentityManagementDocumentFormBase { 040 protected static final long serialVersionUID = -107836689162363400L; 041 042 { 043 requiredNonEditableProperties.add("methodToCall"); 044 } 045 046 protected boolean canAssignGroup = true; 047 048 protected KimType kimType; 049 protected GroupDocumentMember member = new GroupDocumentMember(); 050 protected String groupId; 051 052 public IdentityManagementGroupDocumentForm() { 053 super(); 054 setFormatterType("document.members.activeFromDate", DateDisplayTimestampObjectFormatter.class); 055 setFormatterType("document.members.activeToDate", DateDisplayTimestampObjectFormatter.class); 056 } 057 058 @Override 059 public String getDefaultDocumentTypeName(){ 060 return "IdentityManagementGroupDocument"; 061 } 062 063 public IdentityManagementGroupDocument getGroupDocument() { 064 return (IdentityManagementGroupDocument) this.getDocument(); 065 } 066 067 public String getMemberFieldConversions(){ 068 if(member==null) { 069 return ""; 070 } 071 return getMemberFieldConversions(member.getMemberTypeCode()); 072 } 073 074 public String getMemberBusinessObjectName(){ 075 if(member==null) { 076 return ""; 077 } 078 return getMemberBusinessObjectName(member.getMemberTypeCode()); 079 } 080 081 protected String getMemberFieldConversions(String memberTypeCode){ 082 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { 083 return "principalId:member.memberId,principalName:member.memberName"; 084 } 085 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) { 086 return "id:member.memberId,name:member.memberName"; 087 } 088 else if(MemberType.GROUP.getCode().equals(memberTypeCode)) { 089 return "id:member.memberId,name:member.memberName,namespaceCode:member.memberNamespaceCode"; 090 } 091 return ""; 092 } 093 094 protected String getMemberBusinessObjectName(String memberTypeCode){ 095 if(MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { 096 return PersonImpl.class.getName(); 097 } 098 else if(MemberType.ROLE.getCode().equals(memberTypeCode)) { 099 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}