/*
   * This method gets called after the primary update to an authority item has happened.  If the authority item's refName
   * has changed, then we need to updated all the records that use that refname with the new/updated version
   *
   * (non-Javadoc)
   * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#completeUpdate(org.collectionspace.services.common.document.DocumentWrapper)
   */
  public void completeUpdate(DocumentWrapper<DocumentModel> wrapDoc) throws Exception {
    // Must call our super class' version first
    super.completeUpdate(wrapDoc);

    //
    // Look for and update authority references with the updated refName
    //
    if (hasRefNameUpdate() == true) {
      // We have work to do.
      if (logger.isDebugEnabled()) {
        final String EOL = System.getProperty("line.separator");
        logger.debug(
            "Need to find and update references to authority item."
                + EOL
                + "   Old refName"
                + oldRefNameOnUpdate
                + EOL
                + "   New refName"
                + newRefNameOnUpdate);
      }
      ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = getServiceContext();
      RepositoryClient<PoxPayloadIn, PoxPayloadOut> repoClient = getRepositoryClient(ctx);
      RepositoryInstanceInterface repoSession = this.getRepositorySession();

      // Update all the existing records that have a field with the old refName in it
      int nUpdated =
          RefNameServiceUtils.updateAuthorityRefDocs(
              ctx,
              repoClient,
              repoSession,
              oldRefNameOnUpdate,
              newRefNameOnUpdate,
              getRefPropName());

      // Finished so log a message.
      if (logger.isDebugEnabled()) {
        logger.debug("Updated " + nUpdated + " instances of oldRefName to newRefName");
      }
    }
  }