1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.web; |
17 | |
|
18 | |
import javax.servlet.http.HttpServletRequest; |
19 | |
import javax.servlet.http.HttpServletResponse; |
20 | |
|
21 | |
import org.apache.struts.action.ActionForm; |
22 | |
import org.apache.struts.action.ActionForward; |
23 | |
import org.apache.struts.action.ActionMapping; |
24 | |
import org.kuali.rice.kew.rule.RuleDelegation; |
25 | |
import org.kuali.rice.kew.rule.bo.RuleTemplate; |
26 | |
import org.kuali.rice.kew.web.KewKualiAction; |
27 | |
import org.kuali.rice.krad.util.GlobalVariables; |
28 | |
import org.kuali.rice.krad.util.KRADConstants; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class DelegateRuleAction extends KewKualiAction { |
38 | |
|
39 | |
private static final String PARENT_RULE_PROPERTY = "parentRuleId"; |
40 | |
private static final String PARENT_RESPONSIBILITY_PROPERTY = "parentResponsibilityId"; |
41 | |
|
42 | |
private static final String PARENT_RULE_ERROR = "delegateRule.parentRule.required"; |
43 | |
private static final String PARENT_RESPONSIBILITY_ERROR = "delegateRule.parentResponsibility.required"; |
44 | |
private static final String DELEGATE_RULE_INVALID_ERROR = "delegateRule.delegateRuleTemplate.invalid"; |
45 | |
|
46 | |
public ActionForward createDelegateRule(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { |
47 | 0 | DelegateRuleForm form = (DelegateRuleForm) actionForm; |
48 | 0 | if (!validateCreateDelegateRule(form)) { |
49 | 0 | return mapping.findForward(getDefaultMapping()); |
50 | |
} |
51 | 0 | return new ActionForward(generateMaintenanceUrl(request, form), true); |
52 | |
} |
53 | |
|
54 | |
protected boolean validateCreateDelegateRule(DelegateRuleForm form) { |
55 | 0 | if (form.getParentRule() == null) { |
56 | 0 | GlobalVariables.getMessageMap().putError(PARENT_RULE_PROPERTY, PARENT_RULE_ERROR); |
57 | |
} else { |
58 | 0 | RuleTemplate ruleTemplate = form.getParentRule().getRuleTemplate(); |
59 | 0 | if (ruleTemplate == null |
60 | |
|| ruleTemplate.getDelegationTemplate() == null) { |
61 | 0 | GlobalVariables.getMessageMap().putError(PARENT_RULE_PROPERTY, DELEGATE_RULE_INVALID_ERROR); |
62 | |
} |
63 | |
} |
64 | 0 | if (form.getParentResponsibility() == null) { |
65 | 0 | GlobalVariables.getMessageMap().putError(PARENT_RESPONSIBILITY_PROPERTY, PARENT_RESPONSIBILITY_ERROR); |
66 | |
} |
67 | |
|
68 | 0 | return GlobalVariables.getMessageMap().hasNoErrors(); |
69 | |
} |
70 | |
|
71 | |
protected String generateMaintenanceUrl(HttpServletRequest request, DelegateRuleForm form) { |
72 | 0 | return getApplicationBaseUrl() + "/kr/" + KRADConstants.MAINTENANCE_ACTION + "?" + |
73 | |
KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.START_METHOD + "&" + |
74 | |
KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE + "=" + RuleDelegation.class.getName() + "&" + |
75 | |
WebRuleUtils.RESPONSIBILITY_ID_PARAM + "=" + form.getParentResponsibilityId() + "&" + |
76 | |
WebRuleUtils.RULE_TEMPLATE_ID_PARAM + "=" + form.getParentRule().getRuleTemplate().getDelegationTemplateId() + "&" + |
77 | |
WebRuleUtils.DOCUMENT_TYPE_NAME_PARAM + "=" + form.getParentRule().getDocTypeName(); |
78 | |
} |
79 | |
|
80 | |
} |