Search in sources :

Example 1 with DocumentStatus

use of com.ibm.watson.language_translator.v3.model.DocumentStatus 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 DocumentStatus

use of com.ibm.watson.language_translator.v3.model.DocumentStatus 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 DocumentStatus

use of com.ibm.watson.language_translator.v3.model.DocumentStatus in project java-sdk by watson-developer-cloud.

the class Discovery method getDocumentStatus.

/**
 * Get document details.
 *
 * 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 response type of {@link DocumentStatus}
 */
public ServiceCall<DocumentStatus> getDocumentStatus(GetDocumentStatusOptions getDocumentStatusOptions) {
    Validator.notNull(getDocumentStatusOptions, "getDocumentStatusOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "documents" };
    String[] pathParameters = { getDocumentStatusOptions.environmentId(), getDocumentStatusOptions.collectionId(), getDocumentStatusOptions.documentId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DocumentStatus.class));
}
Also used : DocumentStatus(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder)

Example 4 with DocumentStatus

use of com.ibm.watson.language_translator.v3.model.DocumentStatus in project java-sdk by watson-developer-cloud.

the class LanguageTranslator method getDocumentStatus.

/**
 * Get document status.
 *
 * <p>Gets the translation status of a document.
 *
 * @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("document_id", getDocumentStatusOptions.documentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v3/documents/{document_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("language_translator", "v3", "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.language_translator.v3.model.DocumentStatus) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Example 5 with DocumentStatus

use of com.ibm.watson.language_translator.v3.model.DocumentStatus 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)

Aggregations

DocumentStatus (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus)6 GetDocumentStatusOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)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 DocumentStatus (com.ibm.watson.language_translator.v3.model.DocumentStatus)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 InputStream (java.io.InputStream)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 GetDocumentStatusOptions (com.ibm.watson.discovery.v1.model.GetDocumentStatusOptions)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 Test (org.testng.annotations.Test)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 HashMap (java.util.HashMap)2