private String findRoleUidByName(List<Role> roles, String roleName) {
    if (roleName == null || roleName.trim().isEmpty()) {
      return null;
    }

    for (Role role : roles) {
      if (roleName.equalsIgnoreCase(role.getName())) {
        return role.getId();
      }
    }

    return null;
  }
 /**
  * Deletes a role from the package.
  *
  * @param packageId
  * @param role
  * @throws EslException
  */
 public void deleteRole(PackageId packageId, Role role) throws EslException {
   String path =
       template
           .urlFor(UrlTemplate.ROLE_ID_PATH)
           .replace("{packageId}", packageId.getId())
           .replace("{roleId}", role.getId())
           .build();
   try {
     client.delete(path);
   } catch (RequestException e) {
     throw new EslServerException("Could not delete role", e);
   } catch (Exception e) {
     throw new EslException("Could not delete role", e);
   }
 }
  private void sendSmsToSigner(PackageId packageId, Role role) {
    String path =
        template
            .urlFor(UrlTemplate.SEND_SMS_TO_SIGNER_PATH)
            .replace("{packageId}", packageId.getId())
            .replace("{roleId}", role.getId())
            .build();

    try {
      client.post(path, null);
    } catch (RequestException e) {
      throw new EslException("Could not send SMS to the signer.", e);
    } catch (Exception e) {
      throw new EslException("Could not send SMS to the signer." + " Exception: " + e.getMessage());
    }
  }
  /**
   * Updates a role from the package.
   *
   * @param packageId
   * @param role
   * @return The updated role
   * @throws EslException
   */
  public Role updateRole(PackageId packageId, Role role) throws EslException {
    String path =
        template
            .urlFor(UrlTemplate.ROLE_ID_PATH)
            .replace("{packageId}", packageId.getId())
            .replace("{roleId}", role.getId())
            .build();

    String roleJson = JacksonUtil.serializeDirty(role);
    String stringResponse;
    try {
      stringResponse = client.put(path, roleJson);
    } catch (RequestException e) {
      throw new EslServerException("Could not update role", e);
    } catch (Exception e) {
      throw new EslException("Could not update role", e);
    }
    return Serialization.fromJson(stringResponse, Role.class);
  }
  private String getSigningUrl(PackageId packageId, Role role) {

    String path =
        template
            .urlFor(UrlTemplate.SIGNER_URL_PATH)
            .replace("{packageId}", packageId.getId())
            .replace("{roleId}", role.getId())
            .build();

    try {
      String response = client.get(path);
      SigningUrl signingUrl = Serialization.fromJson(response, SigningUrl.class);
      return signingUrl.getUrl();
    } catch (RequestException e) {
      throw new EslException("Could not get a signing url.", e);
    } catch (Exception e) {
      throw new EslException("Could not get a signing url." + " Exception: " + e.getMessage());
    }
  }
  /**
   * Adds a signer to the specified package
   *
   * @param packageId The id of the package in which the signer will be added
   * @param signer The signer to be added
   * @return The role id of the signer
   */
  public String addSigner(PackageId packageId, com.silanis.esl.sdk.Signer signer) {
    Role apiPayload =
        new SignerConverter(signer).toAPIRole(UUID.randomUUID().toString().replace("-", ""));

    String path =
        template
            .urlFor(UrlTemplate.ADD_SIGNER_PATH)
            .replace("{packageId}", packageId.getId())
            .build();

    try {
      String json = Serialization.toJson(apiPayload);
      String response = client.post(path, json);
      Role apiRole = Serialization.fromJson(response, Role.class);
      return apiRole.getId();

    } catch (RequestException e) {
      throw new EslServerException("Could not add signer.", e);
    } catch (Exception e) {
      throw new EslException("Could not add signer." + " Exception: " + e.getMessage());
    }
  }
 public void notifySigner(PackageId packageId, GroupId groupId) {
   Role role = findRoleForGroup(packageId, groupId.getId());
   notifySigner(packageId, role.getId());
 }