View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.RuleDelegationBo;
25  import org.kuali.rice.kew.rule.bo.RuleTemplateBo;
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   * Struts action for handling the initial Delegate Rule screen for selecting
32   * the parent rule and responsibility. 
33   * 
34   * @author Kuali Rice Team (rice.collab@kuali.org)
35   *
36   */
37  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  		DelegateRuleForm form = (DelegateRuleForm) actionForm;
48  		if (!validateCreateDelegateRule(form)) {
49  			return mapping.findForward(getDefaultMapping());
50  		}
51  		return new ActionForward(generateMaintenanceUrl(request, form), true);
52  	}
53  	
54  	protected boolean validateCreateDelegateRule(DelegateRuleForm form) {
55  		if (form.getParentRule() == null) {
56  			GlobalVariables.getMessageMap().putError(PARENT_RULE_PROPERTY, PARENT_RULE_ERROR);
57  		} else {
58  			RuleTemplateBo ruleTemplate = form.getParentRule().getRuleTemplate();
59  			if (ruleTemplate == null
60  			        || ruleTemplate.getDelegationTemplate() == null) {
61  				GlobalVariables.getMessageMap().putError(PARENT_RULE_PROPERTY, DELEGATE_RULE_INVALID_ERROR);
62  			}
63  		}
64  		if (form.getParentResponsibility() == null) {
65  			GlobalVariables.getMessageMap().putError(PARENT_RESPONSIBILITY_PROPERTY, PARENT_RESPONSIBILITY_ERROR);
66  		}
67  		
68  		return GlobalVariables.getMessageMap().hasNoErrors();
69  	}
70  	
71  	protected String generateMaintenanceUrl(HttpServletRequest request, DelegateRuleForm form) {
72  		return getApplicationBaseUrl() + "/kr/" + KRADConstants.MAINTENANCE_ACTION + "?" +
73  			KRADConstants.DISPATCH_REQUEST_PARAMETER + "=" + KRADConstants.START_METHOD + "&" +
74  			KRADConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE + "=" + RuleDelegationBo.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  }