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.fp.document.web.struts;
017    
018    import java.util.Iterator;
019    import java.util.List;
020    
021    import javax.servlet.http.HttpServletRequest;
022    import javax.servlet.http.HttpServletResponse;
023    
024    import org.apache.struts.action.ActionForm;
025    import org.apache.struts.action.ActionForward;
026    import org.apache.struts.action.ActionMapping;
027    import org.kuali.kfs.fp.document.BudgetAdjustmentDocument;
028    import org.kuali.kfs.sys.KFSKeyConstants;
029    import org.kuali.kfs.sys.businessobject.AccountingLine;
030    import org.kuali.kfs.sys.businessobject.AccountingLineOverride;
031    import org.kuali.kfs.sys.businessobject.AccountingLineOverride.COMPONENT;
032    import org.kuali.kfs.sys.context.SpringContext;
033    import org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase;
034    import org.kuali.rice.kew.exception.WorkflowException;
035    import org.kuali.rice.kns.service.PersistenceService;
036    import org.kuali.rice.kns.util.GlobalVariables;
037    import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
038    
039    /**
040     * This class handles specific Actions requests for the BudgetAdjustment.
041     */
042    public class BudgetAdjustmentAction extends KualiAccountingDocumentActionBase {
043        protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetAdjustmentAction.class);
044    
045        /**
046         * Do initialization for a new budget adjustment
047         * 
048         * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#createDocument(org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase)
049         */
050        @Override
051        protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
052            super.createDocument(kualiDocumentFormBase);
053            ((BudgetAdjustmentDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
054    
055        }
056    
057        /**
058         * Add warning message about copying a document with generated labor benefits.
059         * 
060         * @see org.kuali.kfs.sys.web.struts.KualiAccountingDocumentActionBase#copy(org.apache.struts.action.ActionMapping,
061         *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
062         */
063        @Override
064        public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
065            GlobalVariables.getMessageList().add(KFSKeyConstants.WARNING_DOCUMENT_BA_COPY_LABOR_BENEFITS);
066            return super.copy(mapping, form, request, response);
067        }
068    
069        @Override
070        protected void processAccountingLineOverrides(List accountingLines) {
071            if (!accountingLines.isEmpty()) {
072                SpringContext.getBean(PersistenceService.class).retrieveReferenceObjects(accountingLines, AccountingLineOverride.REFRESH_FIELDS);
073    
074                for (Iterator i = accountingLines.iterator(); i.hasNext();) {
075                    AccountingLine line = (AccountingLine) i.next();
076                    processForOutput(line);
077                }
078            }
079        }
080        
081        protected void processForOutput(AccountingLine line) {
082            AccountingLineOverride fromCurrentCode = AccountingLineOverride.valueOf(line.getOverrideCode());
083            AccountingLineOverride needed = AccountingLineOverride.determineNeededOverrides(line);
084            line.setAccountExpiredOverride(fromCurrentCode.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
085            line.setAccountExpiredOverrideNeeded(needed.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
086            line.setObjectBudgetOverride(false);
087            line.setObjectBudgetOverrideNeeded(false);
088    
089        }
090    
091        
092    }