コード例 #1
0
  /**
   * Create Fast Track Package.
   *
   * @param packageId The id of the package to start FastTrack
   * @param signers The signers to get the signing url
   * @return The signing url
   */
  public String startFastTrack(PackageId packageId, List<FastTrackSigner> signers) {
    String token = getFastTrackToken(packageId, true);
    String path =
        template.urlFor(UrlTemplate.START_FAST_TRACK_PATH).replace("{token}", token).build();

    List<FastTrackRole> roles = new ArrayList<FastTrackRole>();
    for (FastTrackSigner signer : signers) {
      FastTrackRole role =
          FastTrackRoleBuilder.newRoleWithId(signer.getId())
              .withName(signer.getId())
              .withSigner(signer)
              .build();
      roles.add(role);
    }

    String json = Serialization.toJson(roles);
    try {
      String response = client.post(path, json);
      SigningUrl signingUrl = Serialization.fromJson(response, SigningUrl.class);
      return signingUrl.getUrl();
    } catch (RequestException e) {
      throw new EslException("Could not start fast track.", e);
    } catch (Exception e) {
      throw new EslException("Could not start fast track." + " Exception: " + e.getMessage());
    }
  }
コード例 #2
0
  /**
   * Creates a package with roles.
   *
   * @param aPackage
   * @return PackageId
   * @throws com.silanis.esl.sdk.EslException
   */
  public PackageId createPackage(Package aPackage) throws EslException {
    String path = template.urlFor(UrlTemplate.PACKAGE_PATH).build();
    String packageJson = Serialization.toJson(aPackage);

    try {
      String response = client.post(path, packageJson);
      return Serialization.fromJson(response, PackageId.class);
    } catch (RequestException e) {
      throw new EslServerException("Could not create a new package", e);
    } catch (Exception e) {
      throw new EslException("Could not create a new package", e);
    }
  }
コード例 #3
0
  /**
   * Adds a role to the package.
   *
   * @param packageId
   * @param role
   * @return The role added
   * @throws EslException
   */
  public Role addRole(PackageId packageId, Role role) throws EslException {
    String path =
        template.urlFor(UrlTemplate.ROLE_PATH).replace("{packageId}", packageId.getId()).build();

    String roleJson = JacksonUtil.serializeDirty(role);
    String stringResponse;
    try {
      stringResponse = client.post(path, roleJson);
    } catch (RequestException e) {
      throw new EslServerException("Could not add role.", e);
    } catch (Exception e) {
      throw new EslException("Could not add role.", e);
    }
    return Serialization.fromJson(stringResponse, Role.class);
  }
コード例 #4
0
 /**
  * Sends the package.
  *
  * @param packageId
  * @throws EslException
  */
 public void sendPackage(PackageId packageId) throws EslException {
   String path =
       template
           .urlFor(UrlTemplate.PACKAGE_ID_PATH)
           .replace("{packageId}", packageId.getId())
           .build();
   String json = "{\"status\":\"SENT\"}";
   try {
     client.post(path, json);
   } catch (RequestException e) {
     throw new EslServerException("Could not send the package.", e);
   } catch (Exception e) {
     throw new EslException("Could not send the package.", e);
   }
 }
コード例 #5
0
 /**
  * Unlock a signer which has been locked out due to too many failed authentication attempts.
  *
  * @param signerId If not null, the id of the signer who's status we are to retrieve
  */
 public void unlockSigner(PackageId packageId, String signerId) {
   String path =
       template
           .urlFor(UrlTemplate.ROLE_UNLOCK_PATH)
           .replace("{packageId}", packageId.getId())
           .replace("{roleId}", signerId)
           .build();
   try {
     client.post(path, null);
   } catch (RequestException e) {
     throw new EslException("Could not unlock signer.", e);
   } catch (Exception e) {
     throw new EslException("Could not unlock signer." + " Exception: " + e.getMessage());
   }
 }
