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