001/*
002 * Copyright 2006 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 */
016package org.kuali.ole.fp.document.web.struts;
017
018import java.util.Properties;
019
020import javax.servlet.http.HttpServletRequest;
021import javax.servlet.http.HttpServletResponse;
022
023import org.apache.log4j.Logger;
024import org.apache.struts.action.ActionForm;
025import org.apache.struts.action.ActionForward;
026import org.apache.struts.action.ActionMapping;
027import org.apache.struts.action.ActionMessage;
028import org.apache.struts.action.ActionMessages;
029import org.kuali.ole.fp.document.CashManagementDocument;
030import org.kuali.ole.sys.OLEConstants;
031import org.kuali.ole.sys.OLEKeyConstants;
032import org.kuali.ole.sys.context.SpringContext;
033import org.kuali.rice.kns.service.DataDictionaryService;
034import org.kuali.rice.kns.web.struts.action.KualiAction;
035import org.kuali.rice.krad.util.UrlFactory;
036
037
038/**
039 * Action class for CashManagementStatusForm
040 */
041public 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(OLEKeyConstants.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(OLEConstants.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(OLEConstants.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(OLEConstants.CASH_MANAGEMENT_DOCUMENT_ACTION, params);
124
125        return new ActionForward(cmActionUrl, true);
126    }
127}