Search in sources :

Example 1 with GetDocumentStatusOptions

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));
}
Also used : DocumentStatus(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus) DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) UpdateDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions) Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GetDocumentStatusOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 2 with GetDocumentStatusOptions

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));
}
Also used : DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) JsonPrimitive(com.google.gson.JsonPrimitive) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GetDocumentStatusOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions) JsonObject(com.google.gson.JsonObject) DocumentStatus(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus) UpdateDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions) AddDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 3 with GetDocumentStatusOptions

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");
}
Also used : DocumentStatus(com.ibm.watson.discovery.v1.model.DocumentStatus) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetDocumentStatusOptions(com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions) Test(org.testng.annotations.Test)

Example 4 with GetDocumentStatusOptions

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);
}
Also used : DocumentStatus(com.ibm.watson.discovery.v1.model.DocumentStatus) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 5 with GetDocumentStatusOptions

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);
}
Also used : DocumentStatus(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetDocumentStatusOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

DocumentStatus (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus)5 GetDocumentStatusOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions)5 Test (org.junit.Test)5 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)4 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)4 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)4 DocumentStatus (com.ibm.watson.discovery.v1.model.DocumentStatus)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 GetDocumentStatusOptions (com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions)3 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 UpdateDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions)2 FileInputStream (java.io.FileInputStream)2 JsonObject (com.google.gson.JsonObject)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)1 IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)1