use of com.ibm.watson.developer_cloud.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());
}
use of com.ibm.watson.developer_cloud.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());
}
use of com.ibm.watson.developer_cloud.discovery.v1.model.Collection in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method getCollectionsByNameIsSuccessful.
@Test
public void getCollectionsByNameIsSuccessful() {
Configuration createConfigResponse = createTestConfig();
String uniqueCollectionName = uniqueName + "-collection";
CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId());
createCollection(createCollectionBuilder.build());
ListCollectionsOptions.Builder getBuilder = new ListCollectionsOptions.Builder(environmentId);
getBuilder.name(uniqueCollectionName);
ListCollectionsResponse getResponse = discovery.listCollections(getBuilder.build()).execute();
assertEquals(1, getResponse.getCollections().size());
assertEquals(uniqueCollectionName, getResponse.getCollections().get(0).getName());
}
use of com.ibm.watson.developer_cloud.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());
}
use of com.ibm.watson.developer_cloud.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);
}
Aggregations