Search in sources :

Example 1 with BatchStatus

use of com.ibm.watson.compare_comply.v1.model.BatchStatus in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testGetBatchWOptions.

@Test
public void testGetBatchWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"function\": \"element_classification\", \"input_bucket_location\": \"inputBucketLocation\", \"input_bucket_name\": \"inputBucketName\", \"output_bucket_location\": \"outputBucketLocation\", \"output_bucket_name\": \"outputBucketName\", \"batch_id\": \"batchId\", \"document_counts\": {\"total\": 5, \"pending\": 7, \"successful\": 10, \"failed\": 6}, \"status\": \"status\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String getBatchPath = "/v1/batches/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the GetBatchOptions model
    GetBatchOptions getBatchOptionsModel = new GetBatchOptions.Builder().batchId("testString").build();
    // Invoke operation with valid options model (positive test)
    Response<BatchStatus> response = compareComplyService.getBatch(getBatchOptionsModel).execute();
    assertNotNull(response);
    BatchStatus responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getBatchPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) GetBatchOptions(com.ibm.watson.compare_comply.v1.model.GetBatchOptions) Test(org.testng.annotations.Test)

Example 2 with BatchStatus

use of com.ibm.watson.compare_comply.v1.model.BatchStatus in project java-sdk by watson-developer-cloud.

the class CompareComply method createBatch.

/**
 * Submit a batch-processing request.
 *
 * <p>Run Compare and Comply methods over a collection of input documents.
 *
 * <p>**Important:** Batch processing requires the use of the [IBM Cloud Object Storage
 * service](https://cloud.ibm.com/docs/cloud-object-storage?topic=cloud-object-storage-about#about-ibm-cloud-object-storage).
 * The use of IBM Cloud Object Storage with Compare and Comply is discussed at [Using batch
 * processing](https://cloud.ibm.com/docs/compare-comply?topic=compare-comply-batching#before-you-batch).
 *
 * @param createBatchOptions the {@link CreateBatchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BatchStatus}
 */
public ServiceCall<BatchStatus> createBatch(CreateBatchOptions createBatchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createBatchOptions, "createBatchOptions cannot be null");
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "createBatch");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    builder.query("function", String.valueOf(createBatchOptions.function()));
    if (createBatchOptions.model() != null) {
        builder.query("model", String.valueOf(createBatchOptions.model()));
    }
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    okhttp3.RequestBody inputCredentialsFileBody = RequestUtils.inputStreamBody(createBatchOptions.inputCredentialsFile(), "application/json");
    multipartBuilder.addFormDataPart("input_credentials_file", "filename", inputCredentialsFileBody);
    multipartBuilder.addFormDataPart("input_bucket_location", createBatchOptions.inputBucketLocation());
    multipartBuilder.addFormDataPart("input_bucket_name", createBatchOptions.inputBucketName());
    okhttp3.RequestBody outputCredentialsFileBody = RequestUtils.inputStreamBody(createBatchOptions.outputCredentialsFile(), "application/json");
    multipartBuilder.addFormDataPart("output_credentials_file", "filename", outputCredentialsFileBody);
    multipartBuilder.addFormDataPart("output_bucket_location", createBatchOptions.outputBucketLocation());
    multipartBuilder.addFormDataPart("output_bucket_name", createBatchOptions.outputBucketName());
    builder.body(multipartBuilder.build());
    ResponseConverter<BatchStatus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BatchStatus>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus)

Example 3 with BatchStatus

use of com.ibm.watson.compare_comply.v1.model.BatchStatus in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testCreateBatchWOptions.

