1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.kew.rule.web; |
18 | |
|
19 | |
import java.lang.reflect.InvocationHandler; |
20 | |
import java.lang.reflect.Method; |
21 | |
import java.lang.reflect.Proxy; |
22 | |
import java.util.Iterator; |
23 | |
import java.util.List; |
24 | |
|
25 | |
import org.apache.commons.beanutils.PropertyUtils; |
26 | |
import org.apache.commons.lang.ClassUtils; |
27 | |
import org.apache.struts.action.ActionErrors; |
28 | |
import org.apache.struts.action.ActionMessage; |
29 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
30 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
31 | |
import org.kuali.rice.kew.rule.RuleExtension; |
32 | |
import org.kuali.rice.kew.rule.RuleExtensionValue; |
33 | |
import org.kuali.rice.kew.rule.RuleResponsibility; |
34 | |
import org.kuali.rice.kew.rule.service.RuleService; |
35 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
36 | |
import org.kuali.rice.kew.util.KEWConstants; |
37 | |
import org.kuali.rice.kew.util.Utilities; |
38 | |
import org.kuali.rice.kim.bo.Group; |
39 | |
import org.kuali.rice.kim.bo.entity.KimPrincipal; |
40 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
41 | |
import org.kuali.rice.kns.util.KNSConstants; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class WebRuleResponsibility extends RuleResponsibility { |
52 | |
|
53 | |
private static final long serialVersionUID = -8422695726158274189L; |
54 | |
|
55 | |
private static final String DISPLAY_INLINE = "display:inline"; |
56 | |
|
57 | |
private static final String DISPLAY_NONE = "display:none"; |
58 | |
|
59 | |
private String reviewer; |
60 | |
|
61 | 0 | private String reviewerStyle = ""; |
62 | |
|
63 | 0 | private String personLookupStyle = ""; |
64 | |
|
65 | 0 | private String workgroupLookupStyle = ""; |
66 | |
|
67 | |
private String roleReviewer; |
68 | |
|
69 | 0 | private String roleAreaStyle = ""; |
70 | |
|
71 | 0 | private boolean delegationRulesMaterialized = false; |
72 | |
|
73 | 0 | private boolean showDelegations = false; |
74 | |
|
75 | |
private int numberOfDelegations; |
76 | |
|
77 | 0 | private int index = 0; |
78 | |
|
79 | 0 | private boolean hasDelegateRuleTemplate = false; |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
private String reviewerId; |
86 | |
|
87 | |
public String getReviewerId() { |
88 | 0 | return reviewerId; |
89 | |
} |
90 | |
|
91 | |
public void setReviewerId(String reviewerId) { |
92 | 0 | this.reviewerId = reviewerId; |
93 | 0 | } |
94 | |
|
95 | 0 | public WebRuleResponsibility() { |
96 | 0 | setRuleResponsibilityType(KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID); |
97 | 0 | setApprovePolicy(KEWConstants.APPROVE_POLICY_FIRST_APPROVE); |
98 | 0 | } |
99 | |
|
100 | |
public void initialize() throws Exception { |
101 | 0 | if (getDelegationRules().size() <= Integer.parseInt(Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.RULE_DETAIL_TYPE, KEWConstants.RULE_DELEGATE_LIMIT))) { |
102 | 0 | showDelegations = true; |
103 | |
} |
104 | 0 | setNumberOfDelegations(getDelegationRules().size()); |
105 | 0 | if (delegationRulesMaterialized) { |
106 | 0 | for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { |
107 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
108 | 0 | WebRuleBaseValues webRule = (WebRuleBaseValues) ruleDelegation.getDelegationRuleBaseValues(); |
109 | 0 | webRule.initialize(); |
110 | 0 | } |
111 | |
} |
112 | 0 | establishRequiredState(); |
113 | 0 | } |
114 | |
|
115 | |
private void loadWebValues() throws Exception { |
116 | 0 | if (!Utilities.isEmpty(getRuleResponsibilityName())) { |
117 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(getRuleResponsibilityType())) { |
118 | |
|
119 | |
|
120 | 0 | KimPrincipal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(getRuleResponsibilityName()); |
121 | 0 | setReviewer(principal.getPrincipalName()); |
122 | 0 | setReviewerId(principal.getPrincipalId()); |
123 | 0 | } else if (KEWConstants.RULE_RESPONSIBILITY_GROUP_ID.equals(getRuleResponsibilityType())) { |
124 | |
|
125 | |
|
126 | |
|
127 | 0 | Group group = KIMServiceLocator.getIdentityManagementService(). |
128 | |
getGroup(getRuleResponsibilityName()); |
129 | 0 | setReviewer(group.getGroupName()); |
130 | 0 | setReviewerId(group.getGroupId()); |
131 | 0 | } else if (KEWConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(getRuleResponsibilityType())) { |
132 | 0 | setRoleReviewer(getRuleResponsibilityName()); |
133 | 0 | setReviewer(getResolvedRoleName()); |
134 | |
} |
135 | |
} |
136 | 0 | } |
137 | |
|
138 | |
private void injectWebMembers() throws Exception { |
139 | 0 | DelegationRulesProxy delegationRulesProxy = new DelegationRulesProxy(getDelegationRules()); |
140 | 0 | Class delegationRulesClass = getDelegationRules().getClass(); |
141 | |
|
142 | 0 | Class[] delegationRulesInterfaces = new Class[0]; |
143 | 0 | List<Class> delegationRulesInterfaceList = (List<Class>) ClassUtils.getAllInterfaces(delegationRulesClass); |
144 | 0 | delegationRulesInterfaces = delegationRulesInterfaceList.toArray(delegationRulesInterfaces); |
145 | 0 | ClassLoader delegationRulesClassLoader = getDelegationRules().getClass().getClassLoader(); |
146 | 0 | Object o = Proxy.newProxyInstance(delegationRulesClassLoader, delegationRulesInterfaces, delegationRulesProxy); |
147 | |
|
148 | |
|
149 | 0 | if (Integer.parseInt(Utilities.getKNSParameterValue(KEWConstants.KEW_NAMESPACE, KNSConstants.DetailTypes.RULE_DETAIL_TYPE, KEWConstants.RULE_DELEGATE_LIMIT)) > getDelegationRules().size() || showDelegations) { |
150 | 0 | for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { |
151 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
152 | 0 | WebRuleBaseValues webRule = new WebRuleBaseValues(); |
153 | 0 | webRule.load(ruleDelegation.getDelegationRuleBaseValues()); |
154 | 0 | webRule.edit(ruleDelegation.getDelegationRuleBaseValues()); |
155 | 0 | ruleDelegation.setDelegationRuleBaseValues(webRule); |
156 | 0 | } |
157 | |
} |
158 | 0 | } |
159 | |
|
160 | |
public RuleDelegation addNewDelegation() { |
161 | 0 | RuleDelegation ruleDelegation = new RuleDelegation(); |
162 | 0 | ruleDelegation.setDelegationRuleBaseValues(new WebRuleBaseValues()); |
163 | 0 | ruleDelegation.setDelegationType(KEWConstants.DELEGATION_PRIMARY); |
164 | 0 | ruleDelegation.getDelegationRuleBaseValues().setDelegateRule(Boolean.TRUE); |
165 | 0 | ruleDelegation.getDelegationRuleBaseValues().setDocTypeName(getRuleBaseValues().getDocTypeName()); |
166 | 0 | getDelegationRules().add(ruleDelegation); |
167 | 0 | showDelegations = true; |
168 | 0 | return ruleDelegation; |
169 | |
} |
170 | |
|
171 | |
public String getReviewer() { |
172 | 0 | return reviewer; |
173 | |
} |
174 | |
|
175 | |
public void setReviewer(String reviewer) { |
176 | 0 | this.reviewer = reviewer; |
177 | 0 | } |
178 | |
|
179 | |
public void setWorkgroupId(String workgroupId) { |
180 | 0 | Group workgroup = KIMServiceLocator.getIdentityManagementService().getGroup(workgroupId); |
181 | |
|
182 | 0 | if (workgroup != null) { |
183 | 0 | setReviewer(workgroup.getGroupName()); |
184 | |
} else { |
185 | 0 | setReviewer(""); |
186 | |
} |
187 | 0 | } |
188 | |
|
189 | |
public String getPersonLookupStyle() { |
190 | 0 | return personLookupStyle; |
191 | |
} |
192 | |
|
193 | |
public void setPersonLookupStyle(String personLookupStyle) { |
194 | 0 | this.personLookupStyle = personLookupStyle; |
195 | 0 | } |
196 | |
|
197 | |
public String getReviewerStyle() { |
198 | 0 | return reviewerStyle; |
199 | |
} |
200 | |
|
201 | |
public void setReviewerStyle(String reviewerStyle) { |
202 | 0 | this.reviewerStyle = reviewerStyle; |
203 | 0 | } |
204 | |
|
205 | |
public String getRoleAreaStyle() { |
206 | 0 | return roleAreaStyle; |
207 | |
} |
208 | |
|
209 | |
public void setRoleAreaStyle(String roleAreaLookupStyle) { |
210 | 0 | this.roleAreaStyle = roleAreaLookupStyle; |
211 | 0 | } |
212 | |
|
213 | |
public String getWorkgroupLookupStyle() { |
214 | 0 | return workgroupLookupStyle; |
215 | |
} |
216 | |
|
217 | |
public void setWorkgroupLookupStyle(String workgroupLookupStyle) { |
218 | 0 | this.workgroupLookupStyle = workgroupLookupStyle; |
219 | 0 | } |
220 | |
|
221 | |
public RuleDelegation getDelegationRule(int index) { |
222 | 0 | while (getDelegationRules().size() <= index) { |
223 | 0 | addNewDelegation(); |
224 | |
} |
225 | 0 | return (RuleDelegation) getDelegationRules().get(index); |
226 | |
} |
227 | |
|
228 | |
public int getNumberOfDelegations() { |
229 | 0 | return numberOfDelegations; |
230 | |
} |
231 | |
|
232 | |
public void setNumberOfDelegations(int numberOfDelegations) { |
233 | 0 | this.numberOfDelegations = numberOfDelegations; |
234 | 0 | } |
235 | |
|
236 | |
public boolean isDelegationRulesMaterialized() { |
237 | 0 | return delegationRulesMaterialized; |
238 | |
} |
239 | |
|
240 | |
public void setDelegationRulesMaterialized(boolean isDelegationRulesMaterialized) { |
241 | 0 | this.delegationRulesMaterialized = isDelegationRulesMaterialized; |
242 | 0 | } |
243 | |
|
244 | |
public String getRoleReviewer() { |
245 | 0 | return roleReviewer; |
246 | |
} |
247 | |
|
248 | |
public void setRoleReviewer(String roleReviewer) { |
249 | 0 | this.roleReviewer = roleReviewer; |
250 | 0 | } |
251 | |
|
252 | |
public int getIndex() { |
253 | 0 | return index; |
254 | |
} |
255 | |
|
256 | |
public void setIndex(int index) { |
257 | 0 | this.index = index; |
258 | 0 | } |
259 | |
|
260 | |
public boolean isShowDelegations() { |
261 | 0 | return showDelegations; |
262 | |
} |
263 | |
|
264 | |
public void setShowDelegations(boolean showDelegations) { |
265 | 0 | this.showDelegations = showDelegations; |
266 | 0 | } |
267 | |
|
268 | |
public void establishRequiredState() throws Exception { |
269 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(getRuleResponsibilityType())) { |
270 | 0 | reviewerStyle = DISPLAY_INLINE; |
271 | 0 | personLookupStyle = DISPLAY_INLINE; |
272 | 0 | workgroupLookupStyle = DISPLAY_NONE; |
273 | 0 | roleAreaStyle = DISPLAY_NONE; |
274 | |
} |
275 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_GROUP_ID.equals(getRuleResponsibilityType())) { |
276 | 0 | reviewerStyle = DISPLAY_INLINE; |
277 | 0 | personLookupStyle = DISPLAY_NONE; |
278 | 0 | workgroupLookupStyle = DISPLAY_INLINE; |
279 | 0 | roleAreaStyle = DISPLAY_NONE; |
280 | |
} |
281 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(getRuleResponsibilityType())) { |
282 | 0 | reviewerStyle = DISPLAY_NONE; |
283 | 0 | personLookupStyle = DISPLAY_NONE; |
284 | 0 | workgroupLookupStyle = DISPLAY_NONE; |
285 | 0 | roleAreaStyle = DISPLAY_INLINE; |
286 | |
} |
287 | 0 | loadWebValues(); |
288 | 0 | if (delegationRulesMaterialized) { |
289 | 0 | for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { |
290 | 0 | RuleDelegation delegation = (RuleDelegation) iterator.next(); |
291 | 0 | ((WebRuleBaseValues) delegation.getDelegationRuleBaseValues()).establishRequiredState(); |
292 | 0 | } |
293 | |
} |
294 | 0 | } |
295 | |
|
296 | |
public void validateResponsibility(String keyPrefix, ActionErrors errors) { |
297 | 0 | if (KEWConstants.RULE_RESPONSIBILITY_WORKFLOW_ID.equals(getRuleResponsibilityType())) { |
298 | 0 | boolean invalidUser = Utilities.isEmpty(getReviewer()); |
299 | 0 | if (!invalidUser) |
300 | |
{ |
301 | |
|
302 | 0 | KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(getReviewer()); |
303 | 0 | if( principal != null) |
304 | |
{ |
305 | 0 | setRuleResponsibilityName(principal.getPrincipalId()); |
306 | |
} |
307 | |
else |
308 | |
{ |
309 | 0 | invalidUser = true; |
310 | |
} |
311 | |
} |
312 | 0 | if (invalidUser) { |
313 | 0 | errors.add(keyPrefix + "reviewer", new ActionMessage("routetemplate.ruleservice.user.invalid")); |
314 | |
} |
315 | 0 | } else if (KEWConstants.RULE_RESPONSIBILITY_GROUP_ID.equals(getRuleResponsibilityType())) { |
316 | 0 | boolean invalidWorkgroup = Utilities.isEmpty(getReviewer()); |
317 | |
; |
318 | 0 | if (!invalidWorkgroup) { |
319 | 0 | Group workgroup = KIMServiceLocator.getIdentityManagementService().getGroup(getReviewerId()); |
320 | 0 | if (workgroup == null) { |
321 | 0 | invalidWorkgroup = true; |
322 | |
} else { |
323 | 0 | setRuleResponsibilityName(workgroup.getGroupId()); |
324 | |
} |
325 | 0 | } else { |
326 | 0 | errors.add(keyPrefix + "reviewer", new ActionMessage("routetemplate.ruleservice.workgroup.invalid")); |
327 | |
} |
328 | |
|
329 | 0 | } else if (KEWConstants.RULE_RESPONSIBILITY_ROLE_ID.equals(getRuleResponsibilityType())) { |
330 | 0 | setRuleResponsibilityName(getRoleReviewer()); |
331 | |
} |
332 | |
|
333 | 0 | int delIndex = 0; |
334 | 0 | for (Iterator respIterator = getDelegationRules().iterator(); respIterator.hasNext();) { |
335 | 0 | String delPrefix = keyPrefix + "delegationRule[" + delIndex + "].delegationRuleBaseValues."; |
336 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) respIterator.next(); |
337 | 0 | ((WebRuleBaseValues) ruleDelegation.getDelegationRuleBaseValues()).validateRule(delPrefix, errors); |
338 | 0 | } |
339 | 0 | } |
340 | |
|
341 | |
public void edit(RuleResponsibility ruleResponsibility) throws Exception { |
342 | 0 | load(ruleResponsibility); |
343 | 0 | initialize(); |
344 | 0 | } |
345 | |
|
346 | |
public void load(RuleResponsibility ruleResponsibility) throws Exception { |
347 | 0 | PropertyUtils.copyProperties(this, ruleResponsibility); |
348 | 0 | injectWebMembers(); |
349 | 0 | } |
350 | |
|
351 | |
public void loadDelegations() throws Exception { |
352 | 0 | fetchDelegations(); |
353 | |
|
354 | 0 | for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { |
355 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
356 | 0 | WebRuleBaseValues webRule = new WebRuleBaseValues(); |
357 | 0 | webRule.edit(ruleDelegation.getDelegationRuleBaseValues()); |
358 | 0 | ruleDelegation.setDelegationRuleBaseValues(webRule); |
359 | 0 | } |
360 | 0 | delegationRulesMaterialized = true; |
361 | 0 | populatePreviousVersionIds(); |
362 | 0 | } |
363 | |
|
364 | |
public void populatePreviousVersionIds() { |
365 | 0 | if (delegationRulesMaterialized) { |
366 | 0 | for (Iterator iterator = getDelegationRules().iterator(); iterator.hasNext();) { |
367 | 0 | RuleDelegation delegation = (RuleDelegation) iterator.next(); |
368 | 0 | ((WebRuleBaseValues) delegation.getDelegationRuleBaseValues()).populatePreviousVersionIds(); |
369 | 0 | } |
370 | |
} |
371 | 0 | } |
372 | |
|
373 | |
private void fetchDelegations() { |
374 | 0 | if (getRuleResponsibilityKey() != null) { |
375 | 0 | RuleResponsibility responsibility = getRuleService().findByRuleResponsibilityId(getRuleResponsibilityKey()); |
376 | 0 | if (responsibility == null) { |
377 | 0 | return; |
378 | |
} |
379 | 0 | getDelegationRules().addAll(responsibility.getDelegationRules()); |
380 | |
} |
381 | 0 | } |
382 | |
|
383 | |
public void prepareHiddenDelegationsForRoute() { |
384 | 0 | if (showDelegations) { |
385 | 0 | return; |
386 | |
} |
387 | |
|
388 | 0 | fetchDelegations(); |
389 | |
|
390 | 0 | for (Iterator iter = getDelegationRules().iterator(); iter.hasNext();) { |
391 | 0 | RuleDelegation delegation = (RuleDelegation) iter.next(); |
392 | 0 | delegation.setDelegateRuleId(null); |
393 | 0 | delegation.setVersionNumber(null); |
394 | 0 | delegation.setRuleDelegationId(null); |
395 | |
|
396 | 0 | delegation.setResponsibilityId(null); |
397 | |
|
398 | 0 | RuleBaseValues rule = delegation.getDelegationRuleBaseValues(); |
399 | 0 | rule.setVersionNumber(null); |
400 | 0 | rule.setPreviousVersionId(rule.getRuleBaseValuesId()); |
401 | 0 | rule.setRouteHeaderId(null); |
402 | 0 | rule.setRuleBaseValuesId(null); |
403 | |
|
404 | 0 | for (Iterator iterator = rule.getResponsibilities().iterator(); iterator.hasNext();) { |
405 | 0 | RuleResponsibility responsibility = (RuleResponsibility) iterator.next(); |
406 | 0 | responsibility.setVersionNumber(null); |
407 | 0 | responsibility.setRuleBaseValuesId(null); |
408 | 0 | responsibility.setRuleBaseValues(rule); |
409 | 0 | responsibility.setRuleResponsibilityKey(null); |
410 | 0 | } |
411 | |
|
412 | 0 | for (Iterator iterator = rule.getRuleExtensions().iterator(); iterator.hasNext();) { |
413 | 0 | RuleExtension extension = (RuleExtension) iterator.next(); |
414 | 0 | extension.setLockVerNbr(null); |
415 | 0 | extension.setRuleBaseValues(rule); |
416 | 0 | extension.setRuleBaseValuesId(null); |
417 | 0 | extension.setRuleExtensionId(null); |
418 | |
|
419 | 0 | for (Iterator iter2 = extension.getExtensionValues().iterator(); iter2.hasNext();) { |
420 | 0 | RuleExtensionValue value = (RuleExtensionValue) iter2.next(); |
421 | 0 | value.setExtension(extension); |
422 | 0 | value.setLockVerNbr(null); |
423 | 0 | value.setRuleExtensionId(null); |
424 | 0 | value.setRuleExtensionValueId(null); |
425 | 0 | } |
426 | 0 | } |
427 | 0 | } |
428 | 0 | } |
429 | |
|
430 | |
public boolean isHasDelegateRuleTemplate() { |
431 | 0 | return hasDelegateRuleTemplate; |
432 | |
} |
433 | |
|
434 | |
public void setHasDelegateRuleTemplate(boolean hasDelegateRuleTemplate) { |
435 | 0 | this.hasDelegateRuleTemplate = hasDelegateRuleTemplate; |
436 | 0 | } |
437 | |
|
438 | |
private RuleService getRuleService() { |
439 | 0 | return (RuleService) KEWServiceLocator.getService(KEWServiceLocator.RULE_SERVICE); |
440 | |
} |
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | |
|
448 | |
|
449 | |
private class DelegationRulesProxy implements InvocationHandler, java.io.Serializable { |
450 | |
|
451 | |
private static final long serialVersionUID = 7046323200221509473L; |
452 | |
|
453 | |
private List delegationRules; |
454 | |
|
455 | 0 | public DelegationRulesProxy(List delegationRules) { |
456 | 0 | this.delegationRules = delegationRules; |
457 | 0 | } |
458 | |
|
459 | |
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable { |
460 | 0 | if (!delegationRulesMaterialized && !m.getName().equals("isEmpty") && !m.getName().equals("size")) { |
461 | 0 | for (Iterator iterator = delegationRules.iterator(); iterator.hasNext();) { |
462 | 0 | RuleDelegation ruleDelegation = (RuleDelegation) iterator.next(); |
463 | 0 | WebRuleBaseValues webRule = new WebRuleBaseValues(); |
464 | 0 | webRule.load(ruleDelegation.getDelegationRuleBaseValues()); |
465 | 0 | webRule.establishRequiredState(); |
466 | 0 | ruleDelegation.setDelegationRuleBaseValues(webRule); |
467 | 0 | } |
468 | 0 | delegationRulesMaterialized = true; |
469 | |
|
470 | |
} |
471 | 0 | return m.invoke(delegationRules, args); |
472 | |
} |
473 | |
|
474 | |
} |
475 | |
|
476 | |
} |