/**
   * Service to update a Bcid's metadata
   *
   * @param doi
   * @param webAddress
   * @param title
   * @param resourceTypeString
   * @param resourceTypesMinusDataset
   * @param identifier
   * @return
   */
  @POST
  @Authenticated
  @Path("/update")
  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  @Produces(MediaType.APPLICATION_JSON)
  public Response bcidUpdate(
      @FormParam("doi") String doi,
      @FormParam("webAddress") String webAddress,
      @FormParam("title") String title,
      @FormParam("resourceType") String resourceTypeString,
      @FormParam("resourceTypesMinusDataset") Integer resourceTypesMinusDataset,
      @FormParam("identifier") String identifier) {
    Hashtable<String, String> metadata;
    Hashtable<String, String> update = new Hashtable<String, String>();
    BcidMinter bcidMinter = new BcidMinter();

    if (identifier == null || identifier.isEmpty()) {
      throw new BadRequestException("You must include an identifier.");
    }
    if (!bcidMinter.userOwnsBcid(identifier, user.getUserId())) {
      throw new BadRequestException(
          "Either the identifier doesn't exist or you are not the owner.");
    }

    // get this BCID's metadata
    metadata = bcidMinter.getBcidMetadata(identifier);

    if (resourceTypesMinusDataset != null && resourceTypesMinusDataset > 0) {
      resourceTypeString = new ResourceTypes().get(resourceTypesMinusDataset).string;
    }

    // compare every field and if they don't match, add them to the update hashtable
    if (doi != null && (!metadata.containsKey("doi") || !metadata.get("doi").equals(doi))) {
      update.put("doi", doi);
    }
    if (webAddress != null
        && (!metadata.containsKey("webAddress")
            || !metadata.get("webAddress").equals(webAddress))) {
      update.put("webAddress", webAddress);
    }
    if (title != null && (!metadata.containsKey("title") || !metadata.get("title").equals(title))) {
      update.put("title", title);
    }
    if (resourceTypeString != null
        && (!metadata.containsKey("resourceType")
            || !metadata.get("resourceType").equals(resourceTypeString))) {
      update.put("resourceTypeString", resourceTypeString);
    }

    if (update.isEmpty()) {
      return Response.ok("{\"success\": \"Nothing needed to be updated.\"}").build();
      // try to update the metadata by calling d.updateBcidMetadata
    } else if (bcidMinter.updateBcidMetadata(update, identifier)) {
      return Response.ok("{\"success\": \"BCID successfully updated.\"}").build();
    } else {
      // if we are here, the Bcid wasn't found
      throw new BadRequestException("Bcid wasn't found");
    }
  }
  /**
   * Return JSON response showing data groups available to this user
   *
   * @return String with JSON response
   */
  @GET
  @Authenticated
  @Path("/list")
  @Produces(MediaType.APPLICATION_JSON)
  public Response bcidList() {
    BcidMinter bcidMinter = new BcidMinter();
    String username = null;
    if (user != null) {
      username = user.getUsername();
    }
    JSONArray response = bcidMinter.bcidList(username);

    return Response.ok(response.toJSONString()).build();
  }