View Javadoc

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      public AdHocRoutePerson() {
42          setType(PERSON_TYPE);
43  
44          // TODO: need some way of handling types that cannot be instantiated due to module dependencies
45          try {
46              person = (Person) Class.forName("org.kuali.rice.kim.impl.identity.PersonImpl").newInstance();
47          } catch (Exception e) {
48              throw new RuntimeException(e);
49          }
50      }
51  
52      @Override
53      public void setType(Integer type) {
54          if (!PERSON_TYPE.equals(type)) {
55              throw new IllegalArgumentException("cannot change type to " + type);
56          }
57          super.setType(type);
58      }
59  
60      @Override
61      public void setId(String id) {
62          super.setId(id);
63  
64          if (StringUtils.isNotBlank(id)) {
65              person = KimApiServiceLocator.getPersonService().getPerson(id);
66              setPerson(person);
67          }
68      }
69  
70      @Override
71      public void setName(String name) {
72          super.setName(name);
73  
74          if (StringUtils.isNotBlank(name) &&
75                  ((person != null) && !StringUtils.equals(person.getName(), name))) {
76              person = KimApiServiceLocator.getPersonService().getPerson(getId());
77              setPerson(person);
78          }
79      }
80  
81      public Person getPerson() {
82          if ((person == null) || !StringUtils.equals(person.getPrincipalId(), getId())) {
83              person = KimApiServiceLocator.getPersonService().getPerson(getId());
84  
85              if (person == null) {
86                  try {
87                      person = (Person) Class.forName("org.kuali.rice.kim.impl.identity.PersonImpl").newInstance();
88                  } catch (Exception e) {
89                      throw new RuntimeException(e);
90                  }
91              }
92          }
93  
94          return person;
95      }
96  
97      public void setPerson(Person person) {
98          this.person = person;
99          this.id = person.getPrincipalId();
100         this.name = person.getPrincipalName();
101     }
102 }
103