Search in sources :

Example 36 with Collection

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

the class DiscoveryServiceIT method queryWithNestedAggregationTermIsSuccessful.

@Test
public void queryWithNestedAggregationTermIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    createTestDocument("test_document_1", collectionId);
    createTestDocument("test_document_2", collectionId);
    QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
    StringBuilder sb = new StringBuilder();
    sb.append(AggregationType.TERM);
    sb.append(Operator.OPENING_GROUPING);
    sb.append("field");
    sb.append(Operator.CLOSING_GROUPING);
    sb.append(Operator.NEST_AGGREGATION);
    sb.append(AggregationType.TERM);
    sb.append(Operator.OPENING_GROUPING);
    sb.append("field");
    sb.append(Operator.CLOSING_GROUPING);
    String aggregation = sb.toString();
    queryBuilder.aggregation(aggregation);
    QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
    Term term = (Term) queryResponse.getAggregations().get(0);
    AggregationResult agResults = term.getResults().get(0);
    List<QueryAggregation> aggregations = agResults.getAggregations();
    assertFalse(aggregations.isEmpty());
}
Also used : AggregationResult(com.ibm.watson.developer_cloud.discovery.v1.model.AggregationResult) QueryResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryResponse) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) Term(com.ibm.watson.developer_cloud.discovery.v1.model.Term) QueryAggregation(com.ibm.watson.developer_cloud.discovery.v1.model.QueryAggregation) QueryOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 37 with Collection

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

the class DiscoveryServiceIT method updateCollectionIsSuccessful.

@Test
public void updateCollectionIsSuccessful() {
    String uniqueCollectionName = uniqueName + "-collection";
    CreateCollectionOptions createOptions = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).build();
    Collection collection = createCollection(createOptions);
    assertNotNull(collection.getCollectionId());
    Configuration testConfig = createTestConfig();
    String updatedCollectionName = UUID.randomUUID().toString() + "-collection";
    String updatedCollectionDescription = "Description for " + updatedCollectionName;
    UpdateCollectionOptions.Builder updateBuilder = new UpdateCollectionOptions.Builder(environmentId, collection.getCollectionId());
    updateBuilder.name(updatedCollectionName);
    updateBuilder.description(updatedCollectionDescription);
    updateBuilder.configurationId(testConfig.getConfigurationId());
    Collection updatedCollection = discovery.updateCollection(updateBuilder.build()).execute();
    assertEquals(updatedCollectionName, updatedCollection.getName());
    assertEquals(updatedCollectionDescription, updatedCollection.getDescription());
    assertEquals(testConfig.getConfigurationId(), updatedCollection.getConfigurationId());
}
Also used : UpdateCollectionOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateCollectionOptions) 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) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 38 with Collection

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

the class DiscoveryServiceIT method getCollectionIsSuccessful.

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

Example 39 with Collection

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

the class DiscoveryServiceIT method updateDocumentWithMetadataIsSuccessful.

@Test
@Ignore("Pending implementation of 'processing' after document update")
public void updateDocumentWithMetadataIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
    String myDocumentJson = "{\"field\":\"value2\"}";
    InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
    JsonObject myMetadata = new JsonObject();
    myMetadata.add("foo", new JsonPrimitive("bar"));
    UpdateDocumentOptions.Builder updateBuilder = new UpdateDocumentOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId());
    updateBuilder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
    updateBuilder.metadata(myMetadata.toString());
    DocumentAccepted updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
    WaitFor.Condition waitForDocumentAccepted = new WaitForDocumentAccepted(environmentId, collectionId, updateResponse.getDocumentId());
    WaitFor.waitFor(waitForDocumentAccepted, 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) UpdateDocumentOptions(com.ibm.watson.developer_cloud.discovery.v1.model.UpdateDocumentOptions) ByteArrayInputStream(java.io.ByteArrayInputStream) 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 40 with Collection

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

the class DiscoveryServiceIT method getDocumentIsSuccessful.

@Ignore
@Test
public void getDocumentIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    DocumentAccepted documentAccepted = createTestDocument("test_document", collectionId);
    GetDocumentStatusOptions getOptions = new GetDocumentStatusOptions.Builder(environmentId, collectionId, documentAccepted.getDocumentId()).build();
    DocumentStatus getResponse = discovery.getDocumentStatus(getOptions).execute();
    assertEquals(DocumentStatus.Status.AVAILABLE, getResponse.getStatus());
}
Also used : DocumentStatus(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentStatus) DocumentAccepted(com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted) GetDocumentStatusOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetDocumentStatusOptions) 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)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5