1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.rule;
17
18 import org.apache.commons.lang.ObjectUtils;
19 import org.apache.commons.lang.builder.HashCodeBuilder;
20 import org.kuali.rice.core.api.reflect.ObjectDefinition;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
23 import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
24 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
25 import org.kuali.rice.kew.actionrequest.Recipient;
26 import org.kuali.rice.kew.api.KewApiConstants;
27 import org.kuali.rice.kew.api.rule.RuleResponsibilityContract;
28 import org.kuali.rice.kew.service.KEWServiceLocator;
29 import org.kuali.rice.kew.user.RoleRecipient;
30 import org.kuali.rice.kim.api.group.Group;
31 import org.kuali.rice.kim.api.identity.principal.Principal;
32 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
33 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
34 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
35
36 import javax.persistence.Column;
37 import javax.persistence.Entity;
38 import javax.persistence.FetchType;
39 import javax.persistence.GeneratedValue;
40 import javax.persistence.Id;
41 import javax.persistence.JoinColumn;
42 import javax.persistence.ManyToOne;
43 import javax.persistence.Table;
44 import java.util.List;
45
46
47
48
49
50
51
52
53
54
55 @Entity
56 @Table(name="KREW_RULE_RSP_T")
57
58 public class RuleResponsibilityBo extends PersistableBusinessObjectBase implements RuleResponsibilityContract {
59
60 private static final long serialVersionUID = -1565688857123316797L;
61 @Id
62 @PortableSequenceGenerator(name="KREW_RSP_S")
63 @GeneratedValue(generator="KREW_RSP_S")
64 @Column(name="RULE_RSP_ID")
65 private String id;
66 @Column(name="RSP_ID")
67 private String responsibilityId;
68 @Column(name="RULE_ID", insertable=false, updatable=false)
69 private String ruleBaseValuesId;
70 @Column(name="ACTN_RQST_CD")
71 private String actionRequestedCd;
72 @Column(name="NM")
73 private String ruleResponsibilityName;
74 @Column(name="TYP")
75 private String ruleResponsibilityType;
76 @Column(name="PRIO")
77 private Integer priority;
78 @Column(name="APPR_PLCY")
79 private String approvePolicy;
80
81 @ManyToOne(fetch=FetchType.EAGER)
82 @JoinColumn(name="RULE_ID")
83 private RuleBaseValues ruleBaseValues;
84
85
86
87
88 public Principal getPrincipal()
89 {
90 if (isUsingPrincipal()) {
91 return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName);
92 }
93 return null;
94 }
95
96 public Group getGroup() {
97 if (isUsingGroup()) {
98 return KimApiServiceLocator.getGroupService().getGroup(ruleResponsibilityName);
99 }
100 return null;
101 }
102
103 public String getRole() {
104 if (isUsingRole()) {
105 return ruleResponsibilityName;
106 }
107 return null;
108 }
109
110 public String getResolvedRoleName() {
111 if (isUsingRole()) {
112 return getRole().substring(getRole().indexOf("!") + 1, getRole().length());
113 }
114 return null;
115 }
116
117 public String getRoleAttributeName() {
118 return getRole().substring(0, getRole().indexOf("!"));
119 }
120
121 public RoleAttribute resolveRoleAttribute() {
122 if (isUsingRole()) {
123 String attributeName = getRoleAttributeName();
124 return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName));
125 }
126 return null;
127 }
128
129 @Override
130 public boolean isUsingRole() {
131 return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_ROLE_ID));
132 }
133
134 @Override
135 public boolean isUsingPrincipal() {
136 return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_WORKFLOW_ID));
137 }
138
139 @Override
140 public boolean isUsingGroup() {
141 return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID));
142 }
143
144 public String getRuleBaseValuesId() {
145 return ruleBaseValuesId;
146 }
147
148 public void setRuleBaseValuesId(String ruleBaseValuesId) {
149 this.ruleBaseValuesId = ruleBaseValuesId;
150 }
151
152 public RuleBaseValues getRuleBaseValues() {
153 return ruleBaseValues;
154 }
155
156 public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
157 this.ruleBaseValues = ruleBaseValues;
158 }
159
160 public String getActionRequestedCd() {
161 return actionRequestedCd;
162 }
163
164 public void setActionRequestedCd(String actionRequestedCd) {
165 this.actionRequestedCd = actionRequestedCd;
166 }
167
168 public String getId() {
169 return id;
170 }
171
172 public void setId(String ruleResponsibilityId) {
173 this.id = ruleResponsibilityId;
174 }
175 public Integer getPriority() {
176 return priority;
177 }
178
179 public void setPriority(Integer priority) {
180 this.priority = priority;
181 }
182
183 public String getApprovePolicy() {
184 return approvePolicy;
185 }
186
187 public void setApprovePolicy(String approvePolicy) {
188 this.approvePolicy = approvePolicy;
189 }
190
191 public Object copy(boolean preserveKeys) {
192 RuleResponsibilityBo ruleResponsibilityClone = new RuleResponsibilityBo();
193 ruleResponsibilityClone.setApprovePolicy(getApprovePolicy());
194 if (actionRequestedCd != null) {
195 ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd);
196 }
197 if (id != null && preserveKeys) {
198 ruleResponsibilityClone.setId(id);
199 }
200
201 if (responsibilityId != null) {
202 ruleResponsibilityClone.setResponsibilityId(responsibilityId);
203 }
204
205 if (ruleResponsibilityName != null) {
206 ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName);
207 }
208 if (ruleResponsibilityType != null) {
209 ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType);
210 }
211 if (priority != null) {
212 ruleResponsibilityClone.setPriority(priority);
213 }
214
215
216
217
218
219
220
221
222
223 return ruleResponsibilityClone;
224 }
225
226 public String getRuleResponsibilityName() {
227 return ruleResponsibilityName;
228 }
229
230 public void setRuleResponsibilityName(String ruleResponsibilityName) {
231 this.ruleResponsibilityName = ruleResponsibilityName;
232 }
233
234 public String getRuleResponsibilityType() {
235 return ruleResponsibilityType;
236 }
237
238 public void setRuleResponsibilityType(String ruleResponsibilityType) {
239 this.ruleResponsibilityType = ruleResponsibilityType;
240 }
241
242 public String getResponsibilityId() {
243 return responsibilityId;
244 }
245 public void setResponsibilityId(String responsibilityId) {
246 this.responsibilityId = responsibilityId;
247 }
248
249 public List<RuleDelegationBo> getDelegationRules() {
250 return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId());
251 }
252
253 public RuleDelegationBo getDelegationRule(int index) {
254 return getDelegationRules().get(index);
255 }
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280 public String getActionRequestedDisplayValue() {
281 return KewApiConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd());
282 }
283
284 public String getRuleResponsibilityTypeDisplayValue() {
285 return KewApiConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType());
286 }
287
288 public boolean equals(Object o) {
289 if (o == null) return false;
290 if (!(o instanceof RuleResponsibilityBo)) return false;
291 RuleResponsibilityBo pred = (RuleResponsibilityBo) o;
292 return ObjectUtils.equals(ruleResponsibilityName, pred.getRuleResponsibilityName()) &&
293 ObjectUtils.equals(actionRequestedCd, pred.getActionRequestedCd()) &&
294 ObjectUtils.equals(priority, pred.getPriority()) &&
295 ObjectUtils.equals(approvePolicy, pred.getApprovePolicy());
296 }
297
298
299
300
301 @Override
302 public int hashCode() {
303 return new HashCodeBuilder()
304 .append(this.actionRequestedCd)
305 .append(this.approvePolicy)
306 .append(this.priority)
307 .append(this.ruleResponsibilityName).toHashCode();
308 }
309
310 @Override
311 public String getGroupId() {
312 if (!isUsingGroup()) {
313 return null;
314 }
315 return getGroup().getId();
316 }
317
318 @Override
319 public String getPrincipalId() {
320 if (getPrincipal() == null) {
321 return null;
322 }
323 return getPrincipal().getPrincipalId();
324 }
325
326 @Override
327 public String getRoleName() {
328 return getRole();
329 }
330
331
332
333
334
335 public Recipient getRecipient() {
336 if (isUsingPrincipal()) {
337 return new KimPrincipalRecipient(getPrincipal());
338 } else if (isUsingGroup()) {
339 return new KimGroupRecipient(getGroup());
340 } else if (isUsingRole()) {
341 return new RoleRecipient(getRole());
342 } else {
343 return null;
344 }
345 }
346
347 public static org.kuali.rice.kew.api.rule.RuleResponsibility to(RuleResponsibilityBo bo) {
348 if (bo == null) {
349 return null;
350 }
351 return org.kuali.rice.kew.api.rule.RuleResponsibility.Builder.create(bo).build();
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372 }
373 }