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.reflect.ObjectDefinition;
23 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
24 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
25 import org.kuali.rice.kew.api.rule.RuleResponsibilityContract;
26 import org.kuali.rice.kew.service.KEWServiceLocator;
27 import org.kuali.rice.kew.api.KewApiConstants;
28 import org.kuali.rice.kim.api.group.Group;
29 import org.kuali.rice.kim.api.identity.principal.Principal;
30 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
31 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
32
33 import javax.persistence.Column;
34 import javax.persistence.Entity;
35 import javax.persistence.FetchType;
36 import javax.persistence.GeneratedValue;
37 import javax.persistence.Id;
38 import javax.persistence.JoinColumn;
39 import javax.persistence.ManyToOne;
40 import javax.persistence.Table;
41 import java.util.List;
42
43
44
45
46
47
48
49
50
51
52 @Entity
53 @Table(name="KREW_RULE_RSP_T")
54
55 public class RuleResponsibilityBo extends PersistableBusinessObjectBase implements RuleResponsibilityContract {
56
57 private static final long serialVersionUID = -1565688857123316797L;
58 @Id
59 @GeneratedValue(generator="KREW_RSP_S")
60 @GenericGenerator(name="KREW_RSP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
61 @Parameter(name="sequence_name",value="KREW_RSP_S"),
62 @Parameter(name="value_column",value="id")
63 })
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 public static org.kuali.rice.kew.api.rule.RuleResponsibility to(RuleResponsibilityBo bo) {
332 if (bo == null) {
333 return null;
334 }
335 return org.kuali.rice.kew.api.rule.RuleResponsibility.Builder.create(bo).build();
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356 }
357 }