1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
28
29
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 }