Coverage Report - org.kuali.rice.kew.rule.web.DelegateRuleAction
 
Classes in this File Line Coverage Branch Coverage Complexity
DelegateRuleAction
0%
0/14
0%
0/10
3
 
 1  
 /*
 2  
  * Copyright 2007-2009 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.RuleDelegation;
 25  
 import org.kuali.rice.kew.rule.bo.RuleTemplate;
 26  
 import org.kuali.rice.kew.web.KewKualiAction;
 27  
 import org.kuali.rice.kns.util.GlobalVariables;
 28  
 import org.kuali.rice.kns.util.KNSConstants;
 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  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/" + KNSConstants.MAINTENANCE_ACTION + "?" + 
 73  
                         KNSConstants.DISPATCH_REQUEST_PARAMETER + "=" + KNSConstants.START_METHOD + "&" +
 74  
                         KNSConstants.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  
 }