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