/**
   * Sets the encumbrance code of the line based on the balance type.
   *
   * @param sourceLine - line to set code on
   */
  protected void populateSourceAccountingLineEncumbranceCode(SourceAccountingLine sourceLine) {
    BalanceType selectedBalanceType = getSelectedBalanceType();
    if (ObjectUtils.isNotNull(selectedBalanceType)) {
      selectedBalanceType.refresh();
      sourceLine.setBalanceTyp(selectedBalanceType);
      sourceLine.setBalanceTypeCode(selectedBalanceType.getCode());

      // set the encumbrance update code appropriately
      // KFSMI-5565 remove the default encumbrance code
      // no more default encumbrance code
      //            if
      // (KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE.equals(selectedBalanceType.getCode())) {
      //
      // sourceLine.setEncumbranceUpdateCode(KFSConstants.JOURNAL_VOUCHER_ENCUMBRANCE_UPDATE_CODE_BALANCE_TYPE_EXTERNAL_ENCUMBRANCE);
      //            }
      //            else {
      //                sourceLine.setEncumbranceUpdateCode(null);
      //            }
    } else {
      // it's the first time in, the form will be empty the first time in
      // set up default selection value
      selectedBalanceType = getPopulatedBalanceTypeInstance(KFSConstants.BALANCE_TYPE_ACTUAL);
      setSelectedBalanceType(selectedBalanceType);
      setOriginalBalanceType(selectedBalanceType.getCode());

      sourceLine.setEncumbranceUpdateCode(null);
    }
  }
  /**
   * @see
   *     org.kuali.rice.krad.bo.AccountingLineParserBase#performCustomSourceAccountingLinePopulation(java.util.Map,
   *     org.kuali.rice.krad.bo.SourceAccountingLine, java.lang.String)
   */
  @Override
  protected void performCustomSourceAccountingLinePopulation(
      Map<String, String> attributeValueMap,
      SourceAccountingLine sourceAccountingLine,
      String accountingLineAsString) {
    // chose debit/credit
    String debitValue = attributeValueMap.remove(DEBIT);
    String creditValue = attributeValueMap.remove(CREDIT);
    KualiDecimal debitAmount = null;
    try {
      if (StringUtils.isNotBlank(debitValue)) {
        debitAmount = new KualiDecimal(debitValue);
      }
    } catch (NumberFormatException e) {
      String[] errorParameters = {
        debitValue,
        retrieveAttributeLabel(sourceAccountingLine.getClass(), DEBIT),
        accountingLineAsString
      };
      throw new AccountingLineParserException(
          "invalid (NaN) '" + DEBIT + "=" + debitValue + " for " + accountingLineAsString,
          ERROR_INVALID_PROPERTY_VALUE,
          errorParameters);
    }
    KualiDecimal creditAmount = null;
    try {
      if (StringUtils.isNotBlank(creditValue)) {
        creditAmount = new KualiDecimal(creditValue);
      }
    } catch (NumberFormatException e) {
      String[] errorParameters = {
        creditValue,
        retrieveAttributeLabel(sourceAccountingLine.getClass(), CREDIT),
        accountingLineAsString
      };
      throw new AccountingLineParserException(
          "invalid (NaN) '" + CREDIT + "=" + creditValue + " for " + accountingLineAsString,
          ERROR_INVALID_PROPERTY_VALUE,
          errorParameters);
    }

    KualiDecimal amount = null;
    String debitCreditCode = null;
    if (debitAmount != null && debitAmount.isNonZero()) {
      amount = debitAmount;
      debitCreditCode = KFSConstants.GL_DEBIT_CODE;
    }

    if (creditAmount != null && creditAmount.isNonZero()) {
      amount = creditAmount;
      debitCreditCode = KFSConstants.GL_CREDIT_CODE;
    }

    sourceAccountingLine.setAmount(amount);
    sourceAccountingLine.setDebitCreditCode(debitCreditCode);

    boolean isFinancialOffsetGeneration =
        SpringContext.getBean(BalanceTypeService.class)
            .getBalanceTypeByCode(balanceTypeCode)
            .isFinancialOffsetGenerationIndicator();
    if (isFinancialOffsetGeneration
        || StringUtils.equals(balanceTypeCode, KFSConstants.BALANCE_TYPE_EXTERNAL_ENCUMBRANCE)) {
      super.performCustomSourceAccountingLinePopulation(
          attributeValueMap, sourceAccountingLine, accountingLineAsString);
    }
    sourceAccountingLine.setBalanceTypeCode(balanceTypeCode);
  }