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