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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations