use of li.naska.bgg.resource.v3.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 result of type {@link Collection}
*/
public ServiceCall<Collection> getCollection(GetCollectionOptions getCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getCollectionOptions, "getCollectionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getCollectionOptions.environmentId());
pathParamsMap.put("collection_id", getCollectionOptions.collectionId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getCollection");
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));
ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class Discovery method createCollection.
/**
* Create a collection.
*
* @param createCollectionOptions the {@link CreateCollectionOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Collection}
*/
public ServiceCall<Collection> createCollection(CreateCollectionOptions createCollectionOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createCollectionOptions, "createCollectionOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", createCollectionOptions.environmentId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createCollection");
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();
contentJson.addProperty("name", createCollectionOptions.name());
if (createCollectionOptions.description() != null) {
contentJson.addProperty("description", createCollectionOptions.description());
}
if (createCollectionOptions.configurationId() != null) {
contentJson.addProperty("configuration_id", createCollectionOptions.configurationId());
}
if (createCollectionOptions.language() != null) {
contentJson.addProperty("language", createCollectionOptions.language());
}
builder.bodyJson(contentJson);
ResponseConverter<Collection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Collection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of li.naska.bgg.resource.v3.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());
}
use of li.naska.bgg.resource.v3.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());
}
use of li.naska.bgg.resource.v3.model.Collection in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method addDocumentWithConfigurationIsSuccessful.
@Test
public void addDocumentWithConfigurationIsSuccessful() {
Collection collection = createTestCollection();
uniqueName = UUID.randomUUID().toString();
String myDocumentJson = "{\"field\":\"value\"}";
InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
AddDocumentOptions.Builder builder = new AddDocumentOptions.Builder();
builder.environmentId(environmentId);
builder.collectionId(collection.getCollectionId());
builder.file(documentStream).fileContentType(HttpMediaType.APPLICATION_JSON);
builder.filename("test_file");
DocumentAccepted createResponse = discovery.addDocument(builder.build()).execute();
assertFalse(createResponse.getDocumentId().isEmpty());
assertNull(createResponse.getNotices());
}
Aggregations