Coverage Report - org.kuali.rice.kim.bo.ui.PersonDocumentRole
 
Classes in this File Line Coverage Branch Coverage Complexity
PersonDocumentRole
0%
0/63
0%
0/16
1.333
 
 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 org.apache.log4j.Logger;
 19  
 import org.hibernate.annotations.Fetch;
 20  
 import org.hibernate.annotations.FetchMode;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 22  
 import org.kuali.rice.kim.bo.impl.KimAttributes;
 23  
 import org.kuali.rice.kim.bo.impl.RoleImpl;
 24  
 import org.kuali.rice.kim.bo.role.impl.RoleResponsibilityImpl;
 25  
 import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap;
 26  
 import org.kuali.rice.kim.impl.type.KimTypeBo;
 27  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 28  
 import org.kuali.rice.kim.service.KIMServiceLocatorWeb;
 29  
 import org.kuali.rice.kim.service.support.KimTypeService;
 30  
 import org.kuali.rice.kns.datadictionary.AttributeDefinition;
 31  
 import org.springframework.util.AutoPopulatingList;
 32  
 
 33  
 import javax.persistence.CascadeType;
 34  
 import javax.persistence.Column;
 35  
 import javax.persistence.Entity;
 36  
 import javax.persistence.FetchType;
 37  
 import javax.persistence.Id;
 38  
 import javax.persistence.IdClass;
 39  
 import javax.persistence.JoinColumn;
 40  
 import javax.persistence.JoinColumns;
 41  
 import javax.persistence.ManyToMany;
 42  
 import javax.persistence.OneToMany;
 43  
 import javax.persistence.Table;
 44  
 import javax.persistence.Transient;
 45  
 import javax.persistence.UniqueConstraint;
 46  
 import java.util.ArrayList;
 47  
 import java.util.HashMap;
 48  
 import java.util.List;
 49  
 import java.util.Map;
 50  
 
 51  
 /**
 52  
  * This is a description of what this class does - shyu don't forget to fill this in. 
 53  
  * 
 54  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 55  
  *
 56  
  */
 57  
 
 58  
 @Entity
 59  
 @IdClass(org.kuali.rice.kim.bo.ui.PersonDocumentRoleId.class)
 60  
 @Table(name="KRIM_PND_ROLE_MT",uniqueConstraints=@UniqueConstraint(columnNames={"FDOC_NBR", "ROLE_ID"}))
 61  
 public class PersonDocumentRole extends KimDocumentBoActivatableEditableBase {
 62  0
     private static final Logger LOG = Logger.getLogger(PersonDocumentRole.class);
 63  
         private static final long serialVersionUID = 4908044213007222739L;
 64  
         @Id
 65  
         @Column(name="ROLE_ID")
 66  
         protected String roleId;
 67  
         @Column(name="KIM_TYP_ID")
 68  
         protected String kimTypeId;
 69  
         @Column(name="ROLE_NM")
 70  
         protected String roleName;
 71  
         @Transient
 72  
         protected RoleImpl roleImpl;
 73  
         @Column(name="NMSPC_CD")
 74  
         protected String namespaceCode;
 75  
         @Transient
 76  
         protected KimTypeBo kimRoleType;
 77  
         @Transient
 78  
         protected List<? extends KimAttributes> attributes;
 79  
         @Transient
 80  
         protected transient AttributeDefinitionMap definitions;
 81  
         @Transient
 82  
         protected transient Map<String,Object> attributeEntry;
 83  
         @OneToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 84  
     @Fetch(value = FetchMode.SELECT)
 85  
         @JoinColumns({
 86  
                 @JoinColumn(name="ROLE_ID",insertable=false,updatable=false),
 87  
                 @JoinColumn(name="FDOC_NBR", insertable=false, updatable=false)
 88  
         })
 89  
         protected List<KimDocumentRoleMember> rolePrncpls;
 90  
         @Transient
 91  
     protected KimDocumentRoleMember newRolePrncpl;
 92  
         //currently mapped as manyToMany even though it is technically a OneToMany
 93  
         //The reason for this is it is linked with a partial Composite-id, which technically can't 
 94  
         //guarantee uniqueness.  
 95  0
         @ManyToMany(fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 96  
     @Fetch(value = FetchMode.SELECT)
 97  
     @JoinColumn(name="ROLE_ID",insertable=false,updatable=false)
 98  
     //@JoinColumns({
 99  
         //        @JoinColumn(name="ROLE_ID",insertable=false,updatable=false),
 100  
         //        @JoinColumn(name="FDOC_NBR", insertable=false, updatable=false, table="KRIM_PERSON_DOCUMENT_T")
 101  
         //})
 102  
         protected List<RoleResponsibilityImpl> assignedResponsibilities = new AutoPopulatingList(RoleResponsibilityImpl.class);
 103  
 
 104  0
         @Transient
 105  
     protected boolean isEditable = true;
 106  
     
 107  0
         public PersonDocumentRole() {
 108  0
                 attributes = new ArrayList<KimAttributes>();        
 109  0
                 rolePrncpls = new ArrayList<KimDocumentRoleMember>();        
 110  0
                 attributeEntry = new HashMap<String,Object>();
 111  0
         }
 112  
         
 113  
         public String getRoleId() {
 114  0
                 return this.roleId;
 115  
         }
 116  
 
 117  
         public void setRoleId(String roleId) {
 118  0
                 this.roleId = roleId;
 119  0
         }
 120  
 
 121  
         public String getKimTypeId() {
 122  0
                 return this.kimTypeId;
 123  
         }
 124  
 
 125  
         public void setKimTypeId(String kimTypeId) {
 126  0
                 this.kimTypeId = kimTypeId;
 127  0
         }
 128  
 
 129  
         public String getRoleName() {
 130  0
                 return this.roleName;
 131  
         }
 132  
 
 133  
         public void setRoleName(String roleName) {
 134  0
                 this.roleName = roleName;
 135  0
         }
 136  
 
 137  
         public List<? extends KimAttributes> getAttributes() {
 138  0
                 return this.attributes;
 139  
         }
 140  
 
 141  
         public void setAttributes(List<? extends KimAttributes> attributes) {
 142  0
                 this.attributes = attributes;
 143  0
         }
 144  
 
 145  
         public KimTypeBo getKimRoleType() {
 146  0
                 if ( kimRoleType == null ) {
 147  0
                         kimRoleType = KimTypeBo.from(KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId));
 148  
                 }
 149  0
                 return kimRoleType;
 150  
         }
 151  
 
 152  
         public AttributeDefinitionMap getDefinitionsKeyedByAttributeName() {
 153  0
                 AttributeDefinitionMap definitionsKeyedBySortCode = getDefinitions();
 154  0
                 AttributeDefinitionMap returnValue = new AttributeDefinitionMap();
 155  0
                 if (definitionsKeyedBySortCode != null) {
 156  0
                         for (AttributeDefinition definition : definitionsKeyedBySortCode.values()) {
 157  0
                                 returnValue.put(definition.getName(), definition);
 158  
                         }
 159  
                 }
 160  0
                 return returnValue;
 161  
         }
 162  
 
 163  
         public AttributeDefinitionMap getDefinitions() {
 164  0
                 if (definitions == null || definitions.isEmpty()) {
 165  0
                 KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(KimTypeBo.to(this.getKimRoleType()));
 166  
                 //it is possible that the the roleTypeService is coming from a remote application 
 167  
                 // and therefore it can't be guarenteed that it is up and working, so using a try/catch to catch this possibility.
 168  
                 try {
 169  0
                     if ( kimTypeService != null ) {
 170  0
                             definitions = kimTypeService.getAttributeDefinitions(getKimTypeId());
 171  
                     } else {
 172  0
                             definitions = new AttributeDefinitionMap();
 173  
                     }
 174  0
                     } catch (Exception ex) {
 175  0
                 LOG.warn("Not able to retrieve KimTypeService from remote system for KIM Role Type: " + this.getKimRoleType(), ex);
 176  0
             }
 177  
                 }
 178  
                 
 179  0
                 return definitions;
 180  
         }
 181  
 
 182  
         public void setDefinitions(AttributeDefinitionMap definitions) {
 183  0
                 this.definitions = definitions;
 184  0
         }
 185  
 
 186  
         public Map<String,Object> getAttributeEntry() {
 187  0
                 if (attributeEntry == null || attributeEntry.isEmpty()) {
 188  0
                         attributeEntry = KIMServiceLocatorInternal.getUiDocumentService().getAttributeEntries(getDefinitions());
 189  
                 }
 190  
                 
 191  0
                 return this.attributeEntry;
 192  
         }
 193  
 
 194  
         public void setAttributeEntry(Map<String,Object> attributeEntry) {
 195  0
                 this.attributeEntry = attributeEntry;
 196  0
         }
 197  
 
 198  
         public List<KimDocumentRoleMember> getRolePrncpls() {
 199  0
                 return this.rolePrncpls;
 200  
         }
 201  
 
 202  
         public void setRolePrncpls(List<KimDocumentRoleMember> rolePrncpls) {
 203  0
                 this.rolePrncpls = rolePrncpls;
 204  0
         }
 205  
 
 206  
         public KimDocumentRoleMember getNewRolePrncpl() {
 207  0
                 return this.newRolePrncpl;
 208  
         }
 209  
 
 210  
         public void setNewRolePrncpl(KimDocumentRoleMember newRolePrncpl) {
 211  0
                 this.newRolePrncpl = newRolePrncpl;
 212  0
         }
 213  
 
 214  
         public String getNamespaceCode() {
 215  0
                 return this.namespaceCode;
 216  
         }
 217  
 
 218  
         public void setNamespaceCode(String namespaceCode) {
 219  0
                 this.namespaceCode = namespaceCode;
 220  0
         }
 221  
 
 222  
         public List<RoleResponsibilityImpl> getAssignedResponsibilities() {
 223  0
                 return this.assignedResponsibilities;
 224  
         }
 225  
 
 226  
         public void setAssignedResponsibilities(
 227  
                         List<RoleResponsibilityImpl> assignedResponsibilities) {
 228  0
                 this.assignedResponsibilities = assignedResponsibilities;
 229  0
         }
 230  
 
 231  
         /**
 232  
          * @return the roleImpl
 233  
          */
 234  
         public RoleImpl getRoleImpl() {
 235  0
                 return this.roleImpl;
 236  
         }
 237  
 
 238  
         /**
 239  
          * @param roleImpl the roleImpl to set
 240  
          */
 241  
         public void setRoleImpl(RoleImpl roleImpl) {
 242  0
                 this.roleImpl = roleImpl;
 243  0
         }
 244  
 
 245  
         /**
 246  
          * @return the isEditable
 247  
          */
 248  
         public boolean isEditable() {
 249  0
                 return this.isEditable;
 250  
         }
 251  
 
 252  
         /**
 253  
          * @param isEditable the isEditable to set
 254  
          */
 255  
         public void setEditable(boolean isEditable) {
 256  0
                 this.isEditable = isEditable;
 257  0
         }
 258  
 
 259  
 }