use of com.ibm.watson.compare_comply.v1.model.CreateBatchOptions 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);
}
use of com.ibm.watson.compare_comply.v1.model.CreateBatchOptions 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);
}
use of com.ibm.watson.compare_comply.v1.model.CreateBatchOptions 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);
}
Aggregations