Coverage Report - org.kuali.rice.krad.bo.AdHocRoutePerson
 
Classes in this File Line Coverage Branch Coverage Complexity
AdHocRoutePerson
0%
0/33
0%
0/16
3.167
 
 1  
 /*
 2  
  * Copyright 2006-2007 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.krad.bo;
 17  
 
 18  
 import org.apache.commons.lang.ObjectUtils;
 19  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 20  
 import org.kuali.rice.kim.bo.Person;
 21  
 
 22  
 import javax.persistence.Entity;
 23  
 import javax.persistence.IdClass;
 24  
 import javax.persistence.Table;
 25  
 import javax.persistence.Transient;
 26  
 
 27  
 import org.apache.commons.lang.StringUtils;
 28  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 29  
 import org.kuali.rice.kim.bo.Person;
 30  
 
 31  
 /**
 32  
  * Ad Hoc Route Person Business Object
 33  
  *
 34  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 35  
  */
 36  
 @IdClass(AdHocRoutePersonId.class)
 37  
 @Entity
 38  
 @Table(name = "KRNS_ADHOC_RTE_ACTN_RECIP_T")
 39  
 public class AdHocRoutePerson extends AdHocRouteRecipient {
 40  
     private static final long serialVersionUID = 1L;
 41  
 
 42  
     @Transient
 43  
     private transient Person person;
 44  
 
 45  0
     public AdHocRoutePerson() {
 46  0
         setType(PERSON_TYPE);
 47  
 
 48  
         // TODO: need some way of handling types that cannot be instantiated due to module dependencies
 49  
         try {
 50  0
             person = (Person) Class.forName("org.kuali.rice.kim.bo.impl.PersonImpl").newInstance();
 51  0
         } catch (Exception e) {
 52  0
             throw new RuntimeException(e);
 53  0
         }
 54  0
     }
 55  
 
 56  
     @Override
 57  
     public void setType(Integer type) {
 58  0
         if (!PERSON_TYPE.equals(type)) {
 59  0
             throw new IllegalArgumentException("cannot change type to " + type);
 60  
         }
 61  0
         super.setType(type);
 62  0
     }
 63  
 
 64  
     @Override
 65  
     public void setId(String id) {
 66  0
         super.setId(id);
 67  
 
 68  0
         if (StringUtils.isNotBlank(id)) {
 69  0
             person = KimApiServiceLocator.getPersonService().getPerson(id);
 70  0
             setPerson(person);
 71  
         }
 72  0
     }
 73  
 
 74  
     @Override
 75  
     public void setName(String name) {
 76  0
         super.setName(name);
 77  
 
 78  0
         if (StringUtils.isNotBlank(name) &&
 79  
                 !((person != null) && StringUtils.equals(person.getPrincipalName(), name))) {
 80  0
             person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(name);
 81  0
             setPerson(person);
 82  
         }
 83  0
     }
 84  
 
 85  
     public Person getPerson() {
 86  0
         if ((person == null) || !StringUtils.equals(person.getPrincipalId(), getId())) {
 87  0
             person = KimApiServiceLocator.getPersonService().getPerson(getId());
 88  
 
 89  0
             if (person == null) {
 90  
                 try {
 91  0
                     person = (Person) Class.forName("org.kuali.rice.kim.bo.impl.PersonImpl").newInstance();
 92  0
                 } catch (Exception e) {
 93  0
                     throw new RuntimeException(e);
 94  0
                 }
 95  
             }
 96  
         }
 97  
 
 98  0
         return person;
 99  
     }
 100  
 
 101  
     public void setPerson(Person person) {
 102  0
         this.person = person;
 103  0
         this.id = person.getPrincipalId();
 104  0
         this.name = person.getPrincipalName();
 105  0
     }
 106  
 }
 107