Search in sources :

Example 1 with Batches

use of com.ibm.watson.compare_comply.v1.model.Batches 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 Batches

use of com.ibm.watson.compare_comply.v1.model.Batches 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 Batches

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

the class CompareComply method listBatches.

/**
 * List submitted batch-processing jobs.
 *
 * <p>Lists batch-processing jobs submitted by users.
 *
 * @param listBatchesOptions the {@link ListBatchesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Batches}
 */
public ServiceCall<Batches> listBatches(ListBatchesOptions listBatchesOptions) {
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "listBatches");
    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));
    ResponseConverter<Batches> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Batches>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) Batches(com.ibm.watson.compare_comply.v1.model.Batches)

Example 4 with Batches

use of com.ibm.watson.compare_comply.v1.model.Batches 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 5 with Batches

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

the class CompareComplyTest method testListBatchesWOptions.

@Test
public void testListBatchesWOptions() throws Throwable {
    // Schedule some responses.
    String mockResponseBody = "{\"batches\": [{\"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 listBatchesPath = "/v1/batches";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    constructClientService();
    // Construct an instance of the ListBatchesOptions model
    ListBatchesOptions listBatchesOptionsModel = new ListBatchesOptions();
    // Invoke operation with valid options model (positive test)
    Response<Batches> response = compareComplyService.listBatches(listBatchesOptionsModel).execute();
    assertNotNull(response);
    Batches 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, listBatchesPath);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListBatchesOptions(com.ibm.watson.compare_comply.v1.model.ListBatchesOptions) Batches(com.ibm.watson.compare_comply.v1.model.Batches) Test(org.testng.annotations.Test)

Aggregations

BatchStatus (com.ibm.watson.compare_comply.v1.model.BatchStatus)7 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 MockResponse (okhttp3.mockwebserver.MockResponse)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 Test (org.testng.annotations.Test)4 Batches (com.ibm.watson.compare_comply.v1.model.Batches)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 ListBatchesOptions (com.ibm.watson.compare_comply.v1.model.ListBatchesOptions)1 MultipartBody (okhttp3.MultipartBody)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1