/**
   * Retrieves validation errors from GlobalVariables MessageMap and appends to the given list of
   * RemotableAttributeError
   *
   * @param validationErrors list to append validation errors
   */
  protected void retrieveValidationErrorsFromGlobalVariables(
      List<RemotableAttributeError> validationErrors) {
    // can we use KualiConfigurationService?  It seemed to be used elsewhere...
    ConfigurationService configurationService =
        CoreApiServiceLocator.getKualiConfigurationService();

    if (GlobalVariables.getMessageMap().hasErrors()) {
      MessageMap deepCopy =
          (MessageMap) SerializationUtils.deepCopy(GlobalVariables.getMessageMap());
      for (String errorKey : deepCopy.getErrorMessages().keySet()) {
        List<ErrorMessage> errorMessages = deepCopy.getErrorMessages().get(errorKey);
        if (CollectionUtils.isNotEmpty(errorMessages)) {
          List<String> errors = new ArrayList<String>();
          for (ErrorMessage errorMessage : errorMessages) {
            // need to materialize the message from it's parameters so we can send it back to the
            // framework
            String error =
                MessageFormat.format(
                    configurationService.getPropertyValueAsString(errorMessage.getErrorKey()),
                    errorMessage.getMessageParameters());
            errors.add(error);
          }
          RemotableAttributeError remotableAttributeError =
              RemotableAttributeError.Builder.create(errorKey, errors).build();
          validationErrors.add(remotableAttributeError);
        }
      }
      // we should now strip the error messages from the map because they have moved to
      // validationErrors
      GlobalVariables.getMessageMap().clearErrorMessages();
    }
  }
 public void populateDeferredMessages(
     ProposalDevelopmentDocumentForm proposalDevelopmentDocumentForm) {
   if (proposalDevelopmentDocumentForm.getDeferredMessages() != null
       && proposalDevelopmentDocumentForm.getDeferredMessages().hasMessages()) {
     MessageMap messageMap = proposalDevelopmentDocumentForm.getDeferredMessages();
     MessageMap currentMessageMap = getGlobalVariableService().getMessageMap();
     messageMap.getErrorMessages().putAll(currentMessageMap.getErrorMessages());
     messageMap.getInfoMessages().putAll(currentMessageMap.getInfoMessages());
     messageMap.getWarningMessages().putAll(currentMessageMap.getWarningMessages());
     getGlobalVariableService().setMessageMap(messageMap);
   }
   proposalDevelopmentDocumentForm.setDeferredMessages(null);
 }
  /**
   * 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);
  }