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.Iterator;
19  import java.util.List;
20  
21  import javax.servlet.http.HttpServletRequest;
22  import javax.servlet.http.HttpServletResponse;
23  
24  import org.apache.struts.action.ActionForm;
25  import org.apache.struts.action.ActionForward;
26  import org.apache.struts.action.ActionMapping;
27  import org.kuali.ole.fp.document.BudgetAdjustmentDocument;
28  import org.kuali.ole.sys.OLEKeyConstants;
29  import org.kuali.ole.sys.businessobject.AccountingLine;
30  import org.kuali.ole.sys.businessobject.AccountingLineOverride;
31  import org.kuali.ole.sys.businessobject.AccountingLineOverride.COMPONENT;
32  import org.kuali.ole.sys.context.SpringContext;
33  import org.kuali.ole.sys.document.AccountingDocument;
34  import org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase;
35  import org.kuali.rice.kew.api.exception.WorkflowException;
36  import org.kuali.rice.kns.util.KNSGlobalVariables;
37  import org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase;
38  import org.kuali.rice.krad.service.PersistenceService;
39  
40  /**
41   * This class handles specific Actions requests for the BudgetAdjustment.
42   */
43  public class BudgetAdjustmentAction extends KualiAccountingDocumentActionBase {
44      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetAdjustmentAction.class);
45  
46      /**
47       * Do initialization for a new budget adjustment
48       * 
49       * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#createDocument(org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase)
50       */
51      @Override
52      protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
53          super.createDocument(kualiDocumentFormBase);
54          ((BudgetAdjustmentDocument) kualiDocumentFormBase.getDocument()).initiateDocument();
55  
56      }
57  
58      /**
59       * Add warning message about copying a document with generated labor benefits.
60       * 
61       * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#copy(org.apache.struts.action.ActionMapping,
62       *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
63       */
64      @Override
65      public ActionForward copy(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
66          KNSGlobalVariables.getMessageList().add(OLEKeyConstants.WARNING_DOCUMENT_BA_COPY_LABOR_BENEFITS);
67          return super.copy(mapping, form, request, response);
68      }
69  
70      @Override
71      protected void processAccountingLineOverrides(AccountingDocument financialDocument, List accountingLines) {
72          if (!accountingLines.isEmpty()) {
73              SpringContext.getBean(PersistenceService.class).retrieveReferenceObjects(accountingLines, AccountingLineOverride.REFRESH_FIELDS);
74  
75              for (Iterator i = accountingLines.iterator(); i.hasNext();) {
76                  AccountingLine line = (AccountingLine) i.next();
77                  processForOutput(financialDocument,line);
78              }
79          }
80      }
81      
82      protected void processForOutput(AccountingDocument financialDocument,AccountingLine line) {
83          AccountingLineOverride fromCurrentCode = AccountingLineOverride.valueOf(line.getOverrideCode());
84          AccountingLineOverride needed = AccountingLineOverride.determineNeededOverrides(financialDocument,line);
85          line.setAccountExpiredOverride(fromCurrentCode.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
86          line.setAccountExpiredOverrideNeeded(needed.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
87          line.setObjectBudgetOverride(false);
88          line.setObjectBudgetOverrideNeeded(false);
89  
90      }
91  
92      
93  }