Search in sources :

Example 16 with Environment

use of com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment in project java-sdk by watson-developer-cloud.

the class Discovery method createEnvironment.

/**
 * Add an environment.
 *
 * Creates a new environment. You can create only one environment 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 response type of {@link Environment}
 */
public ServiceCall<Environment> createEnvironment(CreateEnvironmentOptions createEnvironmentOptions) {
    Validator.notNull(createEnvironmentOptions, "createEnvironmentOptions cannot be null");
    String[] pathSegments = { "v1/environments" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query(VERSION, versionDate);
    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);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Environment.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Environment(com.ibm.watson.developer_cloud.discovery.v1.model.Environment)

Aggregations

Environment (com.ibm.watson.developer_cloud.discovery.v1.model.Environment)15 Test (org.junit.Test)11 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)7 CreateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateEnvironmentOptions)6 GetEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.GetEnvironmentOptions)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 ListEnvironmentsOptions (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsOptions)4 ListEnvironmentsResponse (com.ibm.watson.developer_cloud.discovery.v1.model.ListEnvironmentsResponse)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Ignore (org.junit.Ignore)3 JsonObject (com.google.gson.JsonObject)2 UpdateEnvironmentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.UpdateEnvironmentOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)1 Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)1 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)1 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)1 DeleteCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.DeleteCollectionOptions)1