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  
17  package org.kuali.ole.fp.businessobject;
18  
19  import static org.kuali.ole.sys.OLEKeyConstants.AccountingLineParser.ERROR_INVALID_PROPERTY_VALUE;
20  import static org.kuali.ole.sys.OLEPropertyConstants.ACCOUNT_NUMBER;
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.ORGANIZATION_REFERENCE_ID;
27  import static org.kuali.ole.sys.OLEPropertyConstants.PROJECT_CODE;
28  import static org.kuali.ole.sys.OLEPropertyConstants.SUB_ACCOUNT_NUMBER;
29  
30  import java.util.Map;
31  
32  import org.apache.commons.lang.StringUtils;
33  import org.kuali.ole.sys.OLEConstants;
34  import org.kuali.ole.sys.businessobject.AccountingLineParserBase;
35  import org.kuali.ole.sys.businessobject.SourceAccountingLine;
36  import org.kuali.ole.sys.exception.AccountingLineParserException;
37  import org.kuali.rice.core.api.util.type.KualiDecimal;
38  
39  /**
40   * This class is used to parse an <code>AuxiliaryVocherDocument</code> accounting line.
41   */
42  public class AuxiliaryVoucherAccountingLineParser extends AccountingLineParserBase {
43      protected static final String[] AV_FORMAT = { CHART_OF_ACCOUNTS_CODE, ACCOUNT_NUMBER, SUB_ACCOUNT_NUMBER, FINANCIAL_OBJECT_CODE, FINANCIAL_SUB_OBJECT_CODE, PROJECT_CODE, ORGANIZATION_REFERENCE_ID, DEBIT, CREDIT };
44  
45      /**
46       * Constructs a AuxiliaryVoucherAccountingLineParser.java.
47       */
48      public AuxiliaryVoucherAccountingLineParser() {
49          super();
50      }
51  
52      /**
53       * Populates source accounting lines and sets debit and credit amounts and codes if they exist
54       * 
55       * @see org.kuali.ole.sys.businessobject.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map, org.kuali.ole.sys.businessobject.SourceAccountingLine, java.lang.String)
56       */
57      @Override
58      protected void performCustomSourceAccountingLinePopulation(Map<String, String> attributeValueMap, SourceAccountingLine sourceAccountingLine, String accountingLineAsString) {
59          super.performCustomSourceAccountingLinePopulation(attributeValueMap, sourceAccountingLine, accountingLineAsString);
60  
61          // chose debit/credit
62          String debitValue = attributeValueMap.remove(DEBIT);
63          String creditValue = attributeValueMap.remove(CREDIT);
64          KualiDecimal debitAmount = null;
65          try {
66              if (StringUtils.isNotBlank(debitValue)) {
67                  debitAmount = new KualiDecimal(debitValue);
68              }
69          }
70          catch (NumberFormatException e) {
71              String[] errorParameters = { debitValue, retrieveAttributeLabel(sourceAccountingLine.getClass(), DEBIT), accountingLineAsString };
72              throw new AccountingLineParserException("invalid (NaN) '" + DEBIT + "=" + debitValue + " for " + accountingLineAsString, ERROR_INVALID_PROPERTY_VALUE, errorParameters);
73          }
74          KualiDecimal creditAmount = null;
75          try {
76              if (StringUtils.isNotBlank(creditValue)) {
77                  creditAmount = new KualiDecimal(creditValue);
78              }
79          }
80          catch (NumberFormatException e) {
81              String[] errorParameters = { creditValue, retrieveAttributeLabel(sourceAccountingLine.getClass(), CREDIT), accountingLineAsString };
82              throw new AccountingLineParserException("invalid (NaN) '" + CREDIT + "=" + creditValue + " for " + accountingLineAsString, ERROR_INVALID_PROPERTY_VALUE, errorParameters);
83          }
84  
85          KualiDecimal amount = null;
86          String debitCreditCode = null;
87          if (debitAmount != null && debitAmount.isNonZero()) {
88              amount = debitAmount;
89              debitCreditCode = OLEConstants.GL_DEBIT_CODE;
90          }
91  
92          if (creditAmount != null && creditAmount.isNonZero()) {
93              amount = creditAmount;
94              debitCreditCode = OLEConstants.GL_CREDIT_CODE;
95          }
96  
97          sourceAccountingLine.setAmount(amount);
98          sourceAccountingLine.setDebitCreditCode(debitCreditCode);
99      }
100 
101     /**
102      * @see org.kuali.rice.krad.bo.AccountingLineParserBase#getSourceAccountingLineFormat()
103      */
104     @Override
105     public String[] getSourceAccountingLineFormat() {
106         return removeChartFromFormatIfNeeded(AV_FORMAT);
107     }
108 }