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 | 0 | 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 | 0 | if (isUsingWorkflowUser()) { |
86 | 0 | return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName); |
87 | |
} |
88 | 0 | return null; |
89 | |
} |
90 | |
|
91 | |
public Group getGroup() { |
92 | 0 | if (isUsingGroup()) { |
93 | 0 | return KimApiServiceLocator.getIdentityManagementService().getGroup(ruleResponsibilityName); |
94 | |
} |
95 | 0 | return null; |
96 | |
} |
97 | |
|
98 | |
public String getRole() { |
99 | 0 | if (isUsingRole()) { |
100 | 0 | return ruleResponsibilityName; |
101 | |
} |
102 | 0 | return null; |
103 | |
} |
104 | |
|
105 | |
public String getResolvedRoleName() { |
106 | 0 | if (isUsingRole()) { |
107 | 0 | return getRole().substring(getRole().indexOf("!") + 1, getRole().length()); |
108 | |
} |
109 | 0 | return null; |
110 | |
} |
111 | |
|
112 | |
public String getRoleAttributeName() { |
113 | 0 | return getRole().substring(0, getRole().indexOf("!")); |
114 | |
} |
115 | |
|
116 | |
public RoleAttribute resolveRoleAttribute() throws WorkflowException { |
117 | 0 | if (isUsingRole()) { |
118 | 0 | String attributeName = getRoleAttributeName(); |
119 | 0 | return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName)); |
120 | |
} |
121 | 0 | return null; |
122 | |
} |
123 | |
|
124 | |
public boolean isUsingRole() { |
125 | 0 | return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_ROLE_ID)); |
126 | |
} |
127 | |
|
128 | |
public boolean isUsingWorkflowUser() { |
129 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID)); |
130 | |
} |
131 | |
|
132 | |
public boolean isUsingGroup() { |
133 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KEWConstants.RULE_RESPONSIBILITY_GROUP_ID)); |
134 | |
} |
135 | |
|
136 | |
public Long getRuleBaseValuesId() { |
137 | 0 | return ruleBaseValuesId; |
138 | |
} |
139 | |
|
140 | |
public void setRuleBaseValuesId(Long ruleBaseValuesId) { |
141 | 0 | this.ruleBaseValuesId = ruleBaseValuesId; |
142 | 0 | } |
143 | |
|
144 | |
public RuleBaseValues getRuleBaseValues() { |
145 | 0 | return ruleBaseValues; |
146 | |
} |
147 | |
|
148 | |
public void setRuleBaseValues(RuleBaseValues ruleBaseValues) { |
149 | 0 | this.ruleBaseValues = ruleBaseValues; |
150 | 0 | } |
151 | |
|
152 | |
public String getActionRequestedCd() { |
153 | 0 | return actionRequestedCd; |
154 | |
} |
155 | |
|
156 | |
public void setActionRequestedCd(String actionRequestedCd) { |
157 | 0 | this.actionRequestedCd = actionRequestedCd; |
158 | 0 | } |
159 | |
|
160 | |
public Long getRuleResponsibilityKey() { |
161 | 0 | return ruleResponsibilityKey; |
162 | |
} |
163 | |
|
164 | |
public void setRuleResponsibilityKey(Long ruleResponsibilityId) { |
165 | 0 | this.ruleResponsibilityKey = ruleResponsibilityId; |
166 | 0 | } |
167 | |
public Integer getPriority() { |
168 | 0 | return priority; |
169 | |
} |
170 | |
|
171 | |
public void setPriority(Integer priority) { |
172 | 0 | this.priority = priority; |
173 | 0 | } |
174 | |
|
175 | |
public String getApprovePolicy() { |
176 | 0 | return approvePolicy; |
177 | |
} |
178 | |
|
179 | |
public void setApprovePolicy(String approvePolicy) { |
180 | 0 | this.approvePolicy = approvePolicy; |
181 | 0 | } |
182 | |
|
183 | |
public Object copy(boolean preserveKeys) { |
184 | 0 | RuleResponsibility ruleResponsibilityClone = new RuleResponsibility(); |
185 | 0 | ruleResponsibilityClone.setApprovePolicy(getApprovePolicy()); |
186 | 0 | if (actionRequestedCd != null) { |
187 | 0 | ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd); |
188 | |
} |
189 | 0 | if (ruleResponsibilityKey != null && preserveKeys) { |
190 | 0 | ruleResponsibilityClone.setRuleResponsibilityKey(ruleResponsibilityKey); |
191 | |
} |
192 | |
|
193 | 0 | if (responsibilityId != null) { |
194 | 0 | ruleResponsibilityClone.setResponsibilityId(responsibilityId); |
195 | |
} |
196 | |
|
197 | 0 | if (ruleResponsibilityName != null) { |
198 | 0 | ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName); |
199 | |
} |
200 | 0 | if (ruleResponsibilityType != null) { |
201 | 0 | ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType); |
202 | |
} |
203 | 0 | if (priority != null) { |
204 | 0 | ruleResponsibilityClone.setPriority(priority); |
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
|
213 | |
|
214 | |
|
215 | 0 | return ruleResponsibilityClone; |
216 | |
} |
217 | |
|
218 | |
public String getRuleResponsibilityName() { |
219 | 0 | return ruleResponsibilityName; |
220 | |
} |
221 | |
|
222 | |
public void setRuleResponsibilityName(String ruleResponsibilityName) { |
223 | 0 | this.ruleResponsibilityName = ruleResponsibilityName; |
224 | 0 | } |
225 | |
|
226 | |
public String getRuleResponsibilityType() { |
227 | 0 | return ruleResponsibilityType; |
228 | |
} |
229 | |
|
230 | |
public void setRuleResponsibilityType(String ruleResponsibilityType) { |
231 | 0 | this.ruleResponsibilityType = ruleResponsibilityType; |
232 | 0 | } |
233 | |
|
234 | |
public Long getResponsibilityId() { |
235 | 0 | return responsibilityId; |
236 | |
} |
237 | |
public void setResponsibilityId(Long responsibilityId) { |
238 | 0 | this.responsibilityId = responsibilityId; |
239 | 0 | } |
240 | |
|
241 | |
public List<RuleDelegation> getDelegationRules() { |
242 | 0 | return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId()); |
243 | |
} |
244 | |
|
245 | |
public RuleDelegation getDelegationRule(int index) { |
246 | 0 | 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 | 0 | return KEWConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd()); |
274 | |
} |
275 | |
|
276 | |
public String getRuleResponsibilityTypeDisplayValue() { |
277 | 0 | return KEWConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType()); |
278 | |
} |
279 | |
|
280 | |
public boolean equals(Object o) { |
281 | 0 | if (o == null) return false; |
282 | 0 | if (!(o instanceof RuleResponsibility)) return false; |
283 | 0 | RuleResponsibility pred = (RuleResponsibility) o; |
284 | 0 | 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 | 0 | return new HashCodeBuilder() |
296 | |
.append(this.actionRequestedCd) |
297 | |
.append(this.approvePolicy) |
298 | |
.append(this.priority) |
299 | |
.append(this.ruleResponsibilityName).toHashCode(); |
300 | |
} |
301 | |
} |