Search in sources :

Example 11 with Collection

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

the class Discovery method getCollection.

/**
 * Get collection details.
 *
 * @param getCollectionOptions the {@link GetCollectionOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Collection}
 */
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
    Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections" };
    String[] pathParameters = { getCollectionOptions.environmentId(), getCollectionOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection)

Example 12 with Collection

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

the class Discovery method updateCollection.

/**
 * Update a collection.
 *
 * @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Collection}
 */
public ServiceCall<Collection> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
    Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections" };
    String[] pathParameters = { updateCollectionOptions.environmentId(), updateCollectionOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.put(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateCollectionOptions.name() != null) {
        contentJson.addProperty("name", updateCollectionOptions.name());
    }
    if (updateCollectionOptions.description() != null) {
        contentJson.addProperty("description", updateCollectionOptions.description());
    }
    if (updateCollectionOptions.configurationId() != null) {
        contentJson.addProperty("configuration_id", updateCollectionOptions.configurationId());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Collection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection)

Example 13 with Collection

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

the class Discovery method listExpansions.

/**
 * List current expansions.
 *
 * Returns the current expansion list for the specified collection. If an expansion list is not specified, an object
 * with empty expansion arrays is returned.
 *
 * @param listExpansionsOptions the {@link ListExpansionsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Expansions}
 */
public ServiceCall<Expansions> listExpansions(ListExpansionsOptions listExpansionsOptions) {
    Validator.notNull(listExpansionsOptions, "listExpansionsOptions cannot be null");
    String[] pathSegments = { "v1/environments", "collections", "expansions" };
    String[] pathParameters = { listExpansionsOptions.environmentId(), listExpansionsOptions.collectionId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Expansions.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) Expansions(com.ibm.watson.developer_cloud.discovery.v1.model.Expansions)

Example 14 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 createCollectionIsSuccessful.

@Test
public void createCollectionIsSuccessful() {
    Configuration createConfigResponse = createTestConfig();
    String uniqueCollectionName = uniqueName + "-collection";
    String uniqueCollectionDescription = "Description of " + uniqueCollectionName;
    CreateCollectionOptions.Builder createCollectionBuilder = new CreateCollectionOptions.Builder(environmentId, uniqueCollectionName).configurationId(createConfigResponse.getConfigurationId()).description(uniqueCollectionDescription);
    Collection createResponse = createCollection(createCollectionBuilder.build());
    assertEquals(createConfigResponse.getConfigurationId(), createResponse.getConfigurationId());
    assertEquals(uniqueCollectionName, createResponse.getName());
    assertEquals(uniqueCollectionDescription, createResponse.getDescription());
}
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) Test(org.junit.Test) WatsonServiceTest(com.ibm.watson.developer_cloud.WatsonServiceTest)

Example 15 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 getCollectionFieldsIsSuccessful.

@Ignore
@Test
public void getCollectionFieldsIsSuccessful() {
    Collection collection = createTestCollection();
    String collectionId = collection.getCollectionId();
    createTestDocument("test_document", collectionId);
    ListCollectionFieldsOptions getOptions = new ListCollectionFieldsOptions.Builder(environmentId, collectionId).build();
    ListCollectionFieldsResponse getResponse = discovery.listCollectionFields(getOptions).execute();
    assertFalse(getResponse.getFields().isEmpty());
}
Also used : ListCollectionFieldsOptions(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsOptions) Collection(com.ibm.watson.developer_cloud.discovery.v1.model.Collection) ListCollectionFieldsResponse(com.ibm.watson.developer_cloud.discovery.v1.model.ListCollectionFieldsResponse) 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 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