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