/**
   * @param transDoc
   * @param transForm
   * @param lineSet
   */
  protected void processAccountingLines(
      AccountingDocument transDoc, KualiAccountingDocumentFormBase transForm, String lineSet) {
    // figure out which set of lines we're looking at
    List formLines;
    String pathPrefix;
    boolean source;
    if (lineSet.equals(KFSConstants.SOURCE)) {
      formLines = transDoc.getSourceAccountingLines();
      pathPrefix =
          KFSConstants.DOCUMENT_PROPERTY_NAME
              + "."
              + KFSConstants.EXISTING_SOURCE_ACCT_LINE_PROPERTY_NAME;
      source = true;
    } else {
      formLines = transDoc.getTargetAccountingLines();
      pathPrefix =
          KFSConstants.DOCUMENT_PROPERTY_NAME
              + "."
              + KFSConstants.EXISTING_TARGET_ACCT_LINE_PROPERTY_NAME;
      source = false;
    }

    // find and process corresponding form and baselines
    int index = 0;
    for (Iterator i = formLines.iterator(); i.hasNext(); index++) {
      AccountingLine formLine = (AccountingLine) i.next();

      // update sales tax required attribute for view
      // handleSalesTaxRequired(transDoc, formLine, source, false, index);
      checkSalesTax(transDoc, formLine, source, false, index);
    }
  }
  /** @param transForm */
  protected void processAccountingLineOverrides(KualiAccountingDocumentFormBase transForm) {
    processAccountingLineOverrides(transForm.getNewSourceLine());
    processAccountingLineOverrides(transForm.getNewTargetLine());
    if (transForm.hasDocumentId()) {
      AccountingDocument financialDocument = (AccountingDocument) transForm.getDocument();

      processAccountingLineOverrides(
          financialDocument, financialDocument.getSourceAccountingLines());
      processAccountingLineOverrides(
          financialDocument, financialDocument.getTargetAccountingLines());
    }
  }
  /**
   * This method refreshes the sales tax fields on a refresh or tab toggle so that all the
   * information that was there before is still there after a state change
   *
   * @param form
   */
  protected void refreshSalesTaxInfo(ActionForm form) {
    KualiAccountingDocumentFormBase accountingForm = (KualiAccountingDocumentFormBase) form;
    AccountingDocument document = (AccountingDocument) accountingForm.getDocument();
    List sourceLines = document.getSourceAccountingLines();
    List targetLines = document.getTargetAccountingLines();
    handleSalesTaxRequiredAllLines(accountingForm, sourceLines);
    handleSalesTaxRequiredAllLines(accountingForm, targetLines);

    AccountingLine newTargetLine = accountingForm.getNewTargetLine();
    AccountingLine newSourceLine = accountingForm.getNewSourceLine();
    if (newTargetLine != null) {
      handleSalesTaxRequired(document, newTargetLine, false, true, 0);
    }
    if (newSourceLine != null) {
      handleSalesTaxRequired(document, newSourceLine, true, true, 0);
    }
  }
  /**
   * Main hook point to perform rules check.
   *
   * @see
   *     org.kuali.rice.kns.rules.PromptBeforeValidationBase#doRules(org.kuali.rice.krad.document.Document)
   */
  @Override
  public boolean doPrompts(Document document) {
    AccountingDocument accountingDocument = (AccountingDocument) document;
    List<AccountingLine> accountingLines = accountingDocument.getSourceAccountingLines();
    accountingLines.addAll(accountingDocument.getTargetAccountingLines());

    CapitalAccountingLinesDocumentBase caldb = (CapitalAccountingLinesDocumentBase) document;
    List<CapitalAccountingLines> capitalAccountingLines = caldb.getCapitalAccountingLines();

    if (hasDifferentObjectSubTypes(capitalAccountingLines, accountingLines)) {
      if (!isOkHavingDifferentObjectSubTypes()) {
        event.setActionForwardName(KFSConstants.MAPPING_BASIC);
        return false;
      }
    }

    return true;
  }
  /**
   * If there are line restrictions and the initiator override flag is turned on, we need to disable
   * the copy and error correct buttons since those would result in documents displaying the
   * restricted lines
   *
   * @see
   *     org.kuali.rice.kns.document.authorization.DocumentAuthorizer#getDocumentActions(org.kuali.rice.kns.document.Document,
   *     org.kuali.rice.kim.bo.Person, java.util.Set)
   */
  public Set<String> getDocumentActions(
      Document document, Person user, Set<String> documentActions) {
    Set<String> documentActionsToReturn =
        documentAuthorizer.getDocumentActions(document, user, documentActions);

    AccessSecurityService securityService = SpringContext.getBean(AccessSecurityService.class);

    boolean alwaysAllowInitiatorAccess =
        SpringContext.getBean(ParameterService.class)
            .getIndicatorParameter(
                SecConstants.ACCESS_SECURITY_NAMESPACE_CODE,
                SecConstants.ALL_PARAMETER_DETAIL_COMPONENT,
                SecConstants.SecurityParameterNames.ALWAYS_ALLOW_INITIATOR_LINE_ACCESS_IND);
    if (alwaysAllowInitiatorAccess) {
      // determine if any lines are view restricted
      boolean hasViewRestrictions = false;

      AccountingDocument accountingDocument = (AccountingDocument) document;
      for (Iterator iterator = accountingDocument.getSourceAccountingLines().iterator();
          iterator.hasNext(); ) {
        AccountingLine line = (AccountingLine) iterator.next();
        if (!securityService.canViewDocumentAccountingLine(accountingDocument, line, user)) {
          hasViewRestrictions = true;
          break;
        }
      }

      if (!hasViewRestrictions) {
        for (Iterator iterator = accountingDocument.getTargetAccountingLines().iterator();
            iterator.hasNext(); ) {
          AccountingLine line = (AccountingLine) iterator.next();
          if (!securityService.canViewDocumentAccountingLine(accountingDocument, line, user)) {
            hasViewRestrictions = true;
            break;
          }
        }
      }

      // if we have restrictions then disable copy and error correction
      if (hasViewRestrictions) {
        if (documentActionsToReturn.contains(KNSConstants.KUALI_ACTION_CAN_COPY)) {
          documentActionsToReturn.remove(KNSConstants.KUALI_ACTION_CAN_COPY);
          GlobalVariables.getMessageMap()
              .putInfo(
                  KFSConstants.GLOBAL_ERRORS,
                  SecKeyConstants.MESSAGE_DOCUMENT_COPY_RESTRICTED,
                  (String) null);
        }

        if (documentActionsToReturn.contains(KFSConstants.KFS_ACTION_CAN_ERROR_CORRECT)) {
          documentActionsToReturn.remove(KFSConstants.KFS_ACTION_CAN_ERROR_CORRECT);
          GlobalVariables.getMessageMap()
              .putInfo(
                  KFSConstants.GLOBAL_ERRORS,
                  SecKeyConstants.MESSAGE_DOCUMENT_ERROR_CORRECT_RESTRICTED,
                  (String) null);
        }
      }
    }

    return documentActionsToReturn;
  }