1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.impl.peopleflow |
17 | |
|
18 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
19 | |
import org.kuali.rice.kew.api.peopleflow.PeopleFlowMemberContract |
20 | |
import org.kuali.rice.core.api.membership.MemberType |
21 | |
|
22 | |
import org.kuali.rice.kew.api.peopleflow.PeopleFlowMember |
23 | |
|
24 | |
import org.kuali.rice.kew.api.peopleflow.PeopleFlowDelegate |
25 | |
|
26 | |
import org.kuali.rice.kew.api.action.ActionRequestPolicy; |
27 | |
import org.kuali.rice.kim.api.identity.Person |
28 | |
|
29 | |
import org.kuali.rice.kim.api.KimConstants |
30 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
31 | |
import org.kuali.rice.kim.framework.group.GroupEbo |
32 | |
import org.kuali.rice.kim.framework.role.RoleEbo |
33 | |
|
34 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb |
35 | |
import org.kuali.rice.krad.service.ModuleService |
36 | |
import org.apache.commons.lang.StringUtils; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
class PeopleFlowMemberBo extends PersistableBusinessObjectBase implements PeopleFlowMemberContract { |
42 | |
|
43 | |
String id |
44 | |
String peopleFlowId |
45 | |
String memberId |
46 | |
String memberTypeCode |
47 | |
String actionRequestPolicyCode |
48 | |
String responsibilityId |
49 | |
int priority = 1; |
50 | |
|
51 | |
|
52 | |
String memberName; |
53 | |
Person person; |
54 | |
GroupEbo group; |
55 | |
RoleEbo role; |
56 | |
|
57 | 0 | List<PeopleFlowDelegateBo> delegates = new ArrayList<PeopleFlowDelegateBo>(); |
58 | |
|
59 | |
public Person getPerson() { |
60 | 0 | if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { |
61 | 0 | if ((this.person == null) || !person.getPrincipalId().equals(memberId) || !person.getPrincipalName().equals(memberName)) { |
62 | |
|
63 | 0 | if (StringUtils.isNotBlank(memberName)) { |
64 | 0 | this.person = KimApiServiceLocator.personService.getPersonByPrincipalName(memberName); |
65 | |
} else { |
66 | 0 | this.person = KimApiServiceLocator.personService.getPerson(memberId); |
67 | |
} |
68 | |
} |
69 | |
|
70 | 0 | if (this.person != null) { |
71 | 0 | memberId = person.getPrincipalId(); |
72 | 0 | memberName = person.getPrincipalName(); |
73 | |
|
74 | 0 | return this.person; |
75 | |
} |
76 | |
} |
77 | |
|
78 | 0 | return KimApiServiceLocator.personService.personImplementationClass.newInstance(); |
79 | |
} |
80 | |
|
81 | |
public GroupEbo getGroup() { |
82 | 0 | if (MemberType.GROUP.getCode().equals(memberTypeCode)) { |
83 | 0 | ModuleService eboModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(GroupEbo.class); |
84 | 0 | group = eboModuleService.retrieveExternalizableBusinessObjectIfNecessary(this, group, "group"); |
85 | |
|
86 | 0 | if (group != null) { |
87 | 0 | memberId = group.id; |
88 | 0 | memberName = group.namespaceCode + " : " + group.name; |
89 | |
} |
90 | |
} |
91 | |
|
92 | 0 | return group; |
93 | |
} |
94 | |
|
95 | |
public RoleEbo getRole() { |
96 | 0 | if (MemberType.ROLE.getCode().equals(memberTypeCode)) { |
97 | 0 | ModuleService eboModuleService = KRADServiceLocatorWeb.getKualiModuleService().getResponsibleModuleService(RoleEbo.class); |
98 | 0 | role = eboModuleService.retrieveExternalizableBusinessObjectIfNecessary(this, role, "role"); |
99 | |
|
100 | 0 | if (role != null) { |
101 | 0 | memberId = role.id; |
102 | 0 | memberName = role.namespaceCode + " : " + role.name; |
103 | |
} |
104 | |
} |
105 | |
|
106 | 0 | return role; |
107 | |
} |
108 | |
|
109 | |
public void setMemberName(String memberName) { |
110 | 0 | this.memberName = memberName; |
111 | |
|
112 | |
|
113 | 0 | if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { |
114 | 0 | getPerson(); |
115 | |
} |
116 | |
} |
117 | |
|
118 | |
public void setMemberId(String memberId) { |
119 | 0 | this.memberId = memberId; |
120 | |
|
121 | |
|
122 | 0 | if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) { |
123 | 0 | getPerson(); |
124 | 0 | } else if (MemberType.GROUP.getCode().equals(memberTypeCode)) { |
125 | 0 | getGroup(); |
126 | 0 | } else if (MemberType.ROLE.getCode().equals(memberTypeCode)) { |
127 | 0 | getRole(); |
128 | |
} |
129 | |
} |
130 | |
|
131 | |
@Override |
132 | |
MemberType getMemberType() { |
133 | 0 | return MemberType.fromCode(memberTypeCode) |
134 | |
} |
135 | |
|
136 | |
void setMemberType(MemberType type) { |
137 | 0 | memberTypeCode = type.getCode() |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
ActionRequestPolicy getActionRequestPolicy() { |
142 | 0 | return ActionRequestPolicy.fromCode(actionRequestPolicyCode) |
143 | |
} |
144 | |
|
145 | |
public static PeopleFlowMember to(PeopleFlowMemberBo memberBo) { |
146 | 0 | if (memberBo == null) { |
147 | 0 | return null; |
148 | |
} |
149 | 0 | PeopleFlowMember.Builder member = PeopleFlowMember.Builder.create(memberBo); |
150 | 0 | return member.build(); |
151 | |
} |
152 | |
|
153 | |
public static PeopleFlowMemberBo from(PeopleFlowMember member) { |
154 | 0 | if (member == null) { |
155 | 0 | return null; |
156 | |
} |
157 | 0 | PeopleFlowMemberBo memberBo = new PeopleFlowMemberBo(); |
158 | 0 | memberBo.setMemberId(member.getMemberId()); |
159 | 0 | memberBo.setMemberType(member.getMemberType()); |
160 | 0 | if (member.getActionRequestPolicy() != null) { |
161 | 0 | memberBo.setActionRequestPolicyCode(member.getActionRequestPolicy().getCode()); |
162 | |
} |
163 | 0 | memberBo.setResponsibilityId(member.getResponsibilityId()); |
164 | 0 | memberBo.setPriority(member.getPriority()); |
165 | 0 | memberBo.setDelegates(new ArrayList<PeopleFlowDelegateBo>()); |
166 | 0 | for (PeopleFlowDelegate delegate : member.getDelegates()) { |
167 | 0 | memberBo.getDelegates().add(PeopleFlowDelegateBo.from(delegate)); |
168 | |
} |
169 | 0 | return memberBo; |
170 | |
} |
171 | |
|
172 | |
} |