Search in sources :

Example 6 with Collection

use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method addDocumentWithMetadataIsSuccessful.

@Ignore
@SuppressWarnings("deprecation")
@Test
public void addDocumentWithMetadataIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    String myDocumentJson = "{\"field\":\"value\"}";
    InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
    JsonObject myMetadata = new JsonObject();
    myMetadata.add("foo", new JsonPrimitive("bar"));
    AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder(environmentId, collectionId);
    builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
    builder.filename("test_file");
    builder.metadata(myMetadata.toString());
    DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute();
    WaitFor.Condition documentAccepted = new WaitForDocumentAccepted(environmentId, collectionId, createResponse.getDocumentId());
    WaitFor.waitFor(documentAccepted, 5, TimeUnit.SECONDS, 500);
    QueryOptions queryOptions = new QueryOptions.Builder(environmentId, collectionId).build();
    QueryResponse queryResponse = discovery.query(queryOptions).execute();
    assertTrue(queryResponse.getResults().get(0).getMetadata() != null);
}
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) JsonObject(com.google.gson.JsonObject) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) AddDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions) WaitFor(com.ibm.watson.developer_cloud.util.WaitFor) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Ignore(org.junit.Ignore) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 7 with Collection

use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method setupTestDocuments.

private synchronized String setupTestDocuments() {
    if (collectionId != null) {
        return collectionId;
    }
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    @SuppressWarnings("unused") List<DocumentAccepted> documentAccepted = createTestDocuments(collectionId, 10);
    WaitFor.Condition collectionAvailable = new WaitForCollectionAvailable(environmentId, collectionId);
    WaitFor.waitFor(collectionAvailable, 5, TimeUnit.SECONDS, 500);
    return collectionId;
}
Also used : DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) WaitFor(com.ibm.watson.developer_cloud.util.WaitFor) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection)

Example 8 with Collection

use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection 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 9 with Collection

use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection 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 10 with Collection

use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.

the class DiscoveryServiceIT method deleteCollectionIsSuccessful.

@Test
public void deleteCollectionIsSuccessful() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
    Collection createResponse = createCollection(createCollectionBuilder.build());
    // need to wait for collection to be ready
    DeleteCollectionOptions deleteOptions = new DeleteCollectionOptions.Builder(environmentId, createResponse.getCollectionId()).build();
    deleteCollection(deleteOptions);
}
Also used : Configuration(com.ibm.watson.developer_cloud.discovery.v1.model.Configuration) CreateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) DeleteCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 Test (org.junit.Test)21 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)19 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)11 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)10 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)9 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 JsonObject (com.google.gson.JsonObject)7 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5 QueryResponse (com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse)5 DocumentStatus (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus)4 GetDocumentStatusOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions)4 Ignore (org.junit.Ignore)4 JsonPrimitive (com.google.gson.JsonPrimitive)3 GetCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetCollectionOptions)3 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2