@Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;

    ActionForward fwd = super.execute(mapping, form, request, response);

    AccountsPayableDocumentBase document = (AccountsPayableDocumentBase) baseForm.getDocument();
    boolean foundAccountExpiredWarning = false;
    for (int i = 0; i < KNSGlobalVariables.getMessageList().size(); i++) {
      if (StringUtils.equals(
          KNSGlobalVariables.getMessageList().get(i).getErrorKey(),
          PurapKeyConstants.MESSAGE_CLOSED_OR_EXPIRED_ACCOUNTS_REPLACED)) {
        foundAccountExpiredWarning = true;
      }
    }

    if (!foundAccountExpiredWarning) {
      SpringContext.getBean(AccountsPayableService.class)
          .generateExpiredOrClosedAccountWarning(document);
    }

    return fwd;
  }
  /**
   * Performs refresh of objects after a lookup.
   *
   * @see
   *     org.kuali.rice.kns.web.struts.action.KualiDocumentActionBase#refresh(org.apache.struts.action.ActionMapping,
   *     org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse)
   */
  @Override
  public ActionForward refresh(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    PurchasingAccountsPayableFormBase baseForm = (PurchasingAccountsPayableFormBase) form;

    AccountsPayableDocumentBase document = (AccountsPayableDocumentBase) baseForm.getDocument();

    if (StringUtils.equals(
        baseForm.getRefreshCaller(), VendorConstants.VENDOR_ADDRESS_LOOKUPABLE_IMPL)) {
      if (StringUtils.isNotBlank(
          request.getParameter(
              KFSPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.VENDOR_ADDRESS_ID))) {
        Integer vendorAddressGeneratedId = document.getVendorAddressGeneratedIdentifier();
        VendorAddress refreshVendorAddress = new VendorAddress();
        refreshVendorAddress.setVendorAddressGeneratedIdentifier(vendorAddressGeneratedId);
        refreshVendorAddress =
            (VendorAddress)
                SpringContext.getBean(BusinessObjectService.class).retrieve(refreshVendorAddress);
        document.templateVendorAddress(refreshVendorAddress);
      }
    }

    return super.refresh(mapping, form, request, response);
  }
  /**
   * @see
   *     org.kuali.kfs.sys.web.struts.KualiAccountingDocumentFormBase#populate(javax.servlet.http.HttpServletRequest)
   */
  @Override
  public void populate(HttpServletRequest request) {
    super.populate(request);
    AccountsPayableDocument apDoc = (AccountsPayableDocument) this.getDocument();

    // update po doc
    if (apDoc.getPurchaseOrderIdentifier() != null) {
      apDoc.setPurchaseOrderDocument(
          SpringContext.getBean(PurchaseOrderService.class)
              .getCurrentPurchaseOrder(apDoc.getPurchaseOrderIdentifier()));
    }

    // update counts after populate
    updateItemCounts();
  }