/**
  * Generate a refName for the authority from the short identifier and display name.
  *
  * <p>All refNames for authorities are generated. If a client supplies a refName, it will be
  * overwritten during create (per this method) or discarded during update (per
  * filterReadOnlyPropertiesForPart).
  *
  * @see #filterReadOnlyPropertiesForPart(Map<String, Object>,
  *     org.collectionspace.services.common.service.ObjectPartType)
  */
 protected void updateRefnameForAuthority(
     DocumentWrapper<DocumentModel> wrapDoc, String schemaName) throws Exception {
   DocumentModel docModel = wrapDoc.getWrappedObject();
   String shortIdentifier =
       (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.SHORT_IDENTIFIER);
   String displayName =
       (String) docModel.getProperty(schemaName, AuthorityJAXBSchema.DISPLAY_NAME);
   MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
   RefName.Authority authority =
       RefName.buildAuthority(
           ctx.getTenantName(), ctx.getServiceName(), shortIdentifier, displayName);
   String refName = authority.toString();
   docModel.setProperty(schemaName, AuthorityJAXBSchema.REF_NAME, refName);
 }
  /*
   * After calling this method successfully, the document model will contain an updated refname and short ID
   * (non-Javadoc)
   * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#getRefName(org.collectionspace.services.common.context.ServiceContext, org.nuxeo.ecm.core.api.DocumentModel)
   */
  @Override
  public RefName.RefNameInterface getRefName(ServiceContext ctx, DocumentModel docModel) {
    RefName.RefNameInterface refname = null;

    try {
      String displayName =
          getPrimaryDisplayName(
              docModel,
              authorityItemCommonSchemaName,
              getItemTermInfoGroupXPathBase(),
              AuthorityItemJAXBSchema.TERM_DISPLAY_NAME);
      if (Tools.isEmpty(displayName)) {
        throw new Exception("The displayName for this authority term was empty or not set.");
      }

      String shortIdentifier =
          (String)
              docModel.getProperty(
                  authorityItemCommonSchemaName, AuthorityItemJAXBSchema.SHORT_IDENTIFIER);
      if (Tools.isEmpty(shortIdentifier)) {
        // We didn't find a short ID in the payload request, so we need to synthesize one.
        shortIdentifier =
            handleDisplayNameAsShortIdentifier(
                docModel); // updates the document model with the new short ID as a side-effect
      }

      String authorityRefBaseName = getAuthorityRefNameBase();
      if (Tools.isEmpty(authorityRefBaseName)) {
        throw new Exception(
            "Could not create the refName for this authority term, because the refName for its authority parent was empty.");
      }

      // Create the items refname using the parent's as a base
      RefName.Authority parentsRefName = RefName.Authority.parse(authorityRefBaseName);
      refname = RefName.buildAuthorityItem(parentsRefName, shortIdentifier, displayName);
      // Now update the document model with the refname value
      String refNameStr = refname.toString();
      docModel.setProperty(
          authorityItemCommonSchemaName,
          AuthorityItemJAXBSchema.REF_NAME,
          refNameStr); // REM - This field is deprecated now that the refName is part of the
                       // collection_space core schema

    } catch (Exception e) {
      logger.error(e.getMessage(), e);
    }

    return refname;
  }