View Javadoc

1   /*
2    * Copyright 2007-2008 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.bo.ui;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.LinkedHashMap;
21  import java.util.List;
22  import java.util.Map;
23  
24  import javax.persistence.Column;
25  import javax.persistence.Entity;
26  import javax.persistence.Table;
27  
28  import org.apache.log4j.Logger;
29  import org.kuali.rice.kim.bo.impl.KimAttributes;
30  import org.kuali.rice.kim.bo.impl.RoleImpl;
31  import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl;
32  import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap;
33  import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
34  import org.kuali.rice.kim.service.KIMServiceLocator;
35  import org.kuali.rice.kim.service.impl.UiDocumentServiceImpl;
36  import org.kuali.rice.kim.service.support.KimTypeService;
37  import org.kuali.rice.kim.util.KimCommonUtils;
38  import org.kuali.rice.kns.datadictionary.AttributeDefinition;
39  import org.kuali.rice.kns.util.TypedArrayList;
40  
41  /**
42   * This is a description of what this class does - shyu don't forget to fill this in. 
43   * 
44   * @author Kuali Rice Team (rice.collab@kuali.org)
45   *
46   */
47  @Entity
48  @Table(name="KRIM_PND_ROLE_MT")
49  public class PersonDocumentRole extends KimDocumentBoBase {
50      private static final Logger LOG = Logger.getLogger(PersonDocumentRole.class);
51  	private static final long serialVersionUID = 4908044213007222739L;
52  	@Column(name="ROLE_ID")
53  	protected String roleId;
54  	protected String kimTypeId;
55  	protected String roleName;
56  	protected RoleImpl roleImpl;
57  	@Column(name="NMSPC_CD")
58  	protected String namespaceCode;
59  	protected KimTypeInfo kimRoleType;
60  	protected List<? extends KimAttributes> attributes;
61  	protected transient AttributeDefinitionMap definitions;
62  	protected transient Map<String,Object> attributeEntry;
63  	protected List<KimDocumentRoleMember> rolePrncpls;
64      protected KimDocumentRoleMember newRolePrncpl;
65  	protected List<RoleResponsibilityImpl> assignedResponsibilities = new TypedArrayList(RoleResponsibilityImpl.class);
66  
67      protected boolean isEditable = true;
68      
69  	public PersonDocumentRole() {
70  		attributes = new ArrayList<KimAttributes>();	
71  		rolePrncpls = new ArrayList<KimDocumentRoleMember>();	
72  		attributeEntry = new HashMap<String,Object>();
73  	}
74  	
75  	public String getRoleId() {
76  		return this.roleId;
77  	}
78  
79  	public void setRoleId(String roleId) {
80  		this.roleId = roleId;
81  	}
82  
83  	/**
84  	 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
85  	 */
86  	@SuppressWarnings("unchecked")
87  	@Override
88  	protected LinkedHashMap toStringMapper() {
89  		LinkedHashMap m = new LinkedHashMap();
90  		m.put( "roleId", roleId );
91  		return m;
92  	}
93  
94  	public String getKimTypeId() {
95  		return this.kimTypeId;
96  	}
97  
98  	public void setKimTypeId(String kimTypeId) {
99  		this.kimTypeId = kimTypeId;
100 	}
101 
102 	public String getRoleName() {
103 		return this.roleName;
104 	}
105 
106 	public void setRoleName(String roleName) {
107 		this.roleName = roleName;
108 	}
109 
110 	public List<? extends KimAttributes> getAttributes() {
111 		return this.attributes;
112 	}
113 
114 	public void setAttributes(List<? extends KimAttributes> attributes) {
115 		this.attributes = attributes;
116 	}
117 
118 	public KimTypeInfo getKimRoleType() {
119 		if ( kimRoleType == null ) {
120 			kimRoleType = KIMServiceLocator.getTypeInfoService().getKimType(kimTypeId);
121 		}
122 		return kimRoleType;
123 	}
124 
125 	@Deprecated // for testing only
126 	public void setKimRoleType(KimTypeInfo kimRoleType) {
127 		this.kimRoleType = kimRoleType;
128 	}
129 
130 	public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() {
131 		AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions();
132 		AttributeDefinitionMap returnValue = new AttributeDefinitionMap();
133 		if (definitionsKeyedBySortCode != null) {
134 			for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) {
135 				returnValue.put(definition.getName(), definition);
136 			}
137 		}
138 		return returnValue;
139 	}
140 
141 	public AttributeDefinitionMap getDefinitions() {
142 		if (definitions == null || definitions.isEmpty()) {
143 	        KimTypeService kimTypeService = KimCommonUtils.getKimTypeService( this.getKimRoleType() );
144 	        //it is possible that the the roleTypeService is coming from a remote application 
145 	        // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
146 	        try {
147     	        if ( kimTypeService != null ) {
148     	        	definitions = kimTypeService.getAttributeDefinitions(getKimTypeId());
149     	        } else {
150     	        	definitions = new AttributeDefinitionMap();
151     	        }
152     		} catch (Exception ex) {
153                 LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Role Type: " + this.getKimRoleType(), ex);
154             }
155 		}
156 		
157 		return definitions;
158 	}
159 
160 	public void setDefinitions(AttributeDefinitionMap definitions) {
161 		this.definitions = definitions;
162 	}
163 
164 	public Map<String,Object> getAttributeEntry() {
165 		if (attributeEntry == null || attributeEntry.isEmpty()) {
166 			attributeEntry = KIMServiceLocator.getUiDocumentService().getAttributeEntries(getDefinitions());
167 		}
168 		
169 		return this.attributeEntry;
170 	}
171 
172 	public void setAttributeEntry(Map<String,Object> attributeEntry) {
173 		this.attributeEntry = attributeEntry;
174 	}
175 
176 	public List<KimDocumentRoleMember> getRolePrncpls() {
177 		return this.rolePrncpls;
178 	}
179 
180 	public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
181 		this.rolePrncpls = rolePrncpls;
182 	}
183 
184 	public KimDocumentRoleMember getNewRolePrncpl() {
185 		return this.newRolePrncpl;
186 	}
187 
188 	public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
189 		this.newRolePrncpl = newRolePrncpl;
190 	}
191 
192 	public String getNamespaceCode() {
193 		return this.namespaceCode;
194 	}
195 
196 	public void setNamespaceCode(String namespaceCode) {
197 		this.namespaceCode = namespaceCode;
198 	}
199 
200 	public List<RoleResponsibilityImpl> getAssignedResponsibilities() {
201 		return this.assignedResponsibilities;
202 	}
203 
204 	public void setAssignedResponsibilities(
205 			List<RoleResponsibilityImpl> assignedResponsibilities) {
206 		this.assignedResponsibilities = assignedResponsibilities;
207 	}
208 
209 	@Override
210 	public boolean isActive(){
211 		return this.active;
212 	}
213 
214 	/**
215 	 * @return the roleImpl
216 	 */
217 	public RoleImpl getRoleImpl() {
218 		return this.roleImpl;
219 	}
220 
221 	/**
222 	 * @param roleImpl the roleImpl to set
223 	 */
224 	public void setRoleImpl(RoleImpl roleImpl) {
225 		this.roleImpl = roleImpl;
226 	}
227 
228 	/**
229 	 * @return the isEditable
230 	 */
231 	public boolean isEditable() {
232 		return this.isEditable;
233 	}
234 
235 	/**
236 	 * @param isEditable the isEditable to set
237 	 */
238 	public void setEditable(boolean isEditable) {
239 		this.isEditable = isEditable;
240 	}
241 
242 }