View Javadoc
1   /*
2    * Copyright 2005-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  
17  package org.kuali.ole.fp.businessobject;
18  
19  import static org.kuali.ole.sys.OLEPropertyConstants.ACCOUNT_NUMBER;
20  import static org.kuali.ole.sys.OLEPropertyConstants.AMOUNT;
21  import static org.kuali.ole.sys.OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE;
22  import static org.kuali.ole.sys.OLEPropertyConstants.CREDIT;
23  import static org.kuali.ole.sys.OLEPropertyConstants.DEBIT;
24  import static org.kuali.ole.sys.OLEPropertyConstants.FINANCIAL_OBJECT_CODE;
25  import static org.kuali.ole.sys.OLEPropertyConstants.FINANCIAL_SUB_OBJECT_CODE;
26  import static org.kuali.ole.sys.OLEPropertyConstants.OBJECT_TYPE_CODE;
27  import static org.kuali.ole.sys.OLEPropertyConstants.ORGANIZATION_REFERENCE_ID;
28  import static org.kuali.ole.sys.OLEPropertyConstants.PROJECT_CODE;
29  import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_NUMBER;
30  import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_ORIGIN_CODE;
31  import static org.kuali.ole.sys.OLEPropertyConstants.REFERENCE_TYPE_CODE;
32  import static org.kuali.ole.sys.OLEPropertyConstants.SUB_ACCOUNT_NUMBER;
33  
34  import java.util.Map;
35  
36  import org.apache.commons.lang.StringUtils;
37  import org.kuali.ole.coa.service.BalanceTypeService;
38  import org.kuali.ole.sys.OLEConstants;
39  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
40  import org.kuali.ole.sys.context.SpringContext;
41  
42  /**
43   * This class represents a <code>JournalVoucherDocument</code> accounting line parser.
44   */
45  public class JournalVoucherAccountingLineParser extends AuxiliaryVoucherAccountingLineParser {
46      private String balanceTypeCode;
47      protected static final String[] NON_OFFSET_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, AMOUNT };
48      protected static final String[] OFFSET_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
49      protected static final String[] ENCUMBRANCE_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, OBJECT_TYPE_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, REFERENCE_ORIGIN_CODE, REFERENCE_TYPE_CODE, REFERENCE_NUMBER, DEBIT, CREDIT };
50  
51      /**
52       * Constructs a JournalVoucherAccountingLineParser.java.
53       * 
54       * @param balanceTypeCode
55       */
56      public JournalVoucherAccountingLineParser(String balanceTypeCode) {
57          super();
58          this.balanceTypeCode = balanceTypeCode;
59      }
60  
61      /**
62       * @see org.kuali.rice.krad.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map,
63       *      org.kuali.rice.krad.bo.SourceAccountingLine, java.lang.String)
64       */
65      @Override
66      protected void performCustomSourceAccountingLinePopulation(Map<String, String> attributeValueMap, SourceAccountingLine sourceAccountingLine, String accountingLineAsString) {
67  
68          boolean isFinancialOffsetGeneration = SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator();
69          if (isFinancialOffsetGeneration || StringUtils.equals(balanceTypeCode, OLEConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
70              super.performCustomSourceAccountingLinePopulation(attributeValueMap, sourceAccountingLine, accountingLineAsString);
71          }
72          sourceAccountingLine.setBalanceTypeCode(balanceTypeCode);
73      }
74  
75      /**
76       * @see org.kuali.rice.krad.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
77       */
78      @Override
79      public String[] getSourceAccountingLineFormat() {
80          return removeChartFromFormatIfNeeded(selectFormat());
81      }
82  
83      /**
84       * chooses line format based on balance type code
85       * 
86       * @return String []
87       */
88      private String[] selectFormat() {
89          if (StringUtils.equals(balanceTypeCode, OLEConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
90              return ENCUMBRANCE_FORMAT;
91          }
92          else if (SpringContext.getBean(BalanceTypeService.class).getBalanceTypeByCode(balanceTypeCode).isFinancialOffsetGenerationIndicator()) {
93              return OFFSET_FORMAT;
94          }
95          else {
96              return NON_OFFSET_FORMAT;
97          }
98      }
99  }