001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.financial.web.struts.action;
017:
018: import java.util.Properties;
019:
020: import javax.servlet.http.HttpServletRequest;
021: import javax.servlet.http.HttpServletResponse;
022:
023: import org.apache.log4j.Logger;
024: import org.apache.struts.Globals;
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: import org.kuali.core.service.DocumentTypeService;
031: import org.kuali.core.util.UrlFactory;
032: import org.kuali.core.web.struts.action.KualiAction;
033: import org.kuali.kfs.KFSConstants;
034: import org.kuali.kfs.KFSKeyConstants;
035: import org.kuali.kfs.context.SpringContext;
036: import org.kuali.module.financial.document.CashManagementDocument;
037: import org.kuali.module.financial.exceptions.CashDrawerStateException;
038: import org.kuali.module.financial.web.struts.form.CashManagementStatusForm;
039:
040: /**
041: * Action class for CashManagementStatusForm
042: */
043: public class CashManagementStatusAction extends KualiAction {
044: private static Logger LOG = Logger
045: .getLogger(CashManagementStatusAction.class);
046:
047: /**
048: * Default constructor
049: */
050: public CashManagementStatusAction() {
051: }
052:
053: /**
054: * @see org.kuali.core.web.struts.action.KualiAction#execute(org.apache.struts.action.ActionMapping,
055: * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
056: */
057: public ActionForward execute(ActionMapping mapping,
058: ActionForm form, HttpServletRequest request,
059: HttpServletResponse response) throws Exception {
060: // populate with exception values, if any
061: CashManagementStatusForm cform = (CashManagementStatusForm) form;
062: CashDrawerStateException e = (CashDrawerStateException) request
063: .getAttribute(Globals.EXCEPTION_KEY);
064: if (e != null) {
065: cform.setMethodToCall("displayPage");
066:
067: cform.setVerificationUnit(e.getVerificationUnit());
068: cform
069: .setControllingDocumentId(e
070: .getControllingDocumentId());
071: cform.setCurrentDrawerStatus(e.getCurrentDrawerStatus());
072: cform.setDesiredDrawerStatus(e.getDesiredDrawerStatus());
073: }
074:
075: // generate the status message
076: String[] msgParams = { cform.getVerificationUnit(),
077: cform.getControllingDocumentId(),
078: cform.getCurrentDrawerStatus(),
079: cform.getDesiredDrawerStatus() };
080:
081: ActionMessage message = new ActionMessage(
082: KFSKeyConstants.CashDrawer.MSG_CASH_DRAWER_ALREADY_OPEN,
083: msgParams);
084:
085: ActionMessages messages = new ActionMessages();
086: messages.add(ActionMessages.GLOBAL_MESSAGE, message);
087: saveMessages(request, messages);
088:
089: return super .execute(mapping, form, request, response);
090: }
091:
092: /**
093: * Displays the status page. When requests get redirected here, I need to reset the form's methodToCall to something nonblank or
094: * the superclass will try to invoke a method which (probably) doesn't exist in this class.
095: *
096: * @param mapping
097: * @param form
098: * @param request
099: * @param response
100: * @throws Exception
101: */
102: public ActionForward displayPage(ActionMapping mapping,
103: ActionForm form, HttpServletRequest request,
104: HttpServletResponse response) throws Exception {
105: return mapping.findForward(KFSConstants.MAPPING_BASIC);
106: }
107:
108: /**
109: * Returns the user to the index page.
110: *
111: * @param mapping
112: * @param form
113: * @param request
114: * @param response
115: * @throws Exception
116: */
117: public ActionForward returnToIndex(ActionMapping mapping,
118: ActionForm form, HttpServletRequest request,
119: HttpServletResponse response) throws Exception {
120: return mapping.findForward(KFSConstants.MAPPING_CLOSE);
121: }
122:
123: /**
124: * Sends the user to the existing CashManagementDocument.
125: *
126: * @param mapping
127: * @param form
128: * @param request
129: * @param response
130: * @throws Exception
131: */
132: public ActionForward openExisting(ActionMapping mapping,
133: ActionForm form, HttpServletRequest request,
134: HttpServletResponse response) throws Exception {
135: CashManagementStatusForm cform = (CashManagementStatusForm) form;
136:
137: String cmDocTypeName = SpringContext.getBean(
138: DocumentTypeService.class).getDocumentTypeNameByClass(
139: CashManagementDocument.class);
140:
141: Properties params = new Properties();
142: params.setProperty("methodToCall", "docHandler");
143: params.setProperty("command", "displayDocSearchView");
144: params.setProperty("docId", cform.getControllingDocumentId());
145:
146: String cmActionUrl = UrlFactory.parameterizeUrl(
147: KFSConstants.CASH_MANAGEMENT_DOCUMENT_ACTION, params);
148:
149: return new ActionForward(cmActionUrl, true);
150: }
151: }
|