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