コード例 #6
0
  private void notifySigner(PackageId packageId, String roleId) {
    String path =
        template
            .urlFor(UrlTemplate.NOTIFY_ROLE_PATH)
            .replace("{packageId}", packageId.getId())
            .replace("{roleId}", roleId)
            .build();

    try {
      client.post(path, null);
    } catch (RequestException e) {
      throw new EslServerException("Could not send email notification.", e);
    } catch (Exception e) {
      throw new EslException("Could not send email notification.  " + e.getMessage());
    }
  }
コード例 #7
0
  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());
    }
  }
コード例 #8
0
  /**
   * Archive the specified package.
   *
   * @param packageId The id of the package to be archived
   */
  public void archive(PackageId packageId) {
    String path =
        template
            .urlFor(UrlTemplate.PACKAGE_ID_PATH)
            .replace("{packageId}", packageId.getId())
            .build();

    String json = "{\"status\":\"ARCHIVED\"}";
    try {
      client.post(path, json);
    } catch (RequestException e) {
      throw new EslServerException("Unable to archive the package.", e);
    } catch (Exception e) {
      e.printStackTrace();
      throw new EslException("Unable to archive the package. Exception: " + e.getMessage());
    }
  }
コード例 #9
0
  /**
   * Upload documents with external content to the package.
   *
   * @param packageId
   */
  public void addDocumentWithExternalContent(
      String packageId, List<com.silanis.esl.sdk.Document> providerDocuments) {
    String path =
        template.urlFor(UrlTemplate.DOCUMENT_PATH).replace("{packageId}", packageId).build();

    List<Document> apiDocuments = new ArrayList<Document>();
    for (com.silanis.esl.sdk.Document document : providerDocuments) {
      apiDocuments.add(new DocumentConverter(document).toAPIDocumentMetadata());
    }
    try {
      String json = Serialization.toJson(apiDocuments);
      client.post(path, json);
    } catch (RequestException e) {
      throw new EslServerException("Could not upload the documents.", e);
    } catch (Exception e) {
      throw new EslException("Could not upload the documents." + " Exception: " + e.getMessage());
    }
  }
コード例 #10
0
  /**
   * Notifies the specified signer by email, including a custom message.
   *
   * @param packageId The id of the package containing the signer to be notified
   * @param signerEmail The email of the signer to be notified
   * @param message The custom message to be included in the email sent as notification to the
   *     signer
   */
  public void notifySigner(PackageId packageId, String signerEmail, String message) {
    String path =
        template
            .urlFor(UrlTemplate.CUSTOM_NOTIFICATIONS_PATH)
            .replace("{packageId}", packageId.getId())
            .build();

    Map<String, Object> jsonMap = new HashMap<String, Object>();
    jsonMap.put("email", signerEmail);
    jsonMap.put("message", message);

    try {
      String payload = JacksonUtil.serialize(jsonMap);
      client.post(path, payload);
    } catch (RequestException e) {
      throw new EslException("Could not send email notification to signer.", e);
    } catch (Exception e) {
      throw new EslException(
          "Could not send email notification to signer. Exception: " + e.getMessage());
    }
  }
コード例 #11
0
  /**
   * 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());
    }
  }
コード例 #12
0
  /**
   * Create a new package based on an existing template.
   *
   * @param packageId
   * @param aPackage
   * @return PackageId
   */
  public PackageId createPackageFromTemplate(PackageId packageId, Package aPackage) {
    String path =
        template
            .urlFor(UrlTemplate.TEMPLATE_PATH)
            .replace("{packageId}", packageId.getId())
            .build();

    List<Role> roles = aPackage.getRoles();

    aPackage.setRoles(Collections.<Role>emptyList());

    String packageJson = Serialization.toJson(aPackage);
    PackageId newPackageId = null;
    try {

      String response = client.post(path, packageJson);

      newPackageId = Serialization.fromJson(response, PackageId.class);
    } catch (RequestException e) {
      throw new EslServerException("Could not create a new package", e);
    } catch (Exception e) {
      throw new EslException("Could not create a new package", e);
    }

    Package createdPackage = getApiPackage(newPackageId.getId());

    for (Role role : roles) {
      String roleUid = findRoleUidByName(createdPackage.getRoles(), role.getName());

      if (roleUid == null) {
        continue;
      }

      role.setId(roleUid);
      updateRole(newPackageId, role);
    }

    return newPackageId;
  }