001: /*
002: * Copyright 2005-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 javax.servlet.http.HttpServletRequest;
019: import javax.servlet.http.HttpServletResponse;
020:
021: import org.apache.commons.lang.StringUtils;
022: import org.apache.struts.action.ActionForm;
023: import org.apache.struts.action.ActionForward;
024: import org.apache.struts.action.ActionMapping;
025: import org.kuali.core.document.Document;
026: import org.kuali.core.document.authorization.DocumentAuthorizer;
027: import org.kuali.core.service.DocumentAuthorizationService;
028: import org.kuali.kfs.KFSConstants;
029: import org.kuali.kfs.context.SpringContext;
030: import org.kuali.module.financial.document.AuxiliaryVoucherDocument;
031: import org.kuali.module.financial.web.struts.form.AuxiliaryVoucherForm;
032:
033: /**
034: * This class piggy backs on all of the functionality in the KualiTransactionalDocumentActionBase but is necessary for this document
035: * type. The Auxiliary Voucher is unique in that it defines several fields that aren't typically used by the other financial
036: * transaction processing eDocs (i.e. external system fields, object type override, credit and debit amounts).
037: */
038: public class AuxiliaryVoucherAction extends VoucherAction {
039: /**
040: * Overrides the parent and then calls the super method after checking to see if the user just changed the voucher type.
041: *
042: * @see org.kuali.core.web.struts.action.KualiAction#execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
043: * HttpServletResponse response)
044: */
045: @Override
046: public ActionForward execute(ActionMapping mapping,
047: ActionForm form, HttpServletRequest request,
048: HttpServletResponse response) throws Exception {
049: AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
050:
051: // now check to see if the voucher type was changed and if so, we want to
052: // set the method to call so that the appropriate action can be invoked
053: // did it this way b/c the changing of the type causes the page to re-submit
054: // and we need to process some stuff if it's changed
055: ActionForward returnForward;
056: if (StringUtils.isNotBlank(avForm.getOriginalVoucherType())
057: && !avForm.getAuxiliaryVoucherDocument().getTypeCode()
058: .equals(avForm.getOriginalVoucherType())) {
059: returnForward = super .dispatchMethod(mapping, form,
060: request, response,
061: KFSConstants.AuxiliaryVoucher.CHANGE_VOUCHER_TYPE);
062: // must call this here, because execute in the super method will never have control for this particular action
063: // this is called in the parent by super.execute()
064: Document document = avForm.getDocument();
065: DocumentAuthorizer documentAuthorizer = SpringContext
066: .getBean(DocumentAuthorizationService.class)
067: .getDocumentAuthorizer(document);
068: avForm.populateAuthorizationFields(documentAuthorizer);
069: } else { // otherwise call the super
070: returnForward = super .execute(mapping, avForm, request,
071: response);
072: }
073: return returnForward;
074: }
075:
076: /**
077: * This action method is responsible for clearing the GLPEs for an AV after the voucher type changes, since a voucher type
078: * change makes any previously generated GLPEs inaccurate.
079: *
080: * @param mapping
081: * @param form
082: * @param request
083: * @param response
084: * @return ActionForward
085: * @throws Exception
086: */
087: public ActionForward changeVoucherType(ActionMapping mapping,
088: ActionForm form, HttpServletRequest request,
089: HttpServletResponse response) throws Exception {
090: AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
091:
092: AuxiliaryVoucherDocument avDoc = avForm
093: .getAuxiliaryVoucherDocument();
094:
095: // clear the glpes now
096: avDoc.getGeneralLedgerPendingEntries().clear();
097:
098: // make sure to set the original type to the new one now
099: avForm.setOriginalVoucherType(avDoc.getTypeCode());
100:
101: return mapping.findForward(KFSConstants.MAPPING_BASIC);
102: }
103:
104: /**
105: * @see org.kuali.core.web.struts.action.KualiDocumentActionBase#docHandler(org.apache.struts.action.ActionMapping,
106: * org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
107: */
108: @Override
109: public ActionForward docHandler(ActionMapping mapping,
110: ActionForm form, HttpServletRequest request,
111: HttpServletResponse response) throws Exception {
112: ActionForward forward = super .docHandler(mapping, form,
113: request, response);
114:
115: // Fix for KULEDOCS-1701, update the original voucher type so that the execute method in
116: // this class will call the right block of code
117: AuxiliaryVoucherForm avForm = (AuxiliaryVoucherForm) form;
118: AuxiliaryVoucherDocument avDoc = avForm
119: .getAuxiliaryVoucherDocument();
120: avForm.setOriginalVoucherType(avDoc.getTypeCode());
121:
122: return forward;
123: }
124: }
|