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