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