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.module.ld.document.web.struts;
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.kfs.coa.businessobject.BalanceType;
026    import org.kuali.kfs.fp.document.web.struts.JournalVoucherForm;
027    import org.kuali.kfs.module.ld.LaborConstants;
028    import org.kuali.kfs.module.ld.businessobject.LaborLedgerPendingEntry;
029    import org.kuali.kfs.module.ld.businessobject.PositionData;
030    import org.kuali.kfs.sys.KFSConstants;
031    
032    /**
033     * Struts Action Form for the Labor Ledger Journal Voucher. This class piggy backs on all of the functionality in the
034     * FinancialSystemTransactionalDocumentActionBase but is necessary for this document type. The Journal Voucher is unique in that it
035     * defines several fields that aren't typically used by the other financial transaction processing eDocs (i.e. external system
036     * fields, object type override, credit and debit amounts).
037     */
038    public class JournalVoucherAction extends org.kuali.kfs.fp.document.web.struts.JournalVoucherAction {
039    
040        /**
041         * @see org.kuali.rice.kns.web.struts.action.KualiAction#performLookup(org.apache.struts.action.ActionMapping,
042         *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
043         */
044        @Override
045        public ActionForward performLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
046    
047            // parse out the business object name from our methodToCall parameter
048            String fullParameter = (String) request.getAttribute(KFSConstants.METHOD_TO_CALL_ATTRIBUTE);
049            String boClassName = StringUtils.substringBetween(fullParameter, KFSConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, KFSConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL);
050    
051            if (StringUtils.equals(boClassName, LaborLedgerPendingEntry.class.getName())) {
052                String path = super.performLookup(mapping, form, request, response).getPath();
053                path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, LaborConstants.LONG_ROW_TABLE_INRUIRY_ACTION);
054                return new ActionForward(path, true);
055            }
056            else if (StringUtils.equals(boClassName, PositionData.class.getName())) {
057                String path = super.performLookup(mapping, form, request, response).getPath();
058                path = path.replaceFirst(KFSConstants.LOOKUP_ACTION, KFSConstants.GL_MODIFIED_INQUIRY_ACTION);
059                return new ActionForward(path, true);
060            }
061            else {
062                return super.performLookup(mapping, form, request, response);
063            }
064        }
065    
066        /**
067         * Labor JV allows reference fields on all encumbrance types. So only want to give message if a change is being made from a
068         * encumbrance balance type to a nor (or vice-versa).
069         * 
070         * @see org.kuali.kfs.fp.document.web.struts.JournalVoucherAction#determineBalanceTypeEncumbranceChangeMode(org.kuali.kfs.fp.document.web.struts.JournalVoucherForm)
071         */
072        @Override
073        protected int determineBalanceTypeEncumbranceChangeMode(JournalVoucherForm journalVoucherForm) throws Exception {
074            int balanceTypeExternalEncumbranceChangeMode = NO_MODE_CHANGE;
075    
076            // retrieve fully populated balance type instances
077            BalanceType origBalType = getPopulatedBalanceTypeInstance(journalVoucherForm.getOriginalBalanceType());
078            BalanceType newBalType = journalVoucherForm.getSelectedBalanceType();
079    
080            // then deal with external encumbrance changes
081            if (origBalType.isFinBalanceTypeEncumIndicator() && !newBalType.isFinBalanceTypeEncumIndicator()) {
082                balanceTypeExternalEncumbranceChangeMode = EXT_ENCUMB_TO_NON_EXT_ENCUMB;
083            }
084            else if (!origBalType.isFinBalanceTypeEncumIndicator() && newBalType.isFinBalanceTypeEncumIndicator()) {
085                balanceTypeExternalEncumbranceChangeMode = NON_EXT_ENCUMB_TO_EXT_ENCUMB;
086            }
087    
088            return balanceTypeExternalEncumbranceChangeMode;
089        }
090    
091    }