| 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.doctype.bo.DocumentType; | 
  | 25 |  |  import org.kuali.rice.kew.rule.RuleBaseValues; | 
  | 26 |  |  import org.kuali.rice.kew.rule.bo.RuleTemplate; | 
  | 27 |  |  import org.kuali.rice.kew.service.KEWServiceLocator; | 
  | 28 |  |  import org.kuali.rice.kew.util.Utilities; | 
  | 29 |  |  import org.kuali.rice.kew.web.KewKualiAction; | 
  | 30 |  |  import org.kuali.rice.kns.util.GlobalVariables; | 
  | 31 |  |  import org.kuali.rice.kns.util.KNSConstants; | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 | 0 |  public class RuleAction extends KewKualiAction { | 
  | 37 |  |      private static final String RULE_TEMPLATE_NAME_PROPERTY = "ruleTemplateName"; | 
  | 38 |  |      private static final String DOC_TYPE_NAME_PROPERTY = "ruleTemplateName"; | 
  | 39 |  |   | 
  | 40 |  |      private static final String RULE_TEMPLATE_ERROR = "rule.template.name.required"; | 
  | 41 |  |      private static final String DOCUMENT_TYPE_ERROR = "rule.docType.name.required"; | 
  | 42 |  |   | 
  | 43 |  |      public ActionForward createRule(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { | 
  | 44 | 0 |          RuleForm form = (RuleForm) actionForm; | 
  | 45 | 0 |          if (!validateCreateRule(form)) { | 
  | 46 | 0 |              return mapping.findForward(getDefaultMapping()); | 
  | 47 |  |          } | 
  | 48 | 0 |          return new ActionForward(generateMaintenanceUrl(request, form), true); | 
  | 49 |  |      } | 
  | 50 |  |   | 
  | 51 |  |      public ActionForward clearInitFields(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { | 
  | 52 | 0 |          RuleForm form = (RuleForm) actionForm; | 
  | 53 | 0 |          form.clearSearchableAttributeProperties(); | 
  | 54 | 0 |          return mapping.findForward(getDefaultMapping()); | 
  | 55 |  |      } | 
  | 56 |  |   | 
  | 57 |  |      public ActionForward cancel(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { | 
  | 58 | 0 |          return mapping.findForward("actionTaken"); | 
  | 59 |  |      } | 
  | 60 |  |   | 
  | 61 |  |      protected String generateMaintenanceUrl(HttpServletRequest request, RuleForm form) { | 
  | 62 | 0 |          return getBasePath(request) + "/kr/" + KNSConstants.MAINTENANCE_ACTION + "?" + | 
  | 63 |  |              KNSConstants.DISPATCH_REQUEST_PARAMETER + "=" + KNSConstants.START_METHOD + "&" + | 
  | 64 |  |              KNSConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE + "=" + RuleBaseValues.class.getName() +  "&" + | 
  | 65 |  |              WebRuleUtils.DOCUMENT_TYPE_NAME_PARAM + "=" + form.getDocumentTypeName() + "&" + | 
  | 66 |  |              WebRuleUtils.RULE_TEMPLATE_NAME_PARAM + "=" + form.getRuleTemplateName(); | 
  | 67 |  |      } | 
  | 68 |  |   | 
  | 69 |  |      protected boolean validateCreateRule(RuleForm form) { | 
  | 70 | 0 |          if (Utilities.isEmpty(form.getRuleTemplateName())) { | 
  | 71 | 0 |              GlobalVariables.getMessageMap().putError(RULE_TEMPLATE_NAME_PROPERTY, RULE_TEMPLATE_ERROR); | 
  | 72 |  |          } else { | 
  | 73 | 0 |              RuleTemplate ruleTemplate = KEWServiceLocator.getRuleTemplateService().findByRuleTemplateName(form.getRuleTemplateName().trim()); | 
  | 74 | 0 |              if (ruleTemplate == null) { | 
  | 75 | 0 |                  GlobalVariables.getMessageMap().putError(RULE_TEMPLATE_NAME_PROPERTY, RULE_TEMPLATE_ERROR); | 
  | 76 |  |              } | 
  | 77 |  |          } | 
  | 78 |  |   | 
  | 79 | 0 |          if (Utilities.isEmpty(form.getDocumentTypeName())) { | 
  | 80 | 0 |              GlobalVariables.getMessageMap().putError(DOC_TYPE_NAME_PROPERTY, DOCUMENT_TYPE_ERROR); | 
  | 81 |  |          } else { | 
  | 82 | 0 |              DocumentType docType = KEWServiceLocator.getDocumentTypeService().findByName(form.getDocumentTypeName()); | 
  | 83 | 0 |              if (docType == null) { | 
  | 84 | 0 |                  GlobalVariables.getMessageMap().putError(DOC_TYPE_NAME_PROPERTY, DOCUMENT_TYPE_ERROR); | 
  | 85 |  |              } | 
  | 86 |  |          } | 
  | 87 |  |   | 
  | 88 | 0 |          return GlobalVariables.getMessageMap().isEmpty(); | 
  | 89 |  |      } | 
  | 90 |  |  } |