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 | 0 | 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 | 0 | if (isUsingPrincipal()) { |
91 | 0 | return KEWServiceLocator.getIdentityHelperService().getPrincipal(ruleResponsibilityName); |
92 | |
} |
93 | 0 | return null; |
94 | |
} |
95 | |
|
96 | |
public Group getGroup() { |
97 | 0 | if (isUsingGroup()) { |
98 | 0 | return KimApiServiceLocator.getGroupService().getGroup(ruleResponsibilityName); |
99 | |
} |
100 | 0 | return null; |
101 | |
} |
102 | |
|
103 | |
public String getRole() { |
104 | 0 | if (isUsingRole()) { |
105 | 0 | return ruleResponsibilityName; |
106 | |
} |
107 | 0 | return null; |
108 | |
} |
109 | |
|
110 | |
public String getResolvedRoleName() { |
111 | 0 | if (isUsingRole()) { |
112 | 0 | return getRole().substring(getRole().indexOf("!") + 1, getRole().length()); |
113 | |
} |
114 | 0 | return null; |
115 | |
} |
116 | |
|
117 | |
public String getRoleAttributeName() { |
118 | 0 | return getRole().substring(0, getRole().indexOf("!")); |
119 | |
} |
120 | |
|
121 | |
public RoleAttribute resolveRoleAttribute() { |
122 | 0 | if (isUsingRole()) { |
123 | 0 | String attributeName = getRoleAttributeName(); |
124 | 0 | return (RoleAttribute) GlobalResourceLoader.getResourceLoader().getObject(new ObjectDefinition(attributeName)); |
125 | |
} |
126 | 0 | return null; |
127 | |
} |
128 | |
|
129 | |
@Override |
130 | |
public boolean isUsingRole() { |
131 | 0 | return (ruleResponsibilityName != null && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_ROLE_ID)); |
132 | |
} |
133 | |
|
134 | |
@Override |
135 | |
public boolean isUsingPrincipal() { |
136 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_WORKFLOW_ID)); |
137 | |
} |
138 | |
|
139 | |
@Override |
140 | |
public boolean isUsingGroup() { |
141 | 0 | return (ruleResponsibilityName != null && !ruleResponsibilityName.trim().equals("") && ruleResponsibilityType != null && ruleResponsibilityType.equals(KewApiConstants.RULE_RESPONSIBILITY_GROUP_ID)); |
142 | |
} |
143 | |
|
144 | |
public String getRuleBaseValuesId() { |
145 | 0 | return ruleBaseValuesId; |
146 | |
} |
147 | |
|
148 | |
public void setRuleBaseValuesId(String ruleBaseValuesId) { |
149 | 0 | this.ruleBaseValuesId = ruleBaseValuesId; |
150 | 0 | } |
151 | |
|
152 | |
public RuleBaseValues getRuleBaseValues() { |
153 | 0 | return ruleBaseValues; |
154 | |
} |
155 | |
|
156 | |
public void setRuleBaseValues(RuleBaseValues ruleBaseValues) { |
157 | 0 | this.ruleBaseValues = ruleBaseValues; |
158 | 0 | } |
159 | |
|
160 | |
public String getActionRequestedCd() { |
161 | 0 | return actionRequestedCd; |
162 | |
} |
163 | |
|
164 | |
public void setActionRequestedCd(String actionRequestedCd) { |
165 | 0 | this.actionRequestedCd = actionRequestedCd; |
166 | 0 | } |
167 | |
|
168 | |
public String getId() { |
169 | 0 | return id; |
170 | |
} |
171 | |
|
172 | |
public void setId(String ruleResponsibilityId) { |
173 | 0 | this.id = ruleResponsibilityId; |
174 | 0 | } |
175 | |
public Integer getPriority() { |
176 | 0 | return priority; |
177 | |
} |
178 | |
|
179 | |
public void setPriority(Integer priority) { |
180 | 0 | this.priority = priority; |
181 | 0 | } |
182 | |
|
183 | |
public String getApprovePolicy() { |
184 | 0 | return approvePolicy; |
185 | |
} |
186 | |
|
187 | |
public void setApprovePolicy(String approvePolicy) { |
188 | 0 | this.approvePolicy = approvePolicy; |
189 | 0 | } |
190 | |
|
191 | |
public Object copy(boolean preserveKeys) { |
192 | 0 | RuleResponsibilityBo ruleResponsibilityClone = new RuleResponsibilityBo(); |
193 | 0 | ruleResponsibilityClone.setApprovePolicy(getApprovePolicy()); |
194 | 0 | if (actionRequestedCd != null) { |
195 | 0 | ruleResponsibilityClone.setActionRequestedCd(actionRequestedCd); |
196 | |
} |
197 | 0 | if (id != null && preserveKeys) { |
198 | 0 | ruleResponsibilityClone.setId(id); |
199 | |
} |
200 | |
|
201 | 0 | if (responsibilityId != null) { |
202 | 0 | ruleResponsibilityClone.setResponsibilityId(responsibilityId); |
203 | |
} |
204 | |
|
205 | 0 | if (ruleResponsibilityName != null) { |
206 | 0 | ruleResponsibilityClone.setRuleResponsibilityName(ruleResponsibilityName); |
207 | |
} |
208 | 0 | if (ruleResponsibilityType != null) { |
209 | 0 | ruleResponsibilityClone.setRuleResponsibilityType(ruleResponsibilityType); |
210 | |
} |
211 | 0 | if (priority != null) { |
212 | 0 | ruleResponsibilityClone.setPriority(priority); |
213 | |
} |
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | 0 | return ruleResponsibilityClone; |
224 | |
} |
225 | |
|
226 | |
public String getRuleResponsibilityName() { |
227 | 0 | return ruleResponsibilityName; |
228 | |
} |
229 | |
|
230 | |
public void setRuleResponsibilityName(String ruleResponsibilityName) { |
231 | 0 | this.ruleResponsibilityName = ruleResponsibilityName; |
232 | 0 | } |
233 | |
|
234 | |
public String getRuleResponsibilityType() { |
235 | 0 | return ruleResponsibilityType; |
236 | |
} |
237 | |
|
238 | |
public void setRuleResponsibilityType(String ruleResponsibilityType) { |
239 | 0 | this.ruleResponsibilityType = ruleResponsibilityType; |
240 | 0 | } |
241 | |
|
242 | |
public String getResponsibilityId() { |
243 | 0 | return responsibilityId; |
244 | |
} |
245 | |
public void setResponsibilityId(String responsibilityId) { |
246 | 0 | this.responsibilityId = responsibilityId; |
247 | 0 | } |
248 | |
|
249 | |
public List<RuleDelegationBo> getDelegationRules() { |
250 | 0 | return KEWServiceLocator.getRuleDelegationService().findByResponsibilityId(getResponsibilityId()); |
251 | |
} |
252 | |
|
253 | |
public RuleDelegationBo getDelegationRule(int index) { |
254 | 0 | 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 | 0 | return KewApiConstants.ACTION_REQUEST_CODES.get(getActionRequestedCd()); |
282 | |
} |
283 | |
|
284 | |
public String getRuleResponsibilityTypeDisplayValue() { |
285 | 0 | return KewApiConstants.RULE_RESPONSIBILITY_TYPES.get(getRuleResponsibilityType()); |
286 | |
} |
287 | |
|
288 | |
public boolean equals(Object o) { |
289 | 0 | if (o == null) return false; |
290 | 0 | if (!(o instanceof RuleResponsibilityBo)) return false; |
291 | 0 | RuleResponsibilityBo pred = (RuleResponsibilityBo) o; |
292 | 0 | 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 | 0 | 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 | 0 | if (!isUsingGroup()) { |
313 | 0 | return null; |
314 | |
} |
315 | 0 | return getGroup().getId(); |
316 | |
} |
317 | |
|
318 | |
@Override |
319 | |
public String getPrincipalId() { |
320 | 0 | if (getPrincipal() == null) { |
321 | 0 | return null; |
322 | |
} |
323 | 0 | return getPrincipal().getPrincipalId(); |
324 | |
} |
325 | |
|
326 | |
@Override |
327 | |
public String getRoleName() { |
328 | 0 | return getRole(); |
329 | |
} |
330 | |
|
331 | |
public static org.kuali.rice.kew.api.rule.RuleResponsibility to(RuleResponsibilityBo bo) { |
332 | 0 | if (bo == null) { |
333 | 0 | return null; |
334 | |
} |
335 | 0 | 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 | |
} |