View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.fp.document.web.struts;
17  
18  import java.util.Properties;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  
23  import org.apache.log4j.Logger;
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.apache.struts.action.ActionMessage;
28  import org.apache.struts.action.ActionMessages;
29  import org.kuali.ole.fp.document.CashManagementDocument;
30  import org.kuali.ole.sys.OLEConstants;
31  import org.kuali.ole.sys.OLEKeyConstants;
32  import org.kuali.ole.sys.context.SpringContext;
33  import org.kuali.rice.kns.service.DataDictionaryService;
34  import org.kuali.rice.kns.web.struts.action.KualiAction;
35  import org.kuali.rice.krad.util.UrlFactory;
36  
37  
38  /**
39   * Action class for CashManagementStatusForm
40   */
41  public class CashManagementStatusAction extends KualiAction {
42      private static Logger LOG = Logger.getLogger(CashManagementStatusAction.class);
43  
44      /**
45       * Default constructor
46       */
47      public CashManagementStatusAction() {
48      }
49  
50  
51      /**
52       * @see org.kuali.rice.kns.web.struts.action.KualiAction#execute(org.apache.struts.action.ActionMapping,
53       *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
54       */
55      public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
56          // populate with exception values, if any
57          CashManagementStatusForm cform = (CashManagementStatusForm) form;
58  
59          if (cform.getMethodToCall().equals("docHandler")) {
60              cform.setMethodToCall("displayPage");
61          }
62  
63          // generate the status message
64          String[] msgParams = { cform.getVerificationUnit(), cform.getControllingDocumentId(), cform.getCurrentDrawerStatus(), cform.getDesiredDrawerStatus() };
65  
66          ActionMessage message = new ActionMessage(OLEKeyConstants.CashDrawer.MSG_CASH_DRAWER_ALREADY_OPEN, msgParams);
67  
68          ActionMessages messages = new ActionMessages();
69          messages.add(ActionMessages.GLOBAL_MESSAGE, message);
70          saveMessages(request, messages);
71  
72          return super.execute(mapping, form, request, response);
73      }
74  
75      /**
76       * Displays the status page. When requests get redirected here, I need to reset the form's methodToCall to something nonblank or
77       * the superclass will try to invoke a method which (probably) doesn't exist in this class.
78       * 
79       * @param mapping
80       * @param form
81       * @param request
82       * @param response
83       * @throws Exception
84       */
85      public ActionForward displayPage(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
86          return mapping.findForward(OLEConstants.MAPPING_BASIC);
87      }
88  
89      /**
90       * Returns the user to the index page.
91       * 
92       * @param mapping
93       * @param form
94       * @param request
95       * @param response
96       * @throws Exception
97       */
98      public ActionForward returnToIndex(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
99          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 }