1 /*
2 * Copyright 2005-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 javax.servlet.http.HttpServletRequest;
19 import javax.servlet.http.HttpServletResponse;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.struts.action.ActionForm;
23 import org.apache.struts.action.ActionForward;
24 import org.apache.struts.action.ActionMapping;
25 import org.kuali.ole.fp.document.AuxiliaryVoucherDocument;
26 import org.kuali.ole.sys.OLEConstants;
27
28
29 /**
30 * This class piggy backs on all of the functionality in the FinancialSystemTransactionalDocumentActionBase but is necessary for this document
31 * type. The Auxiliary Voucher is unique in that it defines several fields that aren't typically used by the other financial
32 * transaction processing eDocs (i.e. external system fields, object type override, credit and debit amounts).
33 */
34 public class AuxiliaryVoucherAction extends VoucherAction {
35 /**
36 * Overrides the parent and then calls the super method after checking to see if the user just changed the voucher type.
37 *
38 * @see org.kuali.rice.kns.web.struts.action.KualiAction#execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
39 * HttpServletResponse response)
40 */
41 @Override
42 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
43 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
44
45 // now check to see if the voucher type was changed and if so, we want to
46 // set the method to call so that the appropriate action can be invoked
47 // did it this way b/c the changing of the type causes the page to re-submit
48 // and we need to process some stuff if it's changed
49 ActionForward returnForward;
50 if (StringUtils.isNotBlank(avForm.getOriginalVoucherType()) && !avForm.getAuxiliaryVoucherDocument().getTypeCode().equals(avForm.getOriginalVoucherType())) {
51 returnForward = super.dispatchMethod(mapping, form, request, response, OLEConstants.AuxiliaryVoucher.CHANGE_VOUCHER_TYPE);
52 }
53 else { // otherwise call the super
54 returnForward = super.execute(mapping, avForm, request, response);
55 }
56 return returnForward;
57 }
58
59 /**
60 * This action method is responsible for clearing the GLPEs for an AV after the voucher type changes, since a voucher type
61 * change makes any previously generated GLPEs inaccurate.
62 *
63 * @param mapping
64 * @param form
65 * @param request
66 * @param response
67 * @return ActionForward
68 * @throws Exception
69 */
70 public ActionForward changeVoucherType(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
71 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
72
73 AuxiliaryVoucherDocument avDoc = avForm.getAuxiliaryVoucherDocument();
74
75 // clear the glpes now
76 avDoc.getGeneralLedgerPendingEntries().clear();
77
78 // make sure to set the original type to the new one now
79 avForm.setOriginalVoucherType(avDoc.getTypeCode());
80
81 return mapping.findForward(OLEConstants.MAPPING_BASIC);
82 }
83
84 /**
85 * @see org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#docHandler(org.apache.struts.action.ActionMapping,
86 * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
87 */
88 @Override
89 public ActionForward docHandler(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
90 ActionForward forward = super.docHandler(mapping, form, request, response);
91
92 // Fix for KULEDOCS-1701, update the original voucher type so that the execute method in
93 // this class will call the right block of code
94 AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
95 AuxiliaryVoucherDocument avDoc = avForm.getAuxiliaryVoucherDocument();
96 avForm.setOriginalVoucherType(avDoc.getTypeCode());
97
98 return forward;
99 }
100 }