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.HashSet;
19  import java.util.Map;
20  import java.util.Set;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.businessobject.AccountingLine;
24  import org.kuali.ole.sys.businessobject.AccountingLineOverride;
25  import org.kuali.ole.sys.businessobject.AccountingLineOverride.COMPONENT;
26  import org.kuali.ole.sys.web.struts.KualiAccountingDocumentFormBase;
27  
28  /**
29   * This class is the form class for the ProcurementCard document. This method extends the parent KualiTransactionalDocumentFormBase
30   * class which contains all of the common form methods and form attributes needed by the Procurment Card document.
31   */
32  public class BudgetAdjustmentForm extends KualiAccountingDocumentFormBase {
33  
34      protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetAdjustmentForm.class);
35  
36      
37      /**
38       * Constructs a BudgetAdjustmentForm instance and sets up the appropriately casted document. Also, the
39       * newSourceLine/newTargetLine need to be the extended
40       * BudgetAdjustmentSourceAccountingLine/BudgetAdjustmentTargetAccountingLine.
41       */
42      public BudgetAdjustmentForm() {
43          super();
44      }
45  
46      @Override
47      protected String getDefaultDocumentTypeName() {
48          return "OLE_BA";
49      }
50      
51      @Override
52      protected void repopulateOverrides(AccountingLine line, String accountingLinePropertyName, Map parameterMap) {
53          determineNeededOverrides(line);
54          if (line.getAccountExpiredOverrideNeeded()) {
55              if (LOG.isDebugEnabled()) {
56                  StringUtils.join(parameterMap.keySet(), "\n");
57              }
58              if (parameterMap.containsKey(accountingLinePropertyName+".accountExpiredOverride.present")) {
59                  line.setAccountExpiredOverride(parameterMap.containsKey(accountingLinePropertyName+".accountExpiredOverride"));
60              }
61          } else {
62              line.setAccountExpiredOverride(false);
63          }
64      }
65      
66      /**
67       * Determines what overrides the given line needs.
68       * 
69       * @param line
70       * @return what overrides the given line needs.
71       */
72      public static AccountingLineOverride determineNeededOverrides(AccountingLine line) {
73          Set neededOverrideComponents = new HashSet();
74          if (AccountingLineOverride.needsExpiredAccountOverride(line.getAccount())) {
75              neededOverrideComponents.add(COMPONENT.EXPIRED_ACCOUNT);
76          }
77         
78          return AccountingLineOverride.valueOf(neededOverrideComponents);
79      }
80  }