/**
   * 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());
    }
  }
Esempio n. 2
0
  public JSONObject createPreference(JSONObject preference) throws JSONException, Exception {
    String accessToken;
    try {
      accessToken = this.getAccessToken();
    } catch (Exception e) {
      JSONObject result = new JSONObject(e.getMessage());
      return result;
    }

    JSONObject preferenceResult =
        RestClient.post("/checkout/preferences?access_token=" + accessToken, preference);
    return preferenceResult;
  }
  /**
   * 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);
    }
  }
Esempio n. 4
0
  public JSONObject createPreapprovalPayment(JSONObject preapproval)
      throws JSONException, Exception {
    String accessToken;
    try {
      accessToken = this.getAccessToken();
    } catch (Exception e) {
      JSONObject result = new JSONObject(e.getMessage());
      return result;
    }

    JSONObject preapprovalResult =
        RestClient.post("/preapproval?access_token=" + accessToken, preapproval);
    return preapprovalResult;
  }
  /**
   * 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);
  }
 /**
  * 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);
   }
 }
 /**
  * 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());
   }
 }
  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());
    }
  }
 @Test(
     dependsOnMethods = {"testEnrollment"},
     description = "Test Android install apps operation.")
 public void testInstallApps() throws Exception {
   JsonObject operationData =
       PayloadGenerator.getJsonPayload(
           Constants.AndroidOperations.OPERATION_PAYLOAD_FILE_NAME,
           Constants.AndroidOperations.INSTALL_APPS_OPERATION);
   JsonArray deviceIds = new JsonArray();
   JsonPrimitive deviceID = new JsonPrimitive(Constants.DEVICE_ID);
   deviceIds.add(deviceID);
   operationData.add(Constants.DEVICE_IDENTIFIERS_KEY, deviceIds);
   HttpResponse response =
       rclient.post(Constants.AndroidOperations.INSTALL_APPS_ENDPOINT, operationData.toString());
   Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
 }
  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());
    }
  }
  /**
   * 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());
    }
  }
  /**
   * 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());
    }
  }
  /**
   * 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());
    }
  }
Esempio n. 14
0
  public JSONObject post(String uri, JSONObject data, Map<String, Object> params)
      throws JSONException, Exception {
    if (params == null) {
      params = new HashMap<String, Object>();
    }
    String accessToken;
    try {
      accessToken = this.getAccessToken();
      params.put("access_token", accessToken);
    } catch (Exception e) {
      JSONObject result = new JSONObject(e.getMessage());
      return result;
    }

    if (!params.isEmpty()) {
      uri += (uri.contains("?") ? "&" : "?") + this.buildQuery(params);
    }

    JSONObject result = RestClient.post(uri, data);
    return result;
  }
Esempio n. 15
0
  /**
   * Get Access Token for API use
   *
   * @throws JSONException
   */
  public String getAccessToken() throws JSONException, Exception {
    if (null != this.ll_access_token) {
      return this.ll_access_token;
    }

    HashMap<String, Object> appClientValues = new HashMap<String, Object>();
    appClientValues.put("grant_type", "client_credentials");
    appClientValues.put("client_id", this.client_id);
    appClientValues.put("client_secret", this.client_secret);

    String appClientValuesQuery = this.buildQuery(appClientValues);

    JSONObject access_data =
        RestClient.post("/oauth/token", appClientValuesQuery, RestClient.MIME_FORM);

    if (access_data.getInt("status") == 200) {
      this.access_data = access_data.getJSONObject("response");
      return this.access_data.optString("access_token");
    } else {
      throw new Exception(access_data.toString());
    }
  }
  /**
   * 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());
    }
  }
  /**
   * 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;
  }