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.log4j.Logger;
023: import org.apache.struts.Globals;
024: import org.apache.struts.action.ActionErrors;
025: import org.apache.struts.action.ActionForm;
026: import org.apache.struts.action.ActionForward;
027: import org.apache.struts.action.ActionMapping;
028: import org.apache.struts.action.ActionMessage;
029: import org.apache.struts.action.ActionMessages;
030:
031: import edu.iu.uis.eden.KEWServiceLocator;
032: import edu.iu.uis.eden.export.ExportDataSet;
033: import edu.iu.uis.eden.export.ExportFormat;
034: import edu.iu.uis.eden.routetemplate.RuleAttribute;
035: import edu.iu.uis.eden.web.WorkflowAction;
036:
037: /**
038: * A Struts Action for generating a report for {@link RuleAttribute}s.
039: *
040: * @author ahamid
041: */
042: public class RuleAttributeReportAction extends WorkflowAction {
043: private static final Logger LOG = Logger
044: .getLogger(RuleAttributeReportAction.class);
045:
046: public ActionForward start(ActionMapping mapping, ActionForm form,
047: HttpServletRequest request, HttpServletResponse response)
048: throws Exception {
049: LOG.debug("start");
050: return mapping.findForward("basic");
051: }
052:
053: public ActionForward export(ActionMapping mapping, ActionForm form,
054: HttpServletRequest request, HttpServletResponse response)
055: throws Exception {
056: RuleAttributeReportForm rarform = (RuleAttributeReportForm) form;
057: ExportDataSet dataSet = new ExportDataSet(ExportFormat.XML);
058: dataSet.getRuleAttributes().add(rarform.getRuleAttribute());
059: return exportDataSet(request, dataSet);
060: }
061:
062: public ActionMessages establishRequiredState(
063: HttpServletRequest request, ActionForm form)
064: throws Exception {
065: LOG.info("establishRequiredState");
066: RuleAttributeReportForm rarform = (RuleAttributeReportForm) form;
067: Long id = rarform.getRuleAttributeId();
068: /* Nice inconsistency observed: org.apache.struts.action.MESSAGE is set regardless of whether there are any
069: * messages (or at least any set here), but org.apache.struts.action.ACTION_MESSAGE IS set when there is a
070: * message set here.
071: * On the other hand, org.apache.struts.action.ERROR, is only set when and only when there is an error defined here,
072: * and no such ACTION_ERROR is ever set.
073: * I'm using those in a c:choose block to determine output because I have not found a better way to determine whether
074: * there are any messages on the request (at least not and be able to render an alternative, logic:messagesPresent doesn't
075: * have any "otherwise" clause).
076: */
077: if (id == null) {
078: LOG.error("id not specified");
079: ActionErrors errors = new ActionErrors();
080: errors.add(Globals.ERROR_KEY, new ActionMessage(
081: "ruleAttributeReport.idNotSpecified"));
082: saveErrors(request, errors);
083: // impedence mismatch here: have to return ActionMessages so that control flow does not continue
084: // but that will result in errors being saved under messages key *shrug*
085: return errors;
086: //throw new WorkflowException("RuleAttribute id not specified");
087: }
088: RuleAttribute ra = KEWServiceLocator.getRuleAttributeService()
089: .findByRuleAttributeId(id);
090: if (ra == null) {
091: LOG.error("rule attribute not found");
092: ActionErrors errors = new ActionErrors();
093: errors.add(Globals.ERROR_KEY, new ActionMessage(
094: "ruleAttributeReport.idNotFound", id));
095: saveErrors(request, errors);
096: // impedence mismatch here: have to return ActionMessages so that control flow does not continue
097: // but that will result in errors being saved under messages key *shrug*
098: return errors;
099: //throw new WorkflowException("RuleAttribute '" + id + "' not found");
100: }
101: rarform.setRuleAttribute(ra);
102: return null;
103: }
104: }
|