Search in sources :

Example 6 with CollectionDetails

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

the class Discovery method updateCollection.

/**
 * Update a collection.
 *
 * <p>Updates the specified collection's name, description, and enrichments.
 *
 * @param updateCollectionOptions the {@link UpdateCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link CollectionDetails}
 */
public ServiceCall<CollectionDetails> updateCollection(UpdateCollectionOptions updateCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateCollectionOptions, "updateCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateCollectionOptions.projectId());
    pathParamsMap.put("collection_id", updateCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateCollection");
    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));
    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.enrichments() != null) {
        contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateCollectionOptions.enrichments()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<CollectionDetails> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CollectionDetails>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) CollectionDetails(com.ibm.watson.discovery.v2.model.CollectionDetails)

Aggregations

CollectionDetails (com.ibm.watson.discovery.v2.model.CollectionDetails)6 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 HashMap (java.util.HashMap)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.testng.annotations.Test)3 JsonObject (com.google.gson.JsonObject)2 CollectionEnrichment (com.ibm.watson.discovery.v2.model.CollectionEnrichment)2 CreateCollectionOptions (com.ibm.watson.discovery.v2.model.CreateCollectionOptions)1 GetCollectionOptions (com.ibm.watson.discovery.v2.model.GetCollectionOptions)1 UpdateCollectionOptions (com.ibm.watson.discovery.v2.model.UpdateCollectionOptions)1