/**
   * All document-load operations get routed through here
   *
   * @see
   *     org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#loadDocument(org.kuali.rice.kns.web.struts.form.KualiDocumentFormBase)
   */
  @Override
  protected void loadDocument(KualiDocumentFormBase kualiDocumentFormBase)
      throws WorkflowException {
    super.loadDocument(kualiDocumentFormBase);

    KualiAccountingDocumentFormBase tform = (KualiAccountingDocumentFormBase) kualiDocumentFormBase;

    // clear out the new accounting line holders
    tform.setNewSourceLine(null);
    tform.setNewTargetLine(null);

    processAccountingLineOverrides(tform);
  }
  /**
   * This action executes an insert of a SourceAccountingLine into a document only after validating
   * the accounting line and checking any appropriate business rules.
   *
   * @param mapping
   * @param form
   * @param request
   * @param response
   * @return ActionForward
   * @throws Exception
   */
  public ActionForward insertSourceLine(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    KualiAccountingDocumentFormBase financialDocumentForm = (KualiAccountingDocumentFormBase) form;
    SourceAccountingLine line = financialDocumentForm.getNewSourceLine();

    // populate chartOfAccountsCode from account number if accounts cant cross chart and Javascript
    // is turned off
    // SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);

    boolean rulePassed = true;
    // DV acct line amount got error during form populate; should not insert this line.
    // KFSUPGRADE-847
    MessageMap msgMap = GlobalVariables.getMessageMap();
    if (msgMap.hasErrors()
        && msgMap.getErrorMessages().keySet().contains("newSourceLine.amount")
        && financialDocumentForm.getDocument() instanceof DisbursementVoucherDocument) {
      rulePassed = false;
    }
    // before we check the regular rules we need to check the sales tax rules
    // TODO: Refactor rules so we no longer have to call this before a copy of the
    // accountingLine
    rulePassed &=
        checkSalesTax(
            (AccountingDocument) financialDocumentForm.getDocument(), line, true, true, 0);
    // check any business rules
    rulePassed &=
        SpringContext.getBean(KualiRuleService.class)
            .applyRules(
                new AddAccountingLineEvent(
                    KFSConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME,
                    financialDocumentForm.getDocument(),
                    line));

    if (rulePassed) {
      // add accountingLine
      SpringContext.getBean(PersistenceService.class).refreshAllNonUpdatingReferences(line);
      insertAccountingLine(true, financialDocumentForm, line);

      // clear the used newTargetLine
      financialDocumentForm.setNewSourceLine(null);
    }

    return mapping.findForward(KFSConstants.MAPPING_BASIC);
  }