View Javadoc

1   /**
2    * Copyright 2005-2012 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          try {
45              person = (Person) KimApiServiceLocator.getPersonService().getPersonImplementationClass().newInstance();
46          } catch (Exception e) {
47              throw new RuntimeException(e);
48          }
49      }
50  
51      @Override
52      public void setType(Integer type) {
53          if (!PERSON_TYPE.equals(type)) {
54              throw new IllegalArgumentException("cannot change type to " + type);
55          }
56          super.setType(type);
57      }
58  
59      @Override
60      public void setId(String id) {
61          super.setId(id);
62  
63          if (StringUtils.isNotBlank(id)) {
64              person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(id);
65              setPerson(person);
66          }
67      }
68  
69      @Override
70      public void setName(String name) {
71          super.setName(name);
72  
73          if (StringUtils.isNotBlank(name) && getId() != null &&
74                  ((person != null) && !StringUtils.equals(person.getName(), name))) {
75              person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(getId());
76              setPerson(person);
77          }
78      }
79  
80      public Person getPerson() {
81          if ((person == null) || !StringUtils.equals(person.getPrincipalName(), getId())) {
82              person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(getId());
83  
84              if (person == null) {
85                  try {
86                      person = (Person) KimApiServiceLocator.getPersonService().getPersonImplementationClass()
87                              .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          if (person != null) {
100             this.id = person.getPrincipalName();
101             this.name = person.getName();
102         }
103     }
104 }
105