/**
   * Return a JSON representation of bcids metadata
   *
   * @param bcidId
   * @return
   */
  @GET
  @Path("/metadata/{bcidId}")
  @Produces(MediaType.APPLICATION_JSON)
  public Response run(@PathParam("bcidId") Integer bcidId) {
    String response;
    String username = null;
    if (user != null) {
      username = user.getUsername();
    }
    try {
      Bcid bcid = bcidService.getBcid(bcidId);
      BcidMetadataSchema bcidMetadataSchema =
          new BcidMetadataSchema(
              bcid,
              settingsManager,
              new Identifier(
                  String.valueOf(bcid.getIdentifier()), settingsManager.retrieveValue("divider")));

      JSONRenderer renderer = new JSONRenderer(username, bcid, bcidMetadataSchema, settingsManager);
      response = renderer.render();

    } catch (EmptyResultDataAccessException e) {
      response = "{\"Identifier\":{\"status\":\"not found\"}}";
    }

    return Response.ok(response).build();
  }
  /**
   * Create a data group
   *
   * @param doi
   * @param webAddress
   * @param title
   * @return
   */
  @POST
  @Authenticated
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.APPLICATION_JSON)
  public Response mint(
      @FormParam("doi") String doi,
      @FormParam("webAddress") String webAddress,
      @FormParam("graph") String graph,
      @FormParam("title") String title,
      @FormParam("resourceType") String resourceTypeString,
      @FormParam("resourceTypesMinusDataset") Integer resourceTypesMinusDataset,
      @FormParam("finalCopy") @DefaultValue("false") Boolean finalCopy) {

    // If resourceType is specified by an integer, then use that to set the String resourceType.
    // If the user omits
    try {
      if (resourceTypesMinusDataset != null && resourceTypesMinusDataset > 0) {
        resourceTypeString = new ResourceTypes().get(resourceTypesMinusDataset).uri;
      }
    } catch (IndexOutOfBoundsException e) {
      throw new BadRequestException(
          "BCID System Unable to set resource type",
          "There was an error retrieving the resource type uri. Did you provide a valid resource type?");
    }

    if (resourceTypeString == null || resourceTypeString.isEmpty()) {
      throw new BadRequestException("ResourceType is required");
    }

    // Mint the Bcid
    if (title == null || title.isEmpty()) {
      title = resourceTypeString;
    }

    Bcid.BcidBuilder builder =
        new Bcid.BcidBuilder(resourceTypeString)
            .ezidRequest(Boolean.valueOf(settingsManager.retrieveValue("ezidRequests")))
            .doi(doi)
            .title(title)
            .graph(graph)
            .finalCopy(finalCopy);

    if (!StringUtils.isEmpty(webAddress)) {
      UriComponents webAddressComponents = UriComponentsBuilder.fromUriString(webAddress).build();
      builder.webAddress(webAddressComponents.toUri());
    }

    Bcid bcid = builder.build();
    bcidService.create(bcid, user.getUserId());

    // TODO return the bcid object here
    return Response.ok("{\"identifier\": \"" + bcid.getIdentifier() + "\"}").build();
  }