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 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
29
30
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
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