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