001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.routetemplate.web;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.servlet.http.HttpServletResponse;
021:
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.action.ActionMapping;
025: import org.apache.struts.action.ActionMessages;
026:
027: import edu.iu.uis.eden.KEWServiceLocator;
028: import edu.iu.uis.eden.export.ExportDataSet;
029: import edu.iu.uis.eden.export.ExportFormat;
030: import edu.iu.uis.eden.routetemplate.RuleAttributeService;
031: import edu.iu.uis.eden.routetemplate.RuleDelegationService;
032: import edu.iu.uis.eden.routetemplate.RuleService;
033: import edu.iu.uis.eden.routetemplate.RuleTemplate;
034: import edu.iu.uis.eden.routetemplate.RuleTemplateService;
035: import edu.iu.uis.eden.util.CodeTranslator;
036: import edu.iu.uis.eden.web.WorkflowAction;
037:
038: /**
039: * A Struts Action for interactig with {@link RuleTemplate}s.
040: *
041: * @see RuleTemplateService
042: *
043: * @author rkirkend
044: * @author bmcgough
045: * @author jhopf
046: */
047: public class RuleTemplateAction extends WorkflowAction {
048:
049: public ActionForward start(ActionMapping mapping, ActionForm form,
050: HttpServletRequest request, HttpServletResponse response)
051: throws Exception {
052: return report(mapping, form, request, response);
053: }
054:
055: public ActionMessages establishRequiredState(
056: HttpServletRequest request, ActionForm form)
057: throws Exception {
058: RuleTemplateForm ruleTemplateForm = (RuleTemplateForm) form;
059: ruleTemplateForm.setRuleAttributes(getRuleAttributeService()
060: .findAll());
061: ruleTemplateForm.setActionRequestCodes(CodeTranslator.arLabels);
062: return null;
063: }
064:
065: public ActionForward report(ActionMapping mapping, ActionForm form,
066: HttpServletRequest request, HttpServletResponse response)
067: throws Exception {
068: RuleTemplateForm ruleTemplateForm = (RuleTemplateForm) form;
069: if (ruleTemplateForm.getCurrentRuleTemplateId() != null) {
070: RuleTemplate ruleTemplate = getRuleTemplateService()
071: .findByRuleTemplateId(
072: ruleTemplateForm.getCurrentRuleTemplateId());
073: ruleTemplateForm.setRuleTemplate(ruleTemplate);
074: }
075:
076: // establishRequiredState(request, form);
077: return mapping.findForward("report");
078: }
079:
080: public ActionForward export(ActionMapping mapping, ActionForm form,
081: HttpServletRequest request, HttpServletResponse response)
082: throws Exception {
083: RuleTemplateForm ruleTemplateForm = (RuleTemplateForm) form;
084: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
085: if (ruleTemplateForm.getCurrentRuleTemplateId() != null) {
086: RuleTemplate ruleTemplate = getRuleTemplateService()
087: .findByRuleTemplateId(
088: ruleTemplateForm.getCurrentRuleTemplateId());
089: dataSet.getRuleTemplates().add(ruleTemplate);
090: }
091: return exportDataSet(request, dataSet);
092: }
093:
094: private RuleTemplateService getRuleTemplateService() {
095: return (RuleTemplateService) KEWServiceLocator
096: .getService(KEWServiceLocator.RULE_TEMPLATE_SERVICE);
097: }
098:
099: private RuleService getRuleService() {
100: return (RuleService) KEWServiceLocator
101: .getService(KEWServiceLocator.RULE_SERVICE);
102: }
103:
104: private RuleDelegationService getRuleDelegationService() {
105: return (RuleDelegationService) KEWServiceLocator
106: .getService(KEWServiceLocator.RULE_DELEGATION_SERVICE);
107: }
108:
109: private RuleAttributeService getRuleAttributeService() {
110: return (RuleAttributeService) KEWServiceLocator
111: .getService(KEWServiceLocator.RULE_ATTRIBUTE_SERVICE);
112: }
113: }
|