use of com.ibm.watson.compare_comply.v1.model.CompareDocumentsOptions in project java-sdk by watson-developer-cloud.
the class CompareComplyTest method testCompareDocumentsWOptions.
@Test
public void testCompareDocumentsWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"model_id\": \"modelId\", \"model_version\": \"modelVersion\", \"documents\": [{\"title\": \"title\", \"html\": \"html\", \"hash\": \"hash\", \"label\": \"label\"}], \"aligned_elements\": [{\"element_pair\": [{\"document_label\": \"documentLabel\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}, \"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}}], \"categories\": [{\"label\": \"Amendments\"}], \"attributes\": [{\"type\": \"Currency\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}], \"identical_text\": false, \"provenance_ids\": [\"provenanceIds\"], \"significant_elements\": false}], \"unaligned_elements\": [{\"document_label\": \"documentLabel\", \"location\": {\"begin\": 5, \"end\": 3}, \"text\": \"text\", \"types\": [{\"label\": {\"nature\": \"nature\", \"party\": \"party\"}}], \"categories\": [{\"label\": \"Amendments\"}], \"attributes\": [{\"type\": \"Currency\", \"text\": \"text\", \"location\": {\"begin\": 5, \"end\": 3}}]}]}";
String compareDocumentsPath = "/v1/comparison";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the CompareDocumentsOptions model
CompareDocumentsOptions compareDocumentsOptionsModel = new CompareDocumentsOptions.Builder().file1(TestUtilities.createMockStream("This is a mock file.")).file2(TestUtilities.createMockStream("This is a mock file.")).file1ContentType("application/pdf").file2ContentType("application/pdf").file1Label("file_1").file2Label("file_2").model("contracts").build();
// Invoke operation with valid options model (positive test)
Response<CompareReturn> response = compareComplyService.compareDocuments(compareDocumentsOptionsModel).execute();
assertNotNull(response);
CompareReturn 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("file_1_label"), "file_1");
assertEquals(query.get("file_2_label"), "file_2");
assertEquals(query.get("model"), "contracts");
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, compareDocumentsPath);
}
use of com.ibm.watson.compare_comply.v1.model.CompareDocumentsOptions in project java-sdk by watson-developer-cloud.
the class CompareComply method compareDocuments.
/**
* Compare two documents.
*
* <p>Compares two input documents. Documents must be in the same format.
*
* @param compareDocumentsOptions the {@link CompareDocumentsOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link CompareReturn}
*/
public ServiceCall<CompareReturn> compareDocuments(CompareDocumentsOptions compareDocumentsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(compareDocumentsOptions, "compareDocumentsOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/comparison"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("compare-comply", "v1", "compareDocuments");
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));
if (compareDocumentsOptions.file1Label() != null) {
builder.query("file_1_label", String.valueOf(compareDocumentsOptions.file1Label()));
}
if (compareDocumentsOptions.file2Label() != null) {
builder.query("file_2_label", String.valueOf(compareDocumentsOptions.file2Label()));
}
if (compareDocumentsOptions.model() != null) {
builder.query("model", String.valueOf(compareDocumentsOptions.model()));
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
okhttp3.RequestBody file1Body = RequestUtils.inputStreamBody(compareDocumentsOptions.file1(), compareDocumentsOptions.file1ContentType());
multipartBuilder.addFormDataPart("file_1", "filename", file1Body);
okhttp3.RequestBody file2Body = RequestUtils.inputStreamBody(compareDocumentsOptions.file2(), compareDocumentsOptions.file2ContentType());
multipartBuilder.addFormDataPart("file_2", "filename", file2Body);
builder.body(multipartBuilder.build());
ResponseConverter<CompareReturn> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CompareReturn>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.compare_comply.v1.model.CompareDocumentsOptions in project java-sdk by watson-developer-cloud.
the class CompareComplyServiceIT method testCompareDocuments.
@Test
public void testCompareDocuments() throws FileNotFoundException {
CompareDocumentsOptions compareDocumentsOptions = new CompareDocumentsOptions.Builder().file1(CONTRACT_A).file1ContentType(HttpMediaType.APPLICATION_PDF).file2(CONTRACT_B).file2ContentType(HttpMediaType.APPLICATION_PDF).build();
CompareReturn response = service.compareDocuments(compareDocumentsOptions).execute().getResult();
assertNotNull(response);
// System.out.println(response);
}
Aggregations