watson-developer-cloud / java-sdk

:1st_place_medal: Java SDK to use the IBM Watson services.
http://watson-developer-cloud.github.io/java-sdk/
Apache License 2.0
590 stars 533 forks source link

[discovery] creating a collection does not use the configuration id #659

Closed Pmagnard closed 7 years ago

Pmagnard commented 7 years ago

I use Watson Java SDK v3.7.2 to create a Discovery collection based on a non-default configuration. By using the sample code from the API reference (https://www.ibm.com/watson/developercloud/discovery/api/v1/?java#create-collection), I can create the collection but it is created with the default configuration of the environment instead of the the supplied configuration id. The problem is located in the method Discovery.createCollection(CreateCollectionRequest). The CreateCollectionRequest is "JSONised" to serve as a parameter in the consecutive HTTP POST request. The expected JSON fragment for the configuration is "configuration_id":"" while the generated fragment is "configurationId":"" (because of the name of the field CreateCollectionRequest.configurationId).

In order to be able to create a collection with a specific configuration id, I had to create a class based on Discovery and override the createCollection() method to handle the JSON parameter in the request differently. Here are the details: @Override public ServiceCall createCollection(CreateCollectionRequest createRequest) { Validator.notEmpty(createRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty"); Validator.notEmpty(createRequest.getConfigurationId(), ConfigurationManager.ID + " cannot be empty"); Validator.notEmpty(createRequest.getName(), CollectionManager.NAME + " cannot be empty"); RequestBuilder builder = RequestBuilder.post(String.format("/v1/environments/%s/collections", createRequest.getEnvironmentId())); / patch to take the configuration_id into account / //builder.bodyJson(GsonSingleton.getGson().toJsonTree(createRequest, CreateCollectionRequest.class).getAsJsonObject()); JsonObject paramJson = new JsonObject(); paramJson.addProperty("name", createRequest.getName()); paramJson.addProperty("description", createRequest.getDescription()); paramJson.addProperty("configuration_id", createRequest.getConfigurationId()); builder.bodyJson(paramJson); final Request request = createVersionedRequest(builder); return createServiceCall(request, ResponseConverterUtils.getObject(CreateCollectionResponse.class)); }

mkistler commented 7 years ago

I've create a test to reproduce this problem. But my test passes. The new test is in this branch:

https://github.com/watson-developer-cloud/java-sdk/tree/mdk/659-use-configid-on-create-collection

Please let me know if I have misunderstood the problem, or somehow failed to translate it correctly in my test. Otherwise I'm inclined close this issue as invalid.

mkistler commented 7 years ago

Closing as invalid.