Search in sources :

Example 6 with Batches

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

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

Example 8 with Batches

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

the class CompareComply method getBatch.

/**
 * Get information about a specific batch-processing job.
 *
 * <p>Gets information about a batch-processing job with a specified ID.
 *
 * @param getBatchOptions the {@link GetBatchOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link BatchStatus}
 */
public ServiceCall<BatchStatus> getBatch(GetBatchOptions getBatchOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getBatchOptions, "getBatchOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("batch_id", getBatchOptions.batchId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/batches/{batch_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "getBatch");
    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<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)

Example 9 with Batches

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

the class CompareComplyServiceIT method testBatchOperations.

@Test
@Ignore
public void testBatchOperations() throws FileNotFoundException {
    String bucketLocation = "us-south";
    String inputBucketName = "compare-comply-integration-test-bucket-input";
    String outputBucketName = "compare-comply-integration-test-bucket-output";
    CreateBatchOptions createBatchOptions = new CreateBatchOptions.Builder().function(CreateBatchOptions.Function.ELEMENT_CLASSIFICATION).inputBucketLocation(bucketLocation).inputBucketName(inputBucketName).inputCredentialsFile(INPUT_CREDENTIALS_FILE).outputBucketLocation(bucketLocation).outputBucketName(outputBucketName).outputCredentialsFile(OUTPUT_CREDENTIALS_FILE).build();
    BatchStatus createBatchResponse = service.createBatch(createBatchOptions).execute().getResult();
    String batchId = createBatchResponse.getBatchId();
    GetBatchOptions getBatchOptions = new GetBatchOptions.Builder().batchId(batchId).build();
    BatchStatus getBatchResponse = service.getBatch(getBatchOptions).execute().getResult();
    assertNotNull(getBatchResponse);
    UpdateBatchOptions updateBatchOptions = new UpdateBatchOptions.Builder().batchId(batchId).action(UpdateBatchOptions.Action.RESCAN).build();
    BatchStatus updateBatchResponse = service.updateBatch(updateBatchOptions).execute().getResult();
    assertTrue(updateBatchResponse.getCreated().before(updateBatchResponse.getUpdated()));
    Batches listBatchesResponse = service.listBatches().execute().getResult();
    List<BatchStatus> batches = listBatchesResponse.getBatches();
    boolean batchFound = false;
    for (BatchStatus batch : batches) {
        if (batch.getBatchId().equals(batchId)) {
            batchFound = true;
            break;
        }
    }
    assertTrue(batchFound);
}
Also used : UpdateBatchOptions(com.ibm.watson.compare_comply.v1.model.UpdateBatchOptions) BatchStatus(com.ibm.watson.compare_comply.v1.model.BatchStatus) Batches(com.ibm.watson.compare_comply.v1.model.Batches) CreateBatchOptions(com.ibm.watson.compare_comply.v1.model.CreateBatchOptions) GetBatchOptions(com.ibm.watson.compare_comply.v1.model.GetBatchOptions) Ignore(org.junit.Ignore) Test(org.junit.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