@Test
public void testCreateBatchWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"function\": \"element_classification\", \"input_bucket_location\": \"inputBucketLocation\", \"input_bucket_name\": \"inputBucketName\", \"output_bucket_location\": \"outputBucketLocation\", \"output_bucket_name\": \"outputBucketName\", \"batch_id\": \"batchId\", \"document_counts\": {\"total\": 5, \"pending\": 7, \"successful\": 10, \"failed\": 6}, \"status\": \"status\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String createBatchPath = "/v1/batches";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the CreateBatchOptions model
    CreateBatchOptions createBatchOptionsModel = new CreateBatchOptions.Builder().function("html_conversion").inputCredentialsFile(TestUtilities.createMockStream("This is a mock file.")).inputBucketLocation("testString").inputBucketName("testString").outputCredentialsFile(TestUtilities.createMockStream("This is a mock file.")).outputBucketLocation("testString").outputBucketName("testString").model("contracts").build();
    // Invoke operation with valid options model (positive test)
    Response<BatchStatus> response = compareComplyService.createBatch(createBatchOptionsModel).execute();
    assertNotNull(response);
    BatchStatus responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "POST");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("function"), "html_conversion");
    assertEquals(query.get("model"), "contracts");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, createBatchPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) CreateBatchOptions(com.ibm.watson.compare_comply.v1.model.CreateBatchOptions) Test(org.testng.annotations.Test)

Example 4 with BatchStatus

use of com.ibm.watson.compare_comply.v1.model.BatchStatus in project java-sdk by watson-developer-cloud.

the class CompareComplyTest method testUpdateBatchWOptions.

@Test
public void testUpdateBatchWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"function\": \"element_classification\", \"input_bucket_location\": \"inputBucketLocation\", \"input_bucket_name\": \"inputBucketName\", \"output_bucket_location\": \"outputBucketLocation\", \"output_bucket_name\": \"outputBucketName\", \"batch_id\": \"batchId\", \"document_counts\": {\"total\": 5, \"pending\": 7, \"successful\": 10, \"failed\": 6}, \"status\": \"status\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String updateBatchPath = "/v1/batches/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the UpdateBatchOptions model
    UpdateBatchOptions updateBatchOptionsModel = new UpdateBatchOptions.Builder().batchId("testString").action("rescan").model("contracts").build();
    // Invoke operation with valid options model (positive test)
    Response<BatchStatus> response = compareComplyService.updateBatch(updateBatchOptionsModel).execute();
    assertNotNull(response);
    BatchStatus responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "PUT");
    // Check query
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    // Get query params
    assertEquals(query.get("version"), "testString");
    assertEquals(query.get("action"), "rescan");
    assertEquals(query.get("model"), "contracts");
    // Check request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, updateBatchPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) UpdateBatchOptions(com.ibm.watson.compare_comply.v1.model.UpdateBatchOptions) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) Test(org.testng.annotations.Test)

Example 5 with BatchStatus

use of com.ibm.watson.compare_comply.v1.model.BatchStatus in project java-sdk by watson-developer-cloud.

the class CompareComply method updateBatch.

/**
 * Update a pending or active batch-processing job.
 *
 * <p>Updates a pending or active batch-processing job. You can rescan the input bucket to check
 * for new documents or cancel a job.
 *
 * @param updateBatchOptions the {@link UpdateBatchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BatchStatus}
 */
public ServiceCall<BatchStatus> updateBatch(UpdateBatchOptions updateBatchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateBatchOptions, "updateBatchOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("batch_id", updateBatchOptions.batchId());
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches/{batch_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "updateBatch");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    builder.query("action", String.valueOf(updateBatchOptions.action()));
    if (updateBatchOptions.model() != null) {
        builder.query("model", String.valueOf(updateBatchOptions.model()));
    }
    ResponseConverter<BatchStatus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<BatchStatus>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus)

Aggregations

BatchStatus (com.ibm.watson.compare_comply.v1.model.BatchStatus)7 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.testng.annotations.Test)3 CreateBatchOptions (com.ibm.watson.compare_comply.v1.model.CreateBatchOptions)2 GetBatchOptions (com.ibm.watson.compare_comply.v1.model.GetBatchOptions)2 UpdateBatchOptions (com.ibm.watson.compare_comply.v1.model.UpdateBatchOptions)2 HashMap (java.util.HashMap)2 Batches (com.ibm.watson.compare_comply.v1.model.Batches)1 MultipartBody (okhttp3.MultipartBody)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1