use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method createEnvironmentIsSuccessful.
// Deleted test for listEnvironments with null name as this does not fail in the current SDK
/**
* Creates the environment is successful.
*
* @throws InterruptedException the interrupted exception
*/
@Test
public void createEnvironmentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(createEnvResp));
CreateEnvironmentOptions.Builder createRequestBuilder = new CreateEnvironmentOptions.Builder().name(environmentName).size(CreateEnvironmentOptions.Size.XS);
createRequestBuilder.description(environmentDesc);
Environment response = discoveryService.createEnvironment(createRequestBuilder.build()).execute().getResult();
RecordedRequest request = server.takeRequest();
assertEquals(ENV2_PATH, request.getPath());
assertEquals(POST, request.getMethod());
assertEquals(createEnvResp, response);
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class Discovery method createEnvironment.
/**
* Create an environment.
*
* <p>Creates a new environment for private data. An environment must be created before
* collections can be created.
*
* <p>**Note**: You can create only one environment for private data per service instance. An
* attempt to create another environment results in an error.
*
* @param createEnvironmentOptions the {@link CreateEnvironmentOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Environment}
*/
public ServiceCall<Environment> createEnvironment(CreateEnvironmentOptions createEnvironmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createEnvironmentOptions, "createEnvironmentOptions cannot be null");
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createEnvironment");
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", createEnvironmentOptions.name());
if (createEnvironmentOptions.description() != null) {
contentJson.addProperty("description", createEnvironmentOptions.description());
}
if (createEnvironmentOptions.size() != null) {
contentJson.addProperty("size", createEnvironmentOptions.size());
}
builder.bodyJson(contentJson);
ResponseConverter<Environment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Environment>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class Discovery method updateEnvironment.
/**
* Update an environment.
*
* <p>Updates an environment. The environment's **name** and **description** parameters can be
* changed. You must specify a **name** for the environment.
*
* @param updateEnvironmentOptions the {@link UpdateEnvironmentOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link Environment}
*/
public ServiceCall<Environment> updateEnvironment(UpdateEnvironmentOptions updateEnvironmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateEnvironmentOptions, "updateEnvironmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", updateEnvironmentOptions.environmentId());
RequestBuilder builder = RequestBuilder.put(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "updateEnvironment");
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 (updateEnvironmentOptions.name() != null) {
contentJson.addProperty("name", updateEnvironmentOptions.name());
}
if (updateEnvironmentOptions.description() != null) {
contentJson.addProperty("description", updateEnvironmentOptions.description());
}
if (updateEnvironmentOptions.size() != null) {
contentJson.addProperty("size", updateEnvironmentOptions.size());
}
builder.bodyJson(contentJson);
ResponseConverter<Environment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Environment>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class Discovery method deleteEnvironment.
/**
* Delete environment.
*
* @param deleteEnvironmentOptions the {@link DeleteEnvironmentOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link DeleteEnvironmentResponse}
*/
public ServiceCall<DeleteEnvironmentResponse> deleteEnvironment(DeleteEnvironmentOptions deleteEnvironmentOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(deleteEnvironmentOptions, "deleteEnvironmentOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("environment_id", deleteEnvironmentOptions.environmentId());
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteEnvironment");
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<DeleteEnvironmentResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteEnvironmentResponse>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.discovery.v1.model.Environment in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method updateEnvironmentIsSuccessful.
@Test
public void updateEnvironmentIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(updateEnvResp));
UpdateEnvironmentOptions.Builder updateBuilder = new UpdateEnvironmentOptions.Builder(environmentId).name(environmentName);
updateBuilder.description(environmentDesc);
Environment response = discoveryService.updateEnvironment(updateBuilder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(ENV1_PATH, request.getPath());
assertEquals(PUT, request.getMethod());
assertEquals(updateEnvResp, response);
}
Aggregations