use of com.ibm.watson.discovery.v1.model.Configuration in project java-sdk by watson-developer-cloud.
the class Discovery method getConfiguration.
/**
* Get configuration details.
*
* @param getConfigurationOptions the {@link GetConfigurationOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Configuration}
*/
public ServiceCall<Configuration> getConfiguration(GetConfigurationOptions getConfigurationOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(getConfigurationOptions, "getConfigurationOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", getConfigurationOptions.environmentId());
pathParamsMap.put("configuration_id", getConfigurationOptions.configurationId());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/configurations/{configuration_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getConfiguration");
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<Configuration> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Configuration>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Configuration in project java-sdk by watson-developer-cloud.
the class Discovery method createConfiguration.
/**
* Add configuration.
*
* <p>Creates a new configuration.
*
* <p>If the input configuration contains the **configuration_id**, **created**, or **updated**
* properties, then they are ignored and overridden by the system, and an error is not returned so
* that the overridden fields do not need to be removed when copying a configuration.
*
* <p>The configuration can contain unrecognized JSON fields. Any such fields are ignored and do
* not generate an error. This makes it easier to use newer configuration files with older
* versions of the API and the service. It also makes it possible for the tooling to add
* additional metadata and information to the configuration.
*
* @param createConfigurationOptions the {@link CreateConfigurationOptions} containing the options
* for the call
* @return a {@link ServiceCall} with a result of type {@link Configuration}
*/
public ServiceCall<Configuration> createConfiguration(CreateConfigurationOptions createConfigurationOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createConfigurationOptions, "createConfigurationOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", createConfigurationOptions.environmentId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/configurations", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createConfiguration");
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", createConfigurationOptions.name());
if (createConfigurationOptions.description() != null) {
contentJson.addProperty("description", createConfigurationOptions.description());
}
if (createConfigurationOptions.conversions() != null) {
contentJson.add("conversions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createConfigurationOptions.conversions()));
}
if (createConfigurationOptions.enrichments() != null) {
contentJson.add("enrichments", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createConfigurationOptions.enrichments()));
}
if (createConfigurationOptions.normalizations() != null) {
contentJson.add("normalizations", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createConfigurationOptions.normalizations()));
}
if (createConfigurationOptions.source() != null) {
contentJson.add("source", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createConfigurationOptions.source()));
}
builder.bodyJson(contentJson);
ResponseConverter<Configuration> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Configuration>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Configuration in project java-sdk by watson-developer-cloud.
the class Discovery method deleteGateway.
/**
* Delete Gateway.
*
* <p>Delete the specified gateway configuration.
*
* @param deleteGatewayOptions the {@link DeleteGatewayOptions} containing the options for the
* call
* @return a {@link ServiceCall} with a result of type {@link GatewayDelete}
*/
public ServiceCall<GatewayDelete> deleteGateway(DeleteGatewayOptions deleteGatewayOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteGatewayOptions, "deleteGatewayOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", deleteGatewayOptions.environmentId());
pathParamsMap.put("gateway_id", deleteGatewayOptions.gatewayId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/gateways/{gateway_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteGateway");
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<GatewayDelete> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<GatewayDelete>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Configuration 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 com.ibm.watson.discovery.v1.model.Configuration in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceIT method updateConfigurationIsSuccessful.
@Test
public void updateConfigurationIsSuccessful() {
Configuration testConfig = createTestConfig();
Date start = new Date();
String updatedName = testConfig.getName() + UUID.randomUUID().toString();
String updatedDescription = "Description of " + updatedName;
Conversions updatedConversions = new Conversions();
HtmlSettings newHtmlSettings = new HtmlSettings();
newHtmlSettings.setExcludeTagsCompletely(Arrays.asList("table", "h6", "header"));
updatedConversions.setHtml(newHtmlSettings);
NormalizationOperation operation = new NormalizationOperation();
operation.setOperation("foo");
operation.setSourceField("bar");
operation.setDestinationField("baz");
List<NormalizationOperation> updatedNormalizations = Arrays.asList(operation);
Enrichment enrichment = new Enrichment();
enrichment.setSourceField("foo");
enrichment.setDestinationField("bar");
enrichment.setEnrichmentName("baz");
enrichment.setDescription("Erich foo to bar with baz");
enrichment.setIgnoreDownstreamErrors(true);
enrichment.setOverwrite(false);
NluEnrichmentSentiment sentiment = new NluEnrichmentSentiment.Builder().document(true).build();
NluEnrichmentEmotion emotion = new NluEnrichmentEmotion.Builder().document(true).build();
NluEnrichmentEntities entities = new NluEnrichmentEntities.Builder().emotion(true).sentiment(true).model("WhatComesAfterQux").build();
NluEnrichmentKeywords keywords = new NluEnrichmentKeywords.Builder().emotion(true).sentiment(true).build();
NluEnrichmentSemanticRoles semanticRoles = new NluEnrichmentSemanticRoles.Builder().entities(true).build();
NluEnrichmentFeatures features = new NluEnrichmentFeatures.Builder().sentiment(sentiment).emotion(emotion).entities(entities).keywords(keywords).semanticRoles(semanticRoles).build();
EnrichmentOptions options = new EnrichmentOptions.Builder().features(features).build();
enrichment.setOptions(options);
List<Enrichment> updatedEnrichments = Arrays.asList(enrichment);
UpdateConfigurationOptions.Builder updateBuilder = new UpdateConfigurationOptions.Builder(environmentId, testConfig.getConfigurationId());
updateBuilder.name(updatedName);
updateBuilder.description(updatedDescription);
updateBuilder.conversions(updatedConversions);
updateBuilder.normalizations(updatedNormalizations);
updateBuilder.enrichments(updatedEnrichments);
Configuration updatedConfiguration = discovery.updateConfiguration(updateBuilder.build()).execute();
assertEquals(updatedName, updatedConfiguration.getName());
assertEquals(updatedDescription, updatedConfiguration.getDescription());
assertEquals(updatedConversions, updatedConfiguration.getConversions());
assertEquals(updatedNormalizations, updatedConfiguration.getNormalizations());
assertEquals(updatedEnrichments, updatedConfiguration.getEnrichments());
Date now = new Date();
assertTrue(fuzzyBefore(updatedConfiguration.getCreated(), start));
assertTrue(fuzzyBefore(updatedConfiguration.getUpdated(), now));
assertTrue(fuzzyAfter(updatedConfiguration.getUpdated(), start));
}
Aggregations