use of com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateDocumentIsSuccessful.
@Test
public void updateDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
uniqueName = UUID.randomUUID().toString();
Configuration testConfig = createTestConfig();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.filename("test_file");
// updateBuilder.configurationId(testConfig.getConfigurationId());
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, updateResponse.getDocumentId()).build();
DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
assertTrue(getResponse.getStatus().equals(DocumentStatus.Status.AVAILABLE) || getResponse.getStatus().equals(DocumentStatus.Status.PROCESSING));
}
use of com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateAnotherDocumentIsSuccessful.
@Test
public void updateAnotherDocumentIsSuccessful() {
Collection collection = createTestCollection();
String collectionId = collection.getCollectionId();
JsonObject myMetadata = new JsonObject();
myMetadata.add("foo", new JsonPrimitive("bar"));
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
builder.metadata(myMetadata.toString());
DocumentAccepted documentAccepted = discovery.addDocument(builder.build()).execute();
String myDocumentJson = "{\"field\":\"value2\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
updateBuilder.filename("test_file");
DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, updateResponse.getDocumentId()).build();
DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
assertTrue(getResponse.getStatus().equals(DocumentStatus.Status.AVAILABLE) || getResponse.getStatus().equals(DocumentStatus.Status.PROCESSING));
}
use of com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryTest method testGetDocumentStatusWOptions.
// Test the getDocumentStatus operation with a valid options model parameter
@Test
public void testGetDocumentStatusWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"document_id\": \"documentId\", \"configuration_id\": \"configurationId\", \"status\": \"available\", \"status_description\": \"statusDescription\", \"filename\": \"filename\", \"file_type\": \"pdf\", \"sha1\": \"sha1\", \"notices\": [{\"notice_id\": \"noticeId\", \"created\": \"2019-01-01T12:00:00.000Z\", \"document_id\": \"documentId\", \"query_id\": \"queryId\", \"severity\": \"warning\", \"step\": \"step\", \"description\": \"description\"}]}";
String getDocumentStatusPath = "/v1/environments/testString/collections/testString/documents/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the GetDocumentStatusOptions model
GetDocumentStatusOptions getDocumentStatusOptionsModel = new GetDocumentStatusOptions.Builder().environmentId("testString").collectionId("testString").documentId("testString").build();
// Invoke getDocumentStatus() with a valid options model and verify the result
Response<DocumentStatus> response = discoveryService.getDocumentStatus(getDocumentStatusOptionsModel).execute();
assertNotNull(response);
DocumentStatus responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request sent to the mock server
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, getDocumentStatusPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
}
use of com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions in project java-sdk by watson-developer-cloud.
the class Discovery method getDocumentStatus.
/**
* Get document details.
*
* <p>Fetch status details about a submitted document. **Note:** this operation does not return
* the document itself. Instead, it returns only the document's processing status and any notices
* (warnings or errors) that were generated when the document was ingested. Use the query API to
* retrieve the actual document content.
*
* @param getDocumentStatusOptions the {@link GetDocumentStatusOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link DocumentStatus}
*/
public ServiceCall<DocumentStatus> getDocumentStatus(GetDocumentStatusOptions getDocumentStatusOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getDocumentStatusOptions, "getDocumentStatusOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getDocumentStatusOptions.environmentId());
pathParamsMap.put("collection_id", getDocumentStatusOptions.collectionId());
pathParamsMap.put("document_id", getDocumentStatusOptions.documentId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/documents/{document_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getDocumentStatus");
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<DocumentStatus> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DocumentStatus>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getDocumentIsSuccessful.
@Test
public void getDocumentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(getDocResp));
GetDocumentStatusOptions getRequest = new GetDocumentStatusOptions.Builder(environmentId, collectionId, documentId).build();
DocumentStatus response = discoveryService.getDocumentStatus(getRequest).execute();
RecordedRequest request = server.takeRequest();
assertEquals(DOCS2_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getDocResp, response);
}
Aggregations