1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.rule;
18
19 import org.apache.commons.lang.ObjectUtils;
20 import org.apache.commons.lang.builder.HashCodeBuilder;
21 import org.hibernate.annotations.GenericGenerator;
22 import org.hibernate.annotations.Parameter;
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.exception.WorkflowException;
27 import org.kuali.rice.kew.service.KEWServiceLocator;
28 import org.kuali.rice.kew.util.KEWConstants;
29 import org.kuali.rice.kim.api.entity.principal.Principal;
30 import org.kuali.rice.kim.api.group.Group;
31 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
32
33 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
34
35 import javax.persistence.*;
36 import java.util.List;
37
38
39
40
41
42
43
44
45
46
47 @Entity
48 @Table(name="KREW_RULE_RSP_T")
49
50 public class RuleResponsibility extends PersistableBusinessObjectBase {
51
52 private static final long serialVersionUID = -1565688857123316797L;
53 @Id
54 @GeneratedValue(generator="KREW_RSP_S")
55 @GenericGenerator(name="KREW_RSP_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={
56 @Parameter(name="sequence_name",value="KREW_RSP_S"),
57 @Parameter(name="value_column",value="id")
58 })
59 @Column(name="RULE_RSP_ID")
60 private Long ruleResponsibilityKey;
61 @Column(name="RSP_ID")
62 private Long responsibilityId;
63 @Column(name="RULE_ID", insertable=false, updatable=false)
64 private Long ruleBaseValuesId;
65 @Column(name="ACTN_RQST_CD")
66 private String actionRequestedCd;
67 @Column(name="NM")
68 private String ruleResponsibilityName;
69 @Column(name="TYP")
70 private String ruleResponsibilityType;
71 @Column(name="PRIO")
72 private Integer priority;
73 @Column(name="APPR_PLCY")
74 private String approvePolicy;
75
76 @ManyToOne(fetch=FetchType.EAGER)
77 @JoinColumn(name="RULE_ID")
78 private RuleBaseValues ruleBaseValues;
79
80
81
82
83 public Principal getPrincipal()
84 {
85 if (isUsingWorkflowUser()) {
86 return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName);
87 }
88 return null;
89 }
90
91 public Group getGroup() {
92 if (isUsingGroup()) {
93 return KimApiServiceLocator.getIdentityManagementService().getGroup(ruleResponsibilityName);
94 }
95 return null;
96 }
97
98 public String getRole() {
99 if (isUsingRole()) {
100 return ruleResponsibilityName;
101 }
102 return null;
103 }
104
105 public String getResolvedRoleName() {
106 if (isUsingRole()) {
107 return getRole().substring(getRole().indexOf("!") + 1, getRole().length());
108 }
109 return null;
110 }
111
112 public String getRoleAttributeName() {
113 return getRole().substring(0, getRole().indexOf("!"));
114 }
115
116 public RoleAttribute resolveRoleAttribute() throws WorkflowException {
117 if (isUsingRole()) {
118 String attributeName = getRoleAttributeName();
119 return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName));
120 }
121 return null;
122 }
123
124 public boolean isUsingRole() {
125 return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_ROLE_ID));
126 }
127
128 public boolean isUsingWorkflowUser() {
129 return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID));
130 }
131
132 public boolean isUsingGroup() {
133 return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_GROUP_ID));
134 }
135
136 public Long getRuleBaseValuesId() {
137 return ruleBaseValuesId;
138 }
139
140 public void setRuleBaseValuesId(Long ruleBaseValuesId) {
141 this.ruleBaseValuesId = ruleBaseValuesId;
142 }
143
144 public RuleBaseValues getRuleBaseValues() {
145 return ruleBaseValues;
146 }
147
148 public void setRuleBaseValues(RuleBaseValues ruleBaseValues) {
149 this.ruleBaseValues = ruleBaseValues;
150 }
151
152 public String getActionRequestedCd() {
153 return actionRequestedCd;
154 }
155
156 public void setActionRequestedCd(String actionRequestedCd) {
157 this.actionRequestedCd = actionRequestedCd;
158 }
159
160 public Long getRuleResponsibilityKey() {
161 return ruleResponsibilityKey;
162 }
163
164 public void setRuleResponsibilityKey(Long ruleResponsibilityId) {
165 this.ruleResponsibilityKey = ruleResponsibilityId;
166 }
167 public Integer getPriority() {
168 return priority;
169 }
170
171 public void setPriority(Integer priority) {
172 this.priority = priority;
173 }
174
175 public String getApprovePolicy() {
176 return approvePolicy;
177 }
178
179 public void setApprovePolicy(String approvePolicy) {
180 this.approvePolicy = approvePolicy;
181 }
182
183 public Object copy(boolean preserveKeys) {
184 RuleResponsibility ruleResponsibilityClone = new RuleResponsibility();
185 ruleResponsibilityClone.setApprovePolicy(getApprovePolicy());
186 if (actionRequestedCd != null) {
187 ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd);
188 }
189 if (ruleResponsibilityKey != null && preserveKeys) {
190 ruleResponsibilityClone.setRuleResponsibilityKey(ruleResponsibilityKey);
191 }
192
193 if (responsibilityId != null) {
194 ruleResponsibilityClone.setResponsibilityId(responsibilityId);
195 }
196
197 if (ruleResponsibilityName != null) {
198 ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName);
199 }
200 if (ruleResponsibilityType != null) {
201 ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType);
202 }
203 if (priority != null) {
204 ruleResponsibilityClone.setPriority(priority);
205 }
206
207
208
209
210
211
212
213
214
215 return ruleResponsibilityClone;
216 }
217
218 public String getRuleResponsibilityName() {
219 return ruleResponsibilityName;
220 }
221
222 public void setRuleResponsibilityName(String ruleResponsibilityName) {
223 this.ruleResponsibilityName = ruleResponsibilityName;
224 }
225
226 public String getRuleResponsibilityType() {
227 return ruleResponsibilityType;
228 }
229
230 public void setRuleResponsibilityType(String ruleResponsibilityType) {
231 this.ruleResponsibilityType = ruleResponsibilityType;
232 }
233
234 public Long getResponsibilityId() {
235 return responsibilityId;
236 }
237 public void setResponsibilityId(Long responsibilityId) {
238 this.responsibilityId = responsibilityId;
239 }
240
241 public List<RuleDelegation> getDelegationRules() {
242 return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId());
243 }
244
245 public RuleDelegation getDelegationRule(int index) {
246 return getDelegationRules().get(index);
247 }
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272 public String getActionRequestedDisplayValue() {
273 return KEWConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd());
274 }
275
276 public String getRuleResponsibilityTypeDisplayValue() {
277 return KEWConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType());
278 }
279
280 public boolean equals(Object o) {
281 if (o == null) return false;
282 if (!(o instanceof RuleResponsibility)) return false;
283 RuleResponsibility pred = (RuleResponsibility) o;
284 return ObjectUtils.equals(ruleResponsibilityName, pred.getRuleResponsibilityName()) &&
285 ObjectUtils.equals(actionRequestedCd, pred.getActionRequestedCd()) &&
286 ObjectUtils.equals(priority, pred.getPriority()) &&
287 ObjectUtils.equals(approvePolicy, pred.getApprovePolicy());
288 }
289
290
291
292
293 @Override
294 public int hashCode() {
295 return new HashCodeBuilder()
296 .append(this.actionRequestedCd)
297 .append(this.approvePolicy)
298 .append(this.priority)
299 .append(this.ruleResponsibilityName).toHashCode();
300 }
301 }