001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.fp.document.web.struts;
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.action.ActionForm;
025 import org.apache.struts.action.ActionForward;
026 import org.apache.struts.action.ActionMapping;
027 import org.apache.struts.action.ActionMessage;
028 import org.apache.struts.action.ActionMessages;
029 import org.kuali.kfs.fp.document.CashManagementDocument;
030 import org.kuali.kfs.sys.KFSConstants;
031 import org.kuali.kfs.sys.KFSKeyConstants;
032 import org.kuali.kfs.sys.context.SpringContext;
033 import org.kuali.rice.kns.service.DataDictionaryService;
034 import org.kuali.rice.kns.util.UrlFactory;
035 import org.kuali.rice.kns.web.struts.action.KualiAction;
036
037
038 /**
039 * Action class for CashManagementStatusForm
040 */
041 public class CashManagementStatusAction extends KualiAction {
042 private static Logger LOG = Logger.getLogger(CashManagementStatusAction.class);
043
044 /**
045 * Default constructor
046 */
047 public CashManagementStatusAction() {
048 }
049
050
051 /**
052 * @see org.kuali.rice.kns.web.struts.action.KualiAction#execute(org.apache.struts.action.ActionMapping,
053 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
054 */
055 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
056 // populate with exception values, if any
057 CashManagementStatusForm cform = (CashManagementStatusForm) form;
058
059 if (cform.getMethodToCall().equals("docHandler")) {
060 cform.setMethodToCall("displayPage");
061 }
062
063 // generate the status message
064 String[] msgParams = { cform.getVerificationUnit(), cform.getControllingDocumentId(), cform.getCurrentDrawerStatus(), cform.getDesiredDrawerStatus() };
065
066 ActionMessage message = new ActionMessage(KFSKeyConstants.CashDrawer.MSG_CASH_DRAWER_ALREADY_OPEN, msgParams);
067
068 ActionMessages messages = new ActionMessages();
069 messages.add(ActionMessages.GLOBAL_MESSAGE, message);
070 saveMessages(request, messages);
071
072 return super.execute(mapping, form, request, response);
073 }
074
075 /**
076 * Displays the status page. When requests get redirected here, I need to reset the form's methodToCall to something nonblank or
077 * the superclass will try to invoke a method which (probably) doesn't exist in this class.
078 *
079 * @param mapping
080 * @param form
081 * @param request
082 * @param response
083 * @throws Exception
084 */
085 public ActionForward displayPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
086 return mapping.findForward(KFSConstants.MAPPING_BASIC);
087 }
088
089 /**
090 * Returns the user to the index page.
091 *
092 * @param mapping
093 * @param form
094 * @param request
095 * @param response
096 * @throws Exception
097 */
098 public ActionForward returnToIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
099 return mapping.findForward(KFSConstants.MAPPING_CLOSE);
100 }
101
102
103 /**
104 * Sends the user to the existing CashManagementDocument.
105 *
106 * @param mapping
107 * @param form
108 * @param request
109 * @param response
110 * @throws Exception
111 */
112 public ActionForward openExisting(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
113 CashManagementStatusForm cform = (CashManagementStatusForm) form;
114
115 String cmDocTypeName = SpringContext.getBean(DataDictionaryService.class).getValidDocumentTypeNameByClass(CashManagementDocument.class);
116
117 Properties params = new Properties();
118 params.setProperty("methodToCall", "docHandler");
119 params.setProperty("command", "displayDocSearchView");
120 params.setProperty("docId", cform.getControllingDocumentId());
121
122
123 String cmActionUrl = UrlFactory.parameterizeUrl(KFSConstants.CASH_MANAGEMENT_DOCUMENT_ACTION, params);
124
125 return new ActionForward(cmActionUrl, true);
126 }
127 }