diff --git a/README.md b/README.md
index c26c10f1f2e..bc65dfb9fc9 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
* [Concept Insights](alchemy)
* [Conversation](conversation)
* [Dialog](dialog)
+ * [Discovery](discovery)
* [Document Conversion](document-conversion)
* [Language Translation](language-translation)
* [Language Translator](language-translator)
diff --git a/all/pom.xml b/all/pom.xml
index 396f8ae180b..19a8191d493 100644
--- a/all/pom.xml
+++ b/all/pom.xml
@@ -27,6 +27,11 @@
dialog
${project.version}
+
+ ${project.groupId}
+ discovery
+ ${project.version}
+
${project.groupId}
document-conversion
diff --git a/discovery/README.md b/discovery/README.md
new file mode 100644
index 00000000000..abadaec4634
--- /dev/null
+++ b/discovery/README.md
@@ -0,0 +1,30 @@
+# Discovery
+
+## Installation
+
+##### Maven
+```xml
+
+ com.ibm.watson.developer_cloud
+ discovery
+ 3.5.3
+
+```
+
+##### Gradle
+```gradle
+'com.ibm.watson.developer_cloud:discovery:3.5.3'
+```
+
+## Usage
+The [Discovery][discovery] wraps the environment, collection, configuration, document, and query operations of the Discovery service.
+
+```java
+Discovery service = new Discovery("2016-12-15");
+service.setEndpoint("https://gateway.watsonplatform.net/discovery/api/");
+service.setUsernameAndPassword("", "");
+
+//TODO add service
+```
+
+[discovery]: http://www.ibm.com/watson/developercloud/doc/discovery/
diff --git a/discovery/pom.xml b/discovery/pom.xml
new file mode 100644
index 00000000000..c4aea70b05b
--- /dev/null
+++ b/discovery/pom.xml
@@ -0,0 +1,20 @@
+
+
+
+ parent
+ com.ibm.watson.developer_cloud
+ 3.5.3-SNAPSHOT
+
+ 4.0.0
+
+ discovery
+ Discovery
+
+
+
+ ${project.groupId}
+ core
+ ${project.version}
+
+
+
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/Discovery.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/Discovery.java
new file mode 100644
index 00000000000..ca2f936b421
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/Discovery.java
@@ -0,0 +1,435 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1;
+
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CreateCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.DeleteCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.DeleteCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.ConfigurationManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.CreateConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.UpdateConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.CreateDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.CreateDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.DeleteDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.GetDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.GetDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.UpdateDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.CreateEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.CreateEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.DeleteEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryRequest;
+import com.ibm.watson.developer_cloud.http.HttpMediaType;
+import com.ibm.watson.developer_cloud.http.InputStreamRequestBody;
+import com.ibm.watson.developer_cloud.http.RequestBuilder;
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+import com.ibm.watson.developer_cloud.service.WatsonService;
+import com.ibm.watson.developer_cloud.util.GsonSingleton;
+import com.ibm.watson.developer_cloud.util.RequestUtils;
+import com.ibm.watson.developer_cloud.util.ResponseConverterUtils;
+import com.ibm.watson.developer_cloud.util.Validator;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CollectionManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CreateCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.CreateConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.DeleteConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.DeleteConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.UpdateConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.DeleteDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.DocumentManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.UpdateDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.DeleteEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.EnvironmentManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.UpdateEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.UpdateEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.Operator;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryResponse;
+
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Discovery service API for CRUD operations for indexing and searching data.
+ */
+public class Discovery extends WatsonService implements EnvironmentManager, ConfigurationManager, CollectionManager,
+ DocumentManager, QueryManager {
+ private static final String VERSION_DATE = "version";
+ private static final String SERVICE_NAME = "discovery";
+ private static final String FILENAME = "filename";
+ private static final String PATH_ENVIRONMENTS = "/v1/environments";
+ private static final String PATH_ENVIRONMENT = PATH_ENVIRONMENTS + "/%s";
+ private static final String PATH_CONFIGURATIONS = PATH_ENVIRONMENT + "/configurations";
+ private static final String PATH_CONFIGURATION = PATH_CONFIGURATIONS + "/%s";
+ private static final String PATH_COLLECTIONS = PATH_ENVIRONMENT + "/collections";
+ private static final String PATH_COLLECTION = PATH_COLLECTIONS + "/%s";
+ private static final String PATH_FIELDS = PATH_COLLECTION + "/fields";
+ private static final String PATH_DOCUMENTS = PATH_COLLECTION + "/documents";
+ private static final String PATH_DOCUMENT = PATH_DOCUMENTS + "/%s";
+ private static final String PATH_QUERY = PATH_COLLECTION + "/query";
+ private static final Pattern invalidFieldCharactersPattern = Pattern.compile("[^\\w\\.]");
+ private static final Pattern escapeControlCharactersPattern;
+ private static final String INVALID_FIELD_CHARACTER_REPLACEMENT = "_";
+
+ private String versionDate;
+ private static Map supportedMediaTypes = new HashMap();
+
+ static {
+ supportedMediaTypes.put(HttpMediaType.APPLICATION_JSON, MediaType.parse(HttpMediaType.APPLICATION_JSON));
+ supportedMediaTypes.put(HttpMediaType.APPLICATION_MS_WORD, MediaType.parse(HttpMediaType.APPLICATION_MS_WORD));
+ supportedMediaTypes
+ .put(HttpMediaType.APPLICATION_MS_WORD_DOCX, MediaType.parse(HttpMediaType.APPLICATION_MS_WORD_DOCX));
+ supportedMediaTypes.put(HttpMediaType.APPLICATION_PDF, MediaType.parse(HttpMediaType.APPLICATION_PDF));
+ supportedMediaTypes.put(HttpMediaType.TEXT_HTML, MediaType.parse(HttpMediaType.TEXT_HTML));
+ supportedMediaTypes
+ .put(HttpMediaType.APPLICATION_XHTML_XML, MediaType.parse(HttpMediaType.APPLICATION_XHTML_XML));
+
+ List operatorsToEscape = new ArrayList();
+ for (Operator operator : Operator.values()) {
+ if (operator.shouldEscape()) {
+ operatorsToEscape.add(Pattern.quote(operator.getSymbol()));
+ }
+ }
+
+ escapeControlCharactersPattern = Pattern.compile("(" + RequestUtils.join(operatorsToEscape, "|") + ")");
+ }
+
+ /**
+ * Instantiates a new Discovery service.
+ *
+ * @param versionDate the version date
+ */
+ public Discovery(String versionDate) {
+ super(SERVICE_NAME);
+ this.versionDate = versionDate;
+ }
+
+ /**
+ * Utility method to replace unsupported characters in a field name.
+ *
+ * @param fieldName the field name to escape
+ * @return a clean field name
+ */
+ public static String cleanFieldName(String fieldName) {
+ return invalidFieldCharactersPattern.matcher(fieldName).replaceAll(INVALID_FIELD_CHARACTER_REPLACEMENT);
+ }
+
+ /**
+ * Utility method to escape control characters in a value for querying.
+ *
+ * @param value the value that potentially contains control characters
+ * @return a value with control characters escaped
+ */
+ public static String escapeControlChracters(String value) {
+ return escapeControlCharactersPattern.matcher(value)
+ .replaceAll(Matcher.quoteReplacement(Operator.ESCAPE.getSymbol()) + "$1");
+ }
+
+ /**
+ * Ping the service.
+ *
+ * @return true if the service is reachable
+ * @throws RuntimeException if the service is unreachable
+ */
+ public boolean ping() throws RuntimeException {
+ getEnvironments(new GetEnvironmentsRequest.Builder().build()).execute();
+ return true;
+ }
+
+ @Override
+ public ServiceCall getEnvironments(GetEnvironmentsRequest getRequest) {
+ RequestBuilder builder = RequestBuilder.get(String.format(PATH_ENVIRONMENTS));
+ if (getRequest.hasName()) {
+ builder.query(EnvironmentManager.NAME, getRequest.getName());
+ }
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetEnvironmentsResponse.class));
+ }
+
+ @Override
+ public ServiceCall getEnvironment(GetEnvironmentRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.get(String.format(PATH_ENVIRONMENT, getRequest.getEnvironmentId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetEnvironmentResponse.class));
+ }
+
+ @Override
+ public ServiceCall createEnvironment(CreateEnvironmentRequest createRequest) {
+ Validator.notEmpty(createRequest.getName(), EnvironmentManager.NAME + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.post(String.format(PATH_ENVIRONMENTS));
+ builder.bodyJson(GsonSingleton.getGson().toJsonTree(createRequest).getAsJsonObject());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(CreateEnvironmentResponse.class));
+ }
+
+ @Override
+ public ServiceCall deleteEnvironment(DeleteEnvironmentRequest deleteRequest) {
+ Validator.notEmpty(deleteRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .delete(String.format(PATH_ENVIRONMENT, deleteRequest.getEnvironmentId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(DeleteEnvironmentResponse.class));
+ }
+
+ @Override
+ public ServiceCall updateEnvironment(UpdateEnvironmentRequest updateRequest) {
+ Validator.notEmpty(updateRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(updateRequest.getName(), EnvironmentManager.NAME + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.put(String.format(PATH_ENVIRONMENT, updateRequest.getEnvironmentId()));
+ builder.bodyJson(GsonSingleton.getGson().toJsonTree(updateRequest).getAsJsonObject());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(UpdateEnvironmentResponse.class));
+ }
+
+ @Override
+ public ServiceCall getConfigurations(GetConfigurationsRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.get(String.format(PATH_CONFIGURATIONS, getRequest.getEnvironmentId()));
+ if (getRequest.hasName()) {
+ builder.query(ConfigurationManager.NAME, getRequest.getName());
+ }
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetConfigurationsResponse.class));
+ }
+
+ @Override
+ public ServiceCall getConfiguration(GetConfigurationRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(getRequest.getConfigurationId(), ConfigurationManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .get(String.format(PATH_CONFIGURATION, getRequest.getEnvironmentId(), getRequest.getConfigurationId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetConfigurationResponse.class));
+ }
+
+ @Override
+ public ServiceCall createConfiguration(CreateConfigurationRequest createRequest) {
+ Validator.notEmpty(createRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notNull(createRequest.getConfiguration(), ConfigurationManager.CONFIGURATION + " cannot be null");
+ Validator.notEmpty(createRequest.getConfiguration().getName(),
+ ConfigurationManager.CONFIGURATION + "." + ConfigurationManager.NAME + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .post(String.format(PATH_CONFIGURATIONS, createRequest.getEnvironmentId()));
+ builder.bodyJson(GsonSingleton.getGson().toJsonTree(createRequest.getConfiguration(), Configuration.class)
+ .getAsJsonObject());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(CreateConfigurationResponse.class));
+ }
+
+ @Override
+ public ServiceCall deleteConfiguration(DeleteConfigurationRequest deleteRequest) {
+ Validator.notEmpty(deleteRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(deleteRequest.getConfigurationId(), ConfigurationManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.delete(String
+ .format(PATH_CONFIGURATION, deleteRequest.getEnvironmentId(), deleteRequest.getConfigurationId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(DeleteConfigurationResponse.class));
+ }
+
+ @Override
+ public ServiceCall updateConfiguration(UpdateConfigurationRequest updateRequest) {
+ Validator.notEmpty(updateRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(updateRequest.getConfigurationId(), ConfigurationManager.ID + " cannot be empty");
+ Validator.notNull(updateRequest.getConfiguration(), ConfigurationManager.CONFIGURATION + " cannot be null");
+ Validator.notEmpty(updateRequest.getConfiguration().getName(),
+ ConfigurationManager.CONFIGURATION + "." + ConfigurationManager.NAME + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.put(String
+ .format(PATH_CONFIGURATION, updateRequest.getEnvironmentId(), updateRequest.getConfigurationId()));
+ builder.bodyJson(GsonSingleton.getGson().toJsonTree(updateRequest.getConfiguration(), Configuration.class)
+ .getAsJsonObject());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(UpdateConfigurationResponse.class));
+ }
+
+ @Override
+ public ServiceCall getCollections(GetCollectionsRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.get(String.format(PATH_COLLECTIONS, getRequest.getEnvironmentId()));
+ if (getRequest.hasName()) {
+ builder.query(CollectionManager.NAME, getRequest.getName());
+ }
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetCollectionsResponse.class));
+ }
+
+ @Override
+ public ServiceCall getCollection(GetCollectionRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(getRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .get(String.format(PATH_COLLECTION, getRequest.getEnvironmentId(), getRequest.getCollectionId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetCollectionResponse.class));
+ }
+
+ @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(PATH_COLLECTIONS, createRequest.getEnvironmentId()));
+ builder.bodyJson(
+ GsonSingleton.getGson().toJsonTree(createRequest, CreateCollectionRequest.class).getAsJsonObject());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(CreateCollectionResponse.class));
+ }
+
+ @Override
+ public ServiceCall deleteCollection(DeleteCollectionRequest deleteRequest) {
+ Validator.notEmpty(deleteRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(deleteRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.delete(String
+ .format(PATH_COLLECTION, deleteRequest.getEnvironmentId(), deleteRequest.getCollectionId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(DeleteCollectionResponse.class));
+ }
+
+ @Override
+ public ServiceCall getCollectionFields(GetCollectionFieldsRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(getRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .get(String.format(PATH_FIELDS, getRequest.getEnvironmentId(), getRequest.getCollectionId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetCollectionFieldsResponse.class));
+ }
+
+ @Override
+ public ServiceCall getDocument(GetDocumentRequest getRequest) {
+ Validator.notEmpty(getRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(getRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ Validator.notEmpty(getRequest.getDocumentId(), DocumentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.get(String
+ .format(PATH_DOCUMENT, getRequest.getEnvironmentId(), getRequest.getCollectionId(),
+ getRequest.getDocumentId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(GetDocumentResponse.class));
+ }
+
+ @Override
+ public ServiceCall createDocument(CreateDocumentRequest createRequest) {
+ Validator.notEmpty(createRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(createRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder
+ .post(String
+ .format(PATH_DOCUMENTS, createRequest.getEnvironmentId(), createRequest.getCollectionId()));
+ if (createRequest.getConfigurationId() != null) {
+ builder.query(CollectionManager.CONFIGURATION_ID, createRequest.getConfigurationId());
+ }
+ Validator.notNull(createRequest.getFile(), "Document " + FILE + " cannot be null");
+ MediaType mediaType = supportedMediaTypes.get(createRequest.getMediaType());
+ Validator.notNull(mediaType, String.format("Media Type '%s' not supported", createRequest.getMediaType()));
+ RequestBody file = InputStreamRequestBody.create(mediaType, createRequest.getFile());
+ MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
+ multipartBuilder.setType(MultipartBody.FORM);
+ multipartBuilder.addFormDataPart(FILE, FILENAME, file);
+ builder.body(multipartBuilder.build());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(CreateDocumentResponse.class));
+ }
+
+ @Override
+ public ServiceCall deleteDocument(DeleteDocumentRequest deleteRequest) {
+ Validator.notEmpty(deleteRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(deleteRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ Validator.notEmpty(deleteRequest.getDocumentId(), DocumentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.delete(String
+ .format(PATH_DOCUMENT, deleteRequest.getEnvironmentId(), deleteRequest.getCollectionId(),
+ deleteRequest.getDocumentId()));
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(DeleteDocumentResponse.class));
+ }
+
+ @Override
+ public ServiceCall updateDocument(UpdateDocumentRequest updateRequest) {
+ Validator.notEmpty(updateRequest.getEnvironmentId(), EnvironmentManager.ID + " cannot be empty");
+ Validator.notEmpty(updateRequest.getCollectionId(), CollectionManager.ID + " cannot be empty");
+ Validator.notEmpty(updateRequest.getDocumentId(), DocumentManager.ID + " cannot be empty");
+ RequestBuilder builder = RequestBuilder.post(String
+ .format(PATH_DOCUMENT, updateRequest.getEnvironmentId(), updateRequest.getCollectionId(),
+ updateRequest.getDocumentId()));
+ if (updateRequest.getConfigurationId() != null) {
+ builder.query(CollectionManager.CONFIGURATION_ID, updateRequest.getConfigurationId());
+ }
+ Validator.notNull(updateRequest.getFile(), "Document " + FILE + " cannot be null");
+ MediaType mediaType = supportedMediaTypes.get(updateRequest.getMediaType());
+ Validator.notNull(mediaType, String.format("Media Type '%s' not supported", updateRequest.getMediaType()));
+ RequestBody file = InputStreamRequestBody.create(mediaType, updateRequest.getFile());
+ MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
+ multipartBuilder.setType(MultipartBody.FORM);
+ multipartBuilder.addFormDataPart(FILE, FILENAME, file);
+ builder.body(multipartBuilder.build());
+ final Request request = createVersionedRequest(builder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(UpdateDocumentResponse.class));
+ }
+
+ @Override
+ public ServiceCall query(QueryRequest queryRequest) {
+ Validator.notNull(queryRequest.getEnvironmentId(), "Environment ID cannot be null");
+ Validator.notNull(queryRequest.getCollectionId(), "Collection ID cannot be null");
+ RequestBuilder requestBuilder = RequestBuilder
+ .get(String.format(PATH_QUERY, queryRequest.getEnvironmentId(), queryRequest.getCollectionId()));
+ if (queryRequest.getFilter() != null) {
+ requestBuilder.query(FILTER, queryRequest.getFilter());
+ }
+ if (queryRequest.getQuery() != null) {
+ requestBuilder.query(QUERY, queryRequest.getQuery());
+ }
+ if (queryRequest.getAggregation() != null) {
+ requestBuilder.query(AGGREGATION, queryRequest.getAggregation());
+ }
+ if (queryRequest.getCount() > -1) {
+ requestBuilder.query(COUNT, queryRequest.getCount());
+ }
+ if (queryRequest.getOffset() > -1) {
+ requestBuilder.query(OFFSET, queryRequest.getOffset());
+ }
+ if (queryRequest.getReturnFields() != null) {
+ String fields = RequestUtils.join(queryRequest.getReturnFields(), ",");
+ if (!fields.isEmpty()) {
+ requestBuilder.query(RETURN, fields);
+ }
+ }
+ final Request request = createVersionedRequest(requestBuilder);
+ return createServiceCall(request, ResponseConverterUtils.getObject(QueryResponse.class));
+ }
+
+ private Request createVersionedRequest(RequestBuilder requestBuilder) {
+ Validator.notEmpty(versionDate, "versionDate cannot be empty");
+ return requestBuilder.query(VERSION_DATE, versionDate).build();
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/Collection.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/Collection.java
new file mode 100644
index 00000000000..d29c6f69f74
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/Collection.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.Date;
+
+/**
+ * A Collection holds the documents that have been ingested and allows querying against it.
+ */
+public class Collection extends GenericModel {
+ @SerializedName(CollectionManager.ID)
+ private String collectionId;
+ @SerializedName(CollectionManager.NAME)
+ private String name;
+ @SerializedName(CollectionManager.STATUS)
+ private Status status;
+ @SerializedName(CollectionManager.CREATED)
+ private Date created;
+ @SerializedName(CollectionManager.UPDATED)
+ private Date updated;
+ @SerializedName(CollectionManager.DESCRIPTION)
+ private String description;
+ @SerializedName(CollectionManager.CONFIGURATION_ID)
+ private String configurationId;
+ @SerializedName(CollectionManager.LANGUAGE)
+ private String language;
+ @SerializedName(CollectionManager.DOCUMENT_COUNTS)
+ private DocumentCounts documentCounts;
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public DocumentCounts getDocumentCounts() {
+ return documentCounts;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CollectionManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CollectionManager.java
new file mode 100644
index 00000000000..7d46d9af06d
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CollectionManager.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsRequest;
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.Field;
+
+/**
+ * Interface defining the constants and methods associated with Collections.
+ *
+ * @see Collection
+ */
+public interface CollectionManager {
+ String COLLECTIONS = "collections";
+
+ //Collection
+ String ID = "collection_id";
+ String NAME = "name";
+ String DESCRIPTION = "description";
+ String CREATED = "created";
+ String UPDATED = "update";
+ String STATUS = "status";
+ String CONFIGURATION_ID = "configuration_id";
+ String LANGUAGE = "language";
+ String DOCUMENT_COUNTS = "document_counts";
+
+ //Document Counts
+ String AVAILABLE = "available";
+ String PROCESSING = "processing";
+ String FAILED = "failed";
+
+ //Fields
+ String FIELDS = "fields";
+ String FIELD = "field";
+ String TYPE = "type";
+
+ /**
+ * Gets a list of {@link Collection}. An optional parameter of name can be provided to filter by name.
+ *
+ * @param getRequest options for getting the {@link Collection}s
+ * @return a {@link GetCollectionsResponse} containing the result of {@link GetCollectionsRequest}
+ */
+ ServiceCall getCollections(GetCollectionsRequest getRequest);
+
+ /**
+ * Gets a {@link Collection}.
+ *
+ * @param getRequest options for getting the {@link Collection}
+ * @return a {@link GetCollectionResponse} containing the result of {@link GetCollectionRequest}
+ */
+ ServiceCall getCollection(GetCollectionRequest getRequest);
+
+ /**
+ * Creates a {@link Collection}.
+ *
+ * @param createRequest options for creating a {@link Collection}
+ * @return a {@link CreateCollectionResponse} containing the result of {@link CreateCollectionRequest}
+ */
+ ServiceCall createCollection(CreateCollectionRequest createRequest);
+
+ /**
+ * Deletes a {@link Collection}.
+ *
+ * @param deleteRequest options for deleting a {@link Collection}
+ * @return a {@link DeleteCollectionResponse} containing the result of {@link DeleteCollectionRequest}
+ */
+ ServiceCall deleteCollection(DeleteCollectionRequest deleteRequest);
+
+ /**
+ * Gets a list of unique {@link Field}s from a {@link Collection}.
+ *
+ * @param getRequest options for getting a unique fields from a {@link Collection}
+ * @return a {@link GetCollectionFieldsResponse} containing the result of {@link GetCollectionFieldsRequest}
+ */
+ ServiceCall getCollectionFields(GetCollectionFieldsRequest getRequest);
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionRequest.java
new file mode 100644
index 00000000000..87567d5367a
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionRequest.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to create a {@link Collection}.
+ */
+public class CreateCollectionRequest extends GenericModel {
+ private final String environmentId;
+ private final String name;
+ private final String description;
+ private final String configurationId;
+ private final String language;
+
+ private CreateCollectionRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.name = builder.name;
+ this.description = builder.description;
+ this.configurationId = builder.configurationId;
+ this.language = builder.language;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public String getLanguage() {
+ return language;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String name;
+ private final String configurationId;
+ private String description;
+ private String language;
+
+ public Builder(String environmentId, String configurationId, String name) {
+ this.environmentId = environmentId;
+ this.configurationId = configurationId;
+ this.name = name;
+ }
+
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public Builder language(String language) {
+ this.language = language;
+ return this;
+ }
+
+ public CreateCollectionRequest build() {
+ return new CreateCollectionRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionResponse.java
new file mode 100644
index 00000000000..663dcf6c71c
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/CreateCollectionResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+/**
+ * Response from {@link CreateCollectionRequest}.
+ */
+public class CreateCollectionResponse extends Collection {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionRequest.java
new file mode 100644
index 00000000000..a9ff19aaa83
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to delete a {@link Collection}.
+ */
+public class DeleteCollectionRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+
+ private DeleteCollectionRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+
+ public Builder(String environmentId, String collectionId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ }
+
+ public DeleteCollectionRequest build() {
+ return new DeleteCollectionRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionResponse.java
new file mode 100644
index 00000000000..52bd373b61a
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DeleteCollectionResponse.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Response from {@link DeleteCollectionRequest}.
+ */
+public class DeleteCollectionResponse extends GenericModel {
+ @SerializedName(CollectionManager.ID)
+ private String collectionId;
+ @SerializedName(CollectionManager.STATUS)
+ private Status status;
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DocumentCounts.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DocumentCounts.java
new file mode 100644
index 00000000000..a512fbc4852
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/DocumentCounts.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Shows the document counts in the collection.
+ */
+public class DocumentCounts extends GenericModel {
+ @SerializedName(CollectionManager.AVAILABLE)
+ private Long available;
+ @SerializedName(CollectionManager.PROCESSING)
+ private Long processing;
+ @SerializedName(CollectionManager.FAILED)
+ private Long failed;
+
+ public Long getAvailable() {
+ return available;
+ }
+
+ public Long getProcessing() {
+ return processing;
+ }
+
+ public Long getFailed() {
+ return failed;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionRequest.java
new file mode 100644
index 00000000000..392afe7727f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a {@link Collection}.
+ */
+public class GetCollectionRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+
+ private GetCollectionRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+
+ public Builder(String environmentId, String collectionId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ }
+
+ public GetCollectionRequest build() {
+ return new GetCollectionRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionResponse.java
new file mode 100644
index 00000000000..655b1f05543
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+/**
+ * Response from {@link GetCollectionRequest}.
+ */
+public class GetCollectionResponse extends Collection {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsRequest.java
new file mode 100644
index 00000000000..fa6de11649e
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsRequest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a list of {@link Collection}s.
+ */
+public class GetCollectionsRequest extends GenericModel {
+ private final String environmentId;
+ private final String name;
+
+ private GetCollectionsRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.name = builder.name;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean hasName() {
+ return name != null;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private String name;
+
+ public Builder(String environmentId) {
+ this.environmentId = environmentId;
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public GetCollectionsRequest build() {
+ return new GetCollectionsRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsResponse.java
new file mode 100644
index 00000000000..1b66521026d
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/GetCollectionsResponse.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Response from {@link GetCollectionsRequest}.
+ */
+public class GetCollectionsResponse extends GenericModel {
+ @SerializedName(CollectionManager.COLLECTIONS)
+ private List collections;
+
+ public List getCollections() {
+ return collections;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/Field.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/Field.java
new file mode 100644
index 00000000000..eba0b1a1f7c
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/Field.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection.field;
+
+import com.google.gson.annotations.JsonAdapter;
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CollectionManager;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Field contains name and type of an indexed field.
+ */
+@JsonAdapter(FieldAdapterFactory.class)
+public class Field extends GenericModel {
+ @SerializedName(CollectionManager.FIELD)
+ private String field;
+ @SerializedName(CollectionManager.TYPE)
+ private Type type;
+
+ public Field(String field, Type type) {
+ this.field = field;
+ this.type = type;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public Type getType() {
+ if (type == null) {
+ type = Type.UNKNOWN;
+ }
+ return type;
+ }
+
+ public enum Type {
+ @SerializedName("nested")NESTED,
+ @SerializedName("string")STRING,
+ @SerializedName("date")DATE,
+ @SerializedName("long")LONG,
+ @SerializedName("integer")INTEGER,
+ @SerializedName("short")SHORT,
+ @SerializedName("byte")BYTE,
+ @SerializedName("double")DOUBLE,
+ @SerializedName("float")FLOAT,
+ @SerializedName("boolean")BOOLEAN,
+ @SerializedName("binary")BINARY,
+ UNKNOWN
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/FieldAdapterFactory.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/FieldAdapterFactory.java
new file mode 100644
index 00000000000..3d783283680
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/FieldAdapterFactory.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection.field;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+
+/**
+ * Override default enum handling for poorly formed JSON field types schema.
+ */
+public class FieldAdapterFactory implements TypeAdapterFactory {
+ @Override
+ public TypeAdapter create(Gson gson, TypeToken typeToken) {
+ if (!Field.class.isAssignableFrom(typeToken.getRawType())) {
+ return null;
+ }
+ return (TypeAdapter) new FieldAdapter();
+ }
+
+ private class FieldAdapter extends TypeAdapter {
+ @Override
+ public void write(JsonWriter out, Field value) throws IOException {
+ out.beginObject();
+ out.name("field");
+ out.value(value.getField());
+ out.name("type");
+ out.value(value.getType().toString());
+ out.endObject();
+ }
+
+ @Override
+ public Field read(JsonReader in) throws IOException {
+ Field field = null;
+ String fieldName = null;
+ Field.Type type = Field.Type.UNKNOWN;
+ in.beginObject();
+ while (in.hasNext()) {
+ String name = in.nextName();
+ if (name.equals("field")) {
+ fieldName = in.nextString();
+ } else if (name.equals("type")) {
+ JsonToken token = in.peek();
+
+ if (token.equals(JsonToken.STRING)) {
+ try {
+ type = Field.Type.valueOf(in.nextString().toUpperCase());
+ } catch (IllegalArgumentException e) {
+ //invalid field type
+ }
+ } else {
+ in.skipValue();
+ }
+ }
+ }
+ in.endObject();
+ return new Field(fieldName, type);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsRequest.java
new file mode 100644
index 00000000000..7af9d2ae979
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsRequest.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection.field;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.Collection;
+
+/**
+ * Request to get a list of {@link Field}s from a {@link Collection}.
+ */
+public class GetCollectionFieldsRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+
+ private GetCollectionFieldsRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+
+ public Builder(String environmentId, String collectionId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ }
+
+ public GetCollectionFieldsRequest build() {
+ return new GetCollectionFieldsRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsResponse.java
new file mode 100644
index 00000000000..948622b8fb7
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/collection/field/GetCollectionFieldsResponse.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.collection.field;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CollectionManager;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Response from {@link GetCollectionFieldsRequest}.
+ */
+public class GetCollectionFieldsResponse extends GenericModel {
+ @SerializedName(CollectionManager.FIELDS)
+ private List fields;
+
+ public List getFields() {
+ return fields;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/CommonManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/CommonManager.java
new file mode 100644
index 00000000000..59232e0813a
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/CommonManager.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.common;
+
+/**
+ * Interface containing constants common across multiple managers.
+ */
+public interface CommonManager {
+ //Notices (Warnings & Errors)
+ String NOTICES = "notices";
+ String NOTICE_ID = "notice_id";
+ String CREATED = "created";
+ String SEVERITY = "severity";
+ String STEP = "step";
+ String DESCRIPTION = "description";
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/EagerNumberAdapterFactory.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/EagerNumberAdapterFactory.java
new file mode 100644
index 00000000000..596c48cf4fb
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/EagerNumberAdapterFactory.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.common;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.internal.LazilyParsedNumber;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.ParseException;
+
+/**
+ * Override the default {@link LazilyParsedNumber} for parsing {@link Number}s.
+ */
+public class EagerNumberAdapterFactory implements TypeAdapterFactory {
+ @Override
+ public TypeAdapter create(Gson gson, TypeToken typeToken) {
+ if (!Number.class.isAssignableFrom(typeToken.getRawType())) {
+ return null;
+ }
+ return (TypeAdapter) new NumberTypeAdapter();
+ }
+
+ private class NumberTypeAdapter extends TypeAdapter {
+ private final NumberFormat numberFormat = new DecimalFormat();
+
+ @Override
+ public void write(JsonWriter out, Number value) throws IOException {
+ out.value(numberFormat.format(value));
+ }
+
+ @Override
+ public Number read(JsonReader in) throws IOException {
+ try {
+ return numberFormat.parse(in.nextString());
+ } catch (ParseException e) {
+ throw new IOException("Not a number", e);
+ }
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Notice.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Notice.java
new file mode 100644
index 00000000000..615739a1949
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Notice.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.common;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Notice is a warning or error on a Document or Configuration deletion.
+ */
+public class Notice extends GenericModel {
+ @SerializedName(CommonManager.NOTICE_ID)
+ private String noticeId;
+ //Only exists in Configuration Deletion
+ @SerializedName(CommonManager.CREATED)
+ private String created;
+ //TODO make an enum
+ @SerializedName(CommonManager.SEVERITY)
+ private String severity;
+ //Only exists in Document Get
+ @SerializedName(CommonManager.STEP)
+ private String step;
+ @SerializedName(CommonManager.DESCRIPTION)
+ private String description;
+
+ public String getNoticeId() {
+ return noticeId;
+ }
+
+ public String getCreated() {
+ return created;
+ }
+
+ public String getSeverity() {
+ return severity;
+ }
+
+ public String getStep() {
+ return step;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Status.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Status.java
new file mode 100644
index 00000000000..6ebc207d8ee
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/common/Status.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.common;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Common status enumeration used for Environments, Configurations, Collections, and Documents.
+ *
+ * "deleted" is only used on delete requests
+ */
+public enum Status {
+ @SerializedName("active")
+ ACTIVE,
+ @SerializedName("pending")
+ PENDING,
+ @SerializedName("deleted")
+ DELETED
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Configuration.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Configuration.java
new file mode 100644
index 00000000000..ec2b615f18c
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Configuration.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.Document;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * A Configuration is used to define how a {@link Document} will be ingested.
+ * It contains various settings for different file types and various steps of the ingestion process.
+ *
+ * The three basic steps are Conversions, Enrichments, and Normalizations
+ *
+ * @see Conversions
+ * @see Enrichment
+ * @see NormalizationOperation
+ */
+public class Configuration extends GenericModel {
+ @SerializedName(ConfigurationManager.ID)
+ private String configurationId;
+ @SerializedName(ConfigurationManager.NAME)
+ private String name;
+ @SerializedName(ConfigurationManager.DESCRIPTION)
+ private String description;
+ @SerializedName(ConfigurationManager.CREATED)
+ private Date created;
+ @SerializedName(ConfigurationManager.UPDATED)
+ private Date updated;
+ @SerializedName(ConfigurationManager.CONVERSIONS)
+ private Conversions conversions;
+ @SerializedName(ConfigurationManager.ENRICHMENTS)
+ private List enrichments;
+ @SerializedName(ConfigurationManager.NORMALIZATIONS)
+ private List normalizations;
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public Conversions getConversions() {
+ return conversions;
+ }
+
+ public List getEnrichments() {
+ return enrichments;
+ }
+
+ public List getNormalizations() {
+ return normalizations;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ConfigurationManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ConfigurationManager.java
new file mode 100644
index 00000000000..82df675d1fe
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ConfigurationManager.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+
+/**
+ * Interface defining the constants and methods associated with Configurations.
+ *
+ * @see Configuration
+ */
+public interface ConfigurationManager {
+ String CONFIGURATIONS = "configurations";
+ String CONFIGURATION = "configuration";
+
+ //Configuration
+ String ID = "configuration_id";
+ String NAME = "name";
+ String DESCRIPTION = "description";
+ String CREATED = "created";
+ String UPDATED = "updated";
+ String CONVERSIONS = "conversions";
+ String ENRICHMENTS = "enrichments";
+ String NORMALIZATIONS = "normalizations";
+
+ //Conversion Types
+ String PDF = "pdf";
+ String WORD = "word";
+ String HTML = "html";
+ String JSON = "json";
+
+ //Conversion -> PDF/Word
+ String HEADING = "heading";
+
+ //Conversion -> PDF/Word -> Heading
+ String FONT_SETTINGS = "fonts";
+ String FONT_STYLES = "styles";
+
+ //Conversion -> PDF/Word -> Heading -> FontSettings
+ String LEVEL = "level";
+ String MIN_SIZE = "min_size";
+ String MAX_SIZE = "max_size";
+ String BOLD = "bold";
+ String ITALIC = "italic";
+ String FONT_NAME = "name";
+
+ //Conversion -> PDF/Word -> Heading -> FontStyles
+ String NAMES = "names";
+
+ //Conversion -> HTML
+ String EXCLUDE_TAGS_COMPLETELY = "exclude_tags_completely";
+ String EXCLUDE_TAGS_KEEP_CONTENT = "exclude_tags_keep_content";
+ String KEEP_CONTENT = "keep_content";
+ String EXCLUDE_CONTENT = "exclude_content";
+ String KEEP_TAG_ATTRIBUTES = "keep_tag_attributes";
+ String EXCLUDE_TAG_ATTRIBUTES = "exclude_tag_attributes";
+
+ //Conversion -> HTML -> ContentSelector
+ String XPATHS = "xpaths";
+
+ //Normalizations & Conversion -> JSON
+ String OPERATION = "operation";
+ String SOURCE_FIELD = "source_field";
+ String DESTINATION_FIELD = "destination_field";
+
+ //Enrichments -> Enrichment
+ //includes DESCRIPTION, SOURCE_FIELD, DESTINATION_FIELD
+ String OVERWRITE = "overwrite";
+ String ENRICHMENT = "enrichment";
+ String OPTIONS = "options";
+
+ //Fields
+ String FIELD = "field";
+ String TYPE = "type";
+
+ String STATUS = "status";
+
+ /**
+ * Lists existing configurations. Optional query param of name can be used to search for configurations by name.
+ *
+ * @param getRequest options for getting the configurations
+ * @return a {@link GetConfigurationsResponse} containing result of the {@link GetConfigurationsRequest}
+ */
+ ServiceCall getConfigurations(GetConfigurationsRequest getRequest);
+
+ /**
+ * Gets configuration details.
+ *
+ * @param getRequest options for getting the configuration
+ * @return a {@link GetConfigurationResponse} containing result of the {@link GetConfigurationRequest}
+ */
+ ServiceCall getConfiguration(GetConfigurationRequest getRequest);
+
+ /**
+ * Creates a configuration.
+ *
+ * @param createRequest options for creating the configuration
+ * @return a {@link CreateConfigurationResponse} containing the result of the {@link CreateConfigurationRequest}
+ */
+ ServiceCall createConfiguration(CreateConfigurationRequest createRequest);
+
+ /**
+ * Deletes an existing configuration. The delete is performed unconditionally.
+ * A configuration delete request will succeed even if the configuration is referenced by a
+ * collection or document ingestion. However, documents which have already been submitted for processing will
+ * continue to use the deleted configuration (documents are always processed with a snapshot of the
+ * configuration as it existed at the time the document was submitted).
+ *
+ * @param deleteRequest options for deleting the configuration
+ * @return a {@link DeleteConfigurationResponse} containing the result of the {@link DeleteConfigurationRequest}
+ */
+ ServiceCall deleteConfiguration(DeleteConfigurationRequest deleteRequest);
+
+ /**
+ * Replaces an existing configuration.
+ * - Completely replaces the original configuration that was here before.
+ * - The 'configuration_id', 'updated', and 'created' fields accepted in the request,
+ * but they are ignored (an error is not generated). It is also acceptable for users to submit an
+ * updated config with none of the three properties.
+ * - Documents are processed with a snapshot of the configuration as it was at the time the document
+ * was submitted to be ingested. This means that already submitted documents will not see any updates
+ * made to the configuration.
+ *
+ * @param updateRequest options for updating the configuration
+ * @return a {@link UpdateConfigurationResponse} containing the result of the {@link UpdateConfigurationRequest}
+ */
+ ServiceCall updateConfiguration(UpdateConfigurationRequest updateRequest);
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ContentSelector.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ContentSelector.java
new file mode 100644
index 00000000000..decfb6e548f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/ContentSelector.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * ContentSelector allows you to define an xPath to retrieve content from an XML document.
+ *
+ * @see Html
+ */
+public class ContentSelector extends GenericModel {
+ @SerializedName(ConfigurationManager.XPATHS)
+ private List xpaths;
+
+ public List getXpaths() {
+ return xpaths;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Conversions.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Conversions.java
new file mode 100644
index 00000000000..23363f590e5
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Conversions.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Conversions define the steps associated with various filetypes.
+ *
+ * @see Pdf
+ * @see Word
+ * @see Html
+ * @see NormalizationOperation (Json)
+ */
+public class Conversions extends GenericModel {
+ @SerializedName(ConfigurationManager.PDF)
+ private Pdf pdf;
+ @SerializedName(ConfigurationManager.WORD)
+ private Word word;
+ @SerializedName(ConfigurationManager.HTML)
+ private Html html;
+ @SerializedName(ConfigurationManager.JSON)
+ private List json;
+
+ public Pdf getPdf() {
+ return pdf;
+ }
+
+ public Word getWord() {
+ return word;
+ }
+
+ public Html getHtml() {
+ return html;
+ }
+
+ public List getJson() {
+ return json;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationRequest.java
new file mode 100644
index 00000000000..23d9edfdb44
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationRequest.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to create a {@link Configuration}.
+ */
+public class CreateConfigurationRequest extends GenericModel {
+ private final String environmentId;
+ private final Configuration configuration;
+
+ private CreateConfigurationRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.configuration = builder.configuration;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private Configuration configuration;
+
+ public Builder(String environmentId) {
+ this.environmentId = environmentId;
+ }
+
+ public Builder configuration(Configuration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ public CreateConfigurationRequest build() {
+ return new CreateConfigurationRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationResponse.java
new file mode 100644
index 00000000000..55073539fe3
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/CreateConfigurationResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+/**
+ * Response from {@link CreateConfigurationRequest}.
+ */
+public class CreateConfigurationResponse extends Configuration {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationRequest.java
new file mode 100644
index 00000000000..051e0e17e62
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to delete a {@link Configuration}.
+ */
+public class DeleteConfigurationRequest extends GenericModel {
+ private final String environmentId;
+ private final String configurationId;
+
+ private DeleteConfigurationRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.configurationId = builder.configurationId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String configurationId;
+
+ public Builder(String environmentId, String configurationId) {
+ this.environmentId = environmentId;
+ this.configurationId = configurationId;
+ }
+
+ public DeleteConfigurationRequest build() {
+ return new DeleteConfigurationRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationResponse.java
new file mode 100644
index 00000000000..5e9e300c3cb
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/DeleteConfigurationResponse.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.CommonManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Notice;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Response from a {@link DeleteConfigurationRequest}.
+ * The response contains a {@link Notice} if the configuration was referenced by at least one collection.
+ */
+public class DeleteConfigurationResponse extends GenericModel {
+ @SerializedName(ConfigurationManager.ID)
+ private String configurationId;
+ @SerializedName(ConfigurationManager.STATUS)
+ private Status status;
+ @SerializedName(CommonManager.NOTICES)
+ private List notices;
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public List getNotices() {
+ return notices;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Enrichment.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Enrichment.java
new file mode 100644
index 00000000000..8881c3f64fc
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Enrichment.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.Map;
+
+/**
+ * An Enrichment contains configuration pertaining to which fields Watson should extract metadata from.
+ */
+public class Enrichment extends GenericModel {
+ @SerializedName(ConfigurationManager.DESCRIPTION)
+ private String description;
+ @SerializedName(ConfigurationManager.DESTINATION_FIELD)
+ private String destinationField;
+ @SerializedName(ConfigurationManager.SOURCE_FIELD)
+ private String sourceField;
+ @SerializedName(ConfigurationManager.OVERWRITE)
+ private boolean overwrite;
+ @SerializedName(ConfigurationManager.ENRICHMENT)
+ private String enrichment;
+ @SerializedName(ConfigurationManager.OPTIONS)
+ private Map options;
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getDestinationField() {
+ return destinationField;
+ }
+
+ public String getSourceField() {
+ return sourceField;
+ }
+
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+ public String getEnrichment() {
+ return enrichment;
+ }
+
+ public Map getOptions() {
+ return options;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontSetting.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontSetting.java
new file mode 100644
index 00000000000..719f872661f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontSetting.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Contains basic settings for a font.
+ */
+public class FontSetting extends GenericModel {
+ @SerializedName(ConfigurationManager.LEVEL)
+ private Number level;
+ @SerializedName(ConfigurationManager.MIN_SIZE)
+ private Number minSize;
+ @SerializedName(ConfigurationManager.MAX_SIZE)
+ private Number maxSize;
+ @SerializedName(ConfigurationManager.BOLD)
+ private boolean bold;
+ @SerializedName(ConfigurationManager.ITALIC)
+ private boolean italic;
+ @SerializedName(ConfigurationManager.FONT_NAME)
+ private String fontName;
+
+ public Number getLevel() {
+ return level;
+ }
+
+ public Number getMinSize() {
+ return minSize;
+ }
+
+ public Number getMaxSize() {
+ return maxSize;
+ }
+
+ public boolean isBold() {
+ return bold;
+ }
+
+ public boolean isItalic() {
+ return italic;
+ }
+
+ public String getFontName() {
+ return fontName;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontStyles.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontStyles.java
new file mode 100644
index 00000000000..6544e57b304
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/FontStyles.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Contains basic styles for a font.
+ */
+public class FontStyles extends GenericModel {
+ @SerializedName(ConfigurationManager.LEVEL)
+ private Number level;
+ @SerializedName(ConfigurationManager.NAMES)
+ private List names;
+
+ public Number getLevel() {
+ return level;
+ }
+
+ public List getNames() {
+ return names;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationRequest.java
new file mode 100644
index 00000000000..cff6b2d5c71
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a single {@link Configuration}.
+ */
+public class GetConfigurationRequest extends GenericModel {
+ private final String environmentId;
+ private final String configurationId;
+
+ private GetConfigurationRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.configurationId = builder.configurationId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String configurationId;
+
+ public Builder(String environmentId, String configurationId) {
+ this.environmentId = environmentId;
+ this.configurationId = configurationId;
+ }
+
+ public GetConfigurationRequest build() {
+ return new GetConfigurationRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationResponse.java
new file mode 100644
index 00000000000..95b6a4daf67
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+/**
+ * Response from {@link GetConfigurationRequest}.
+ */
+public class GetConfigurationResponse extends Configuration {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsRequest.java
new file mode 100644
index 00000000000..6626d8754bf
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsRequest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a list of {@link Configuration}s.
+ */
+public class GetConfigurationsRequest extends GenericModel {
+ private final String environmentId;
+ private final String name;
+
+ private GetConfigurationsRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.name = builder.name;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean hasName() {
+ return name != null;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private String name;
+
+ public Builder(String environmentId) {
+ this.environmentId = environmentId;
+ }
+
+ public GetConfigurationsRequest build() {
+ return new GetConfigurationsRequest(this);
+ }
+
+ public void name(String name) {
+ this.name = name;
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsResponse.java
new file mode 100644
index 00000000000..d654f4bbadb
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/GetConfigurationsResponse.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Response from {@link GetConfigurationsRequest}.
+ */
+public class GetConfigurationsResponse extends GenericModel {
+ @SerializedName(ConfigurationManager.CONFIGURATIONS)
+ private List configurations;
+
+ public List getConfigurations() {
+ return configurations;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Heading.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Heading.java
new file mode 100644
index 00000000000..754f9a604d2
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Heading.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Heading settings in a PDF or Word document.
+ *
+ * @see Pdf
+ * @see Word
+ */
+public class Heading extends GenericModel {
+ @SerializedName(ConfigurationManager.FONT_SETTINGS)
+ private List fontSettings;
+ @SerializedName(ConfigurationManager.FONT_STYLES)
+ private FontStyles fontStyles;
+
+ public List getFontSettings() {
+ return fontSettings;
+ }
+
+ public FontStyles getFontStyles() {
+ return fontStyles;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Html.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Html.java
new file mode 100644
index 00000000000..4f508aefb80
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Html.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Configuration options for an HTML document.
+ */
+public class Html extends GenericModel {
+ @SerializedName(ConfigurationManager.EXCLUDE_TAGS_COMPLETELY)
+ private List excludeTagsCompletely;
+ @SerializedName(ConfigurationManager.EXCLUDE_TAGS_KEEP_CONTENT)
+ private List excludeTagsKeepContent;
+ @SerializedName(ConfigurationManager.KEEP_CONTENT)
+ private ContentSelector keepContent;
+ @SerializedName(ConfigurationManager.EXCLUDE_CONTENT)
+ private ContentSelector excludeContent;
+ @SerializedName(ConfigurationManager.KEEP_TAG_ATTRIBUTES)
+ private List keepTagAttributes;
+ @SerializedName(ConfigurationManager.EXCLUDE_TAG_ATTRIBUTES)
+ private List excludeTagAttributes;
+
+ public List getExcludeTagsCompletely() {
+ return excludeTagsCompletely;
+ }
+
+ public List getExcludeTagsKeepContent() {
+ return excludeTagsKeepContent;
+ }
+
+ public ContentSelector getKeepContent() {
+ return keepContent;
+ }
+
+ public ContentSelector getExcludeContent() {
+ return excludeContent;
+ }
+
+ public List getKeepTagAttributes() {
+ return keepTagAttributes;
+ }
+
+ public List getExcludeTagAttributes() {
+ return excludeTagAttributes;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/NormalizationOperation.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/NormalizationOperation.java
new file mode 100644
index 00000000000..6bb0db04d90
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/NormalizationOperation.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Configuration options for a JSON document.
+ */
+public class NormalizationOperation extends GenericModel {
+ //TODO make this an enum
+ @SerializedName(ConfigurationManager.OPERATION)
+ private String operation;
+ @SerializedName(ConfigurationManager.SOURCE_FIELD)
+ private String sourceField;
+ @SerializedName(ConfigurationManager.DESTINATION_FIELD)
+ private String destinationField;
+
+ public String getOperation() {
+ return operation;
+ }
+
+ public String getSourceField() {
+ return sourceField;
+ }
+
+ public String getDestinationField() {
+ return destinationField;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Pdf.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Pdf.java
new file mode 100644
index 00000000000..7afb5161b43
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Pdf.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Configuration options for a PDF document.
+ */
+public class Pdf extends GenericModel {
+ @SerializedName(ConfigurationManager.HEADING)
+ private Heading heading;
+
+ public Heading getHeading() {
+ return heading;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationRequest.java
new file mode 100644
index 00000000000..1f7c4f70828
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationRequest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to update a {@link Configuration}.
+ */
+public class UpdateConfigurationRequest extends GenericModel {
+ private final String environmentId;
+ private final String configurationId;
+ private final Configuration configuration;
+
+ private UpdateConfigurationRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.configurationId = builder.configurationId;
+ this.configuration = builder.configuration;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String configurationId;
+ private Configuration configuration;
+
+ public Builder(String environmentId, String configurationId) {
+ this.environmentId = environmentId;
+ this.configurationId = configurationId;
+ }
+
+ public Builder configuration(Configuration configuration) {
+ this.configuration = configuration;
+ return this;
+ }
+
+ public UpdateConfigurationRequest build() {
+ return new UpdateConfigurationRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationResponse.java
new file mode 100644
index 00000000000..91f4cc06782
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/UpdateConfigurationResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+/**
+ * Response from {@link UpdateConfigurationRequest}.
+ */
+public class UpdateConfigurationResponse extends Configuration {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Word.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Word.java
new file mode 100644
index 00000000000..330165e6258
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/configuration/Word.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.configuration;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Configuration options for a Microsoft Word document.
+ */
+public class Word extends GenericModel {
+ @SerializedName(ConfigurationManager.HEADING)
+ private Heading heading;
+
+ public Heading getHeading() {
+ return heading;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentRequest.java
new file mode 100644
index 00000000000..45a02e328e4
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentRequest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.google.gson.JsonObject;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * Request to create a {@link Document}.
+ */
+public class CreateDocumentRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+ private String configurationId;
+ private JsonObject metadata;
+ private InputStream file;
+ private String mediaType;
+ //TODO add configuration
+
+ protected CreateDocumentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ this.configurationId = builder.configurationId;
+ this.metadata = builder.metadata;
+ this.file = builder.file;
+ this.mediaType = builder.mediaType;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public JsonObject getMetadata() {
+ return metadata;
+ }
+
+ public InputStream getFile() {
+ return file;
+ }
+
+ public String getMediaType() {
+ return mediaType;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+ private String configurationId;
+ private JsonObject metadata;
+ private InputStream file;
+ private String mediaType;
+
+ public Builder(String environmentId, String collectionId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ }
+
+ public Builder configurationId(String configurationId) {
+ this.configurationId = configurationId;
+ return this;
+ }
+
+ public Builder metadata(JsonObject metadata) {
+ this.metadata = metadata;
+ return this;
+ }
+
+ public Builder inputStream(InputStream file, String mediaType) {
+ this.file = file;
+ this.mediaType = mediaType;
+ return this;
+ }
+
+ public Builder file(File inputFile, String mediaType) {
+ InputStream file;
+ try {
+ file = new FileInputStream(inputFile);
+ this.mediaType = mediaType;
+ } catch (FileNotFoundException e) {
+ file = null;
+ }
+ this.file = file;
+ return this;
+ }
+
+ public CreateDocumentRequest build() {
+ return new CreateDocumentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentResponse.java
new file mode 100644
index 00000000000..4617354005a
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/CreateDocumentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+/**
+ * Response from {@link CreateDocumentRequest}.
+ */
+public class CreateDocumentResponse extends Document {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentRequest.java
new file mode 100644
index 00000000000..e0e252b643b
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentRequest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to delete a {@link Document}.
+ */
+public class DeleteDocumentRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+
+ private DeleteDocumentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ this.documentId = builder.documentId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getDocumentId() {
+ return documentId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+
+ public Builder(String environmentId, String collectionId, String documentId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ this.documentId = documentId;
+ }
+
+ public DeleteDocumentRequest build() {
+ return new DeleteDocumentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentResponse.java
new file mode 100644
index 00000000000..128fe41aa4d
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DeleteDocumentResponse.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Response from {@link DeleteDocumentRequest}.
+ */
+public class DeleteDocumentResponse extends GenericModel {
+ @SerializedName(DocumentManager.ID)
+ private String documentId;
+ @SerializedName(DocumentManager.STATUS)
+ private Status status;
+
+ public String getDocumentId() {
+ return documentId;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/Document.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/Document.java
new file mode 100644
index 00000000000..98e63e13983
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/Document.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.CommonManager;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Notice;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryManager;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * A Document contains the processing status and notices, if any, for a document in the index.
+ * It does not return the document itself.
+ *
+ * @see QueryManager to see how to fetch the actual document content.
+ */
+public class Document extends GenericModel {
+ @SerializedName(DocumentManager.ID)
+ private String documentId;
+ @SerializedName(DocumentManager.CONFIGURATION_ID)
+ private String configurationId;
+ @SerializedName(DocumentManager.CREATED)
+ private Date created;
+ @SerializedName(DocumentManager.UPDATED)
+ private Date updated;
+ @SerializedName(DocumentManager.STATUS)
+ private Status status;
+ @SerializedName(DocumentManager.STATUS_DESCRIPTION)
+ private String statusDescription;
+ @SerializedName(CommonManager.NOTICES)
+ private List notices;
+
+ public String getDocumentId() {
+ return documentId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public String getStatusDescription() {
+ return statusDescription;
+ }
+
+ public List getNotices() {
+ return notices;
+ }
+
+ public enum Status {
+ @SerializedName("available")
+ AVAILABLE,
+ @SerializedName("available with notices")
+ AVAILABLE_WITH_NOTICES,
+ @SerializedName("processing")
+ PROCESSING,
+ @SerializedName("failed")
+ FAILED
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DocumentManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DocumentManager.java
new file mode 100644
index 00000000000..2add0739716
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/DocumentManager.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+
+/**
+ * Interface defining the constants and methods associated with Environments.
+ *
+ * @see Document
+ */
+public interface DocumentManager {
+ //Document
+ String ID = "document_id";
+ String CONFIGURATION_ID = "configuration_id";
+ String CREATED = "created";
+ String UPDATED = "updated";
+ String STATUS = "status";
+ String STATUS_DESCRIPTION = "status_description";
+ String FILE = "file";
+
+ /**
+ * Gets a {@link Document}.
+ *
+ * @param getRequest options for getting a {@link Document}
+ * @return a {@link GetDocumentResponse} containing the details of {@link GetDocumentRequest}
+ */
+ ServiceCall getDocument(GetDocumentRequest getRequest);
+
+ /**
+ * Starts ingesting a document with optional metadata and optional configuration overrides.
+ *
+ * Returns immediately after the system has accepted the document for processing.
+ * The user must provide document content, metadata, or both.
+ * If the request is missing both document content and metadata, then it will be rejected.
+ * User can set the Content-Type parameter on the file part to indicate the media type of the document.
+ * If the Content-Type parameter is missing or is one of the generic media types (e.g. application/octet-stream),
+ * then the service will attempt to automatically detect the document's media type.
+ *
+ * @param createRequest options for creating a {@link Document}
+ * @return a {@link CreateDocumentResponse} containing the details of {@link CreateDocumentRequest}
+ */
+ ServiceCall createDocument(CreateDocumentRequest createRequest);
+
+ /**
+ * Deletes a {@link Document}.
+ *
+ * @param deleteRequest options for deleting a {@link Document}
+ * @return a {@link DeleteDocumentResponse} containing the details of {@link DeleteDocumentRequest}
+ */
+ ServiceCall deleteDocument(DeleteDocumentRequest deleteRequest);
+
+ /**
+ * Starts ingesting a source document to create or replace an existing document.
+ *
+ * This is a POST operation instead of a PUT operation because an existing document may be partially updated,
+ * depending on whether or not the new, replacement document is successfully ingested (see the next bullet for
+ * details).
+ * - If a document already exists with the provided Document ID, then the fate of the original document
+ * depends on whether or not the new document is successfully ingested
+ * - If the new document fails, then the original document is left intact in the collection's index.
+ * However, any previous notices (warnings or errors) that were stored for the original document are replaced
+ * with the new document's notices.
+ * - If the new document is successfully processed, then the original document is replaced with the new document
+ * in the collection's index, including any notices.
+ * - Only the document_id from the request path is used. If the user provides a document_id in the input document
+ * (assuming JSON is submitted), it will be ignored. Returns immediately after the system has accepted
+ * the document for processing. The user must provide document content, metadata, or both.
+ * If the request is missing both document content and metadata, then it will be rejected.
+ * User can set the Content-Type parameter on the file part to indicate the media type of the document.
+ * If the Content-Type parameter is missing or is one of the generic media types
+ * (e.g. application/octet-stream), then the service will attempt to automatically detect the document's
+ * media type.
+ *
+ * @param updateRequest options for updating a {@link Document}
+ * @return a {@link UpdateDocumentResponse} containing the details of {@link UpdateDocumentRequest}
+ */
+ ServiceCall updateDocument(UpdateDocumentRequest updateRequest);
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentRequest.java
new file mode 100644
index 00000000000..f203eba6711
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentRequest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a {@link Document}.
+ */
+public class GetDocumentRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+
+ private GetDocumentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ this.documentId = builder.documentId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getDocumentId() {
+ return documentId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+
+ public Builder(String environmentId, String collectionId, String documentId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ this.documentId = documentId;
+ }
+
+ public GetDocumentRequest build() {
+ return new GetDocumentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentResponse.java
new file mode 100644
index 00000000000..e1f3bfe4edd
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/GetDocumentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+/**
+ * Response from {@link GetDocumentRequest}.
+ */
+public class GetDocumentResponse extends Document {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentRequest.java
new file mode 100644
index 00000000000..2b6b07a021c
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentRequest.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+import com.google.gson.JsonObject;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+/**
+ * Request to update a {@link Document}.
+ */
+public class UpdateDocumentRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+ private String configurationId;
+ private JsonObject metadata;
+ private InputStream file;
+ private String mediaType;
+ //TODO add configuration
+
+ private UpdateDocumentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ this.documentId = builder.documentId;
+ this.configurationId = builder.configurationId;
+ this.metadata = builder.metadata;
+ this.file = builder.file;
+ this.mediaType = builder.mediaType;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getDocumentId() {
+ return documentId;
+ }
+
+ public String getConfigurationId() {
+ return configurationId;
+ }
+
+ public JsonObject getMetadata() {
+ return metadata;
+ }
+
+ public InputStream getFile() {
+ return file;
+ }
+
+ public String getMediaType() {
+ return mediaType;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+ private String configurationId;
+ private JsonObject metadata;
+ private InputStream file;
+ private String mediaType;
+
+ public Builder(String environmentId, String collectionId, String documentId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ this.documentId = documentId;
+ }
+
+ public Builder configurationId(String configurationId) {
+ this.configurationId = configurationId;
+ return this;
+ }
+
+ public Builder metadata(JsonObject metadata) {
+ this.metadata = metadata;
+ return this;
+ }
+
+ public Builder inputStream(InputStream file, String mediaType) {
+ this.file = file;
+ this.mediaType = mediaType;
+ return this;
+ }
+
+ public Builder file(File inputFile, String mediaType) {
+ InputStream file;
+ try {
+ file = new FileInputStream(inputFile);
+ this.mediaType = mediaType;
+ } catch (FileNotFoundException e) {
+ file = null;
+ }
+ this.file = file;
+ return this;
+ }
+
+ public UpdateDocumentRequest build() {
+ return new UpdateDocumentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentResponse.java
new file mode 100644
index 00000000000..be39f2633fd
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/document/UpdateDocumentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.document;
+
+/**
+ * Response from {@link UpdateDocumentRequest}.
+ */
+public class UpdateDocumentResponse extends Document {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentRequest.java
new file mode 100644
index 00000000000..5863023cd07
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentRequest.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to create an {@link Environment}.
+ *
+ * A JSON object where you define an environment name and an environment description.
+ */
+public class CreateEnvironmentRequest extends GenericModel {
+ private final String name;
+ private final Size size;
+ private final String description;
+
+ private CreateEnvironmentRequest(Builder builder) {
+ this.name = builder.name;
+ this.size = builder.size;
+ this.description = builder.description;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Size getSize() {
+ return size;
+ }
+
+ public static class Builder {
+ private final String name;
+ private final Size size;
+ private String description;
+
+ public Builder(String name, Size size) {
+ this.name = name;
+ this.size = size;
+ }
+
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public CreateEnvironmentRequest build() {
+ return new CreateEnvironmentRequest(this);
+ }
+ }
+
+ public enum Size {
+ FREE(0), //free plan
+ ONE(1), //standard plan
+ TWO(2), //standard plan
+ THREE(3); //standard plan
+
+ private final int size;
+
+ Size(int size) {
+ this.size = size;
+ }
+
+ public int getSize() {
+ return size;
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentResponse.java
new file mode 100644
index 00000000000..ee6810d3afa
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/CreateEnvironmentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+/**
+ * Response from a {@link CreateEnvironmentRequest}.
+ */
+public class CreateEnvironmentResponse extends Environment {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentRequest.java
new file mode 100644
index 00000000000..66796696c03
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentRequest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to delete an {@link Environment}.
+ */
+public class DeleteEnvironmentRequest extends GenericModel {
+ private final String environmentId;
+
+ private DeleteEnvironmentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+
+ public Builder(String environmentId) {
+ this.environmentId = environmentId;
+ }
+
+ public DeleteEnvironmentRequest build() {
+ return new DeleteEnvironmentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentResponse.java
new file mode 100644
index 00000000000..c93a3593696
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DeleteEnvironmentResponse.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Response from a {@link DeleteEnvironmentRequest}.
+ */
+public class DeleteEnvironmentResponse extends GenericModel {
+ @SerializedName(EnvironmentManager.ID)
+ private String environmentId;
+ @SerializedName(EnvironmentManager.STATUS)
+ private Status status;
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DiskUsage.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DiskUsage.java
new file mode 100644
index 00000000000..6f9d72bc36a
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/DiskUsage.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * DiskUsage contains storage information for the Environment.
+ */
+public class DiskUsage extends GenericModel {
+ @SerializedName(EnvironmentManager.USED_BYTES)
+ private Long usedBytes;
+ @SerializedName(EnvironmentManager.TOTAL_BYTES)
+ private Long totalBytes;
+ @SerializedName(EnvironmentManager.USED)
+ private String used;
+ @SerializedName(EnvironmentManager.TOTAL)
+ private String total;
+ @SerializedName(EnvironmentManager.PERCENT_USED)
+ private Double percentUsed;
+
+ public Double getPercentUsed() {
+ return percentUsed;
+ }
+
+ public Long getUsedBytes() {
+ return usedBytes;
+ }
+
+ public Long getTotalBytes() {
+ return totalBytes;
+ }
+
+ public String getUsed() {
+ return used;
+ }
+
+ public String getTotal() {
+ return total;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/Environment.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/Environment.java
new file mode 100644
index 00000000000..eaa49ad0995
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/Environment.java
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.Date;
+
+/**
+ * Container where Collections and Configurations are stored.
+ * An Environment gives information about the memory and storage space allocated
+ */
+public class Environment extends GenericModel {
+ @SerializedName(EnvironmentManager.ID)
+ private String environmentId;
+ @SerializedName(EnvironmentManager.NAME)
+ private String name;
+ @SerializedName(EnvironmentManager.DESCRIPTION)
+ private String description;
+ @SerializedName(EnvironmentManager.CREATED)
+ private Date created;
+ @SerializedName(EnvironmentManager.UPDATED)
+ private Date updated;
+ @SerializedName(EnvironmentManager.STATUS)
+ private Status status;
+ @SerializedName(EnvironmentManager.READ_ONLY)
+ private Boolean readOnly;
+ @SerializedName(EnvironmentManager.INDEX_CAPACITY)
+ private IndexCapacity indexCapacity;
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Date getUpdated() {
+ return updated;
+ }
+
+ public Status getStatus() {
+ return status;
+ }
+
+ public Boolean isReadOnly() {
+ return readOnly;
+ }
+
+ public IndexCapacity getIndexCapacity() {
+ return indexCapacity;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/EnvironmentManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/EnvironmentManager.java
new file mode 100644
index 00000000000..836a7012b2f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/EnvironmentManager.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+
+/**
+ * Interface defining the constants and methods associated with Environments.
+ *
+ * @see Environment
+ */
+public interface EnvironmentManager {
+ String ENVIRONMENTS = "environments";
+
+ //Environment
+ String ID = "environment_id";
+ String NAME = "name";
+ String DESCRIPTION = "description";
+ String CREATED = "created";
+ String UPDATED = "updated";
+ String STATUS = "status";
+ String READ_ONLY = "read_only";
+ String INDEX_CAPACITY = "index_capacity";
+
+ //Disk & Memory Usage
+ String DISK_USAGE = "disk_usage";
+ String MEMORY_USAGE = "memory_usage";
+ String USED_BYTES = "used_bytes";
+ String TOTAL_BYTES = "total_bytes";
+ String USED = "used";
+ String TOTAL = "total";
+ String PERCENT_USED = "percent_used";
+
+ //only on creation request
+ String SIZE = "size";
+
+ /**
+ * Lists existing environments. Optional query param of name can be used to search for environments by name.
+ *
+ * @param getRequest options for getting the environments
+ * @return a {@link GetEnvironmentsResponse} containing result of the {@link GetEnvironmentsRequest}
+ */
+ ServiceCall getEnvironments(GetEnvironmentsRequest getRequest);
+
+ /**
+ * Gets details about an existing environment.
+ *
+ * @param getRequest options for getting the environment
+ * @return a {@link GetEnvironmentResponse} containing the result of the {@link GetEnvironmentRequest}
+ */
+ ServiceCall getEnvironment(GetEnvironmentRequest getRequest);
+
+ /**
+ * Creates a new environment.
+ *
+ * @param createRequest options for creating the environment
+ * @return a {@link CreateEnvironmentResponse} containing the result of the {@link CreateEnvironmentRequest}
+ */
+ ServiceCall createEnvironment(CreateEnvironmentRequest createRequest);
+
+ /**
+ * Deletes an existing environment.
+ *
+ * @param deleteRequest options for deleting the environment
+ * @return a {@link DeleteEnvironmentResponse} containing the result of the {@link DeleteEnvironmentRequest}
+ */
+ ServiceCall deleteEnvironment(DeleteEnvironmentRequest deleteRequest);
+
+ /**
+ * Updates an environment.
+ *
+ * @param updateRequest options for deleting the environment
+ * @return a {@link UpdateEnvironmentResponse} containing the result of the {@link UpdateEnvironmentRequest}
+ */
+ ServiceCall updateEnvironment(UpdateEnvironmentRequest updateRequest);
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentRequest.java
new file mode 100644
index 00000000000..7febb263e41
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentRequest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get an {@link Environment}.
+ */
+public class GetEnvironmentRequest extends GenericModel {
+ private final String environmentId;
+
+ private GetEnvironmentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+
+ public Builder(String environmentId) {
+ this.environmentId = environmentId;
+ }
+
+ public GetEnvironmentRequest build() {
+ return new GetEnvironmentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentResponse.java
new file mode 100644
index 00000000000..dfe1907e242
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+/**
+ * Response from a {@link GetEnvironmentRequest}.
+ */
+public class GetEnvironmentResponse extends Environment {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsRequest.java
new file mode 100644
index 00000000000..d12580d0dd1
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to get a list of {@link Environment}s.
+ */
+public class GetEnvironmentsRequest extends GenericModel {
+ private final String name;
+
+ private GetEnvironmentsRequest(Builder builder) {
+ this.name = builder.name;
+ }
+
+ public boolean hasName() {
+ return name != null;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static class Builder {
+ private String name;
+
+ public Builder() {
+ }
+
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public GetEnvironmentsRequest build() {
+ return new GetEnvironmentsRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsResponse.java
new file mode 100644
index 00000000000..6f040a61646
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/GetEnvironmentsResponse.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Response from a {@link GetEnvironmentsRequest}.
+ */
+public class GetEnvironmentsResponse extends GenericModel {
+ @SerializedName(EnvironmentManager.ENVIRONMENTS)
+ private List environments;
+
+ public List getEnvironments() {
+ return environments;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/IndexCapacity.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/IndexCapacity.java
new file mode 100644
index 00000000000..f0453bb2ee6
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/IndexCapacity.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Index capacity lists out disk and memory usage of the Environment.
+ *
+ * @see Environment
+ */
+public class IndexCapacity extends GenericModel {
+ @SerializedName(EnvironmentManager.DISK_USAGE)
+ private DiskUsage diskUsage;
+ @SerializedName(EnvironmentManager.MEMORY_USAGE)
+ private MemoryUsage memoryUsage;
+
+ public DiskUsage getDiskUsage() {
+ return diskUsage;
+ }
+
+ public MemoryUsage getMemoryUsage() {
+ return memoryUsage;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/MemoryUsage.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/MemoryUsage.java
new file mode 100644
index 00000000000..810c123fb18
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/MemoryUsage.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * MemoryUsage contains information about the RAM used.
+ */
+public class MemoryUsage extends GenericModel {
+ @SerializedName(EnvironmentManager.USED_BYTES)
+ private Long usedBytes;
+ @SerializedName(EnvironmentManager.TOTAL_BYTES)
+ private Long totalBytes;
+ @SerializedName(EnvironmentManager.USED)
+ private String used;
+ @SerializedName(EnvironmentManager.TOTAL)
+ private String total;
+ @SerializedName(EnvironmentManager.PERCENT_USED)
+ private Double percentUsed;
+
+ public Long getUsedBytes() {
+ return usedBytes;
+ }
+
+ public Long getTotalBytes() {
+ return totalBytes;
+ }
+
+ public String getUsed() {
+ return used;
+ }
+
+ public String getTotal() {
+ return total;
+ }
+
+ public Double getPercentUsed() {
+ return percentUsed;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentRequest.java
new file mode 100644
index 00000000000..c9a426de131
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentRequest.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Request to update an {@link Environment}.
+ */
+public class UpdateEnvironmentRequest extends GenericModel {
+ private final String environmentId;
+ private final String name;
+ private final String description;
+
+ private UpdateEnvironmentRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.name = builder.name;
+ this.description = builder.description;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String name;
+ private String description;
+
+ public Builder(String environmentId, String name) {
+ this.environmentId = environmentId;
+ this.name = name;
+ }
+
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ public UpdateEnvironmentRequest build() {
+ return new UpdateEnvironmentRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentResponse.java
new file mode 100644
index 00000000000..a619effb307
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/environment/UpdateEnvironmentResponse.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.environment;
+
+/**
+ * Response from a {@link UpdateEnvironmentRequest}.
+ */
+public class UpdateEnvironmentResponse extends Environment {
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Aggregation.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Aggregation.java
new file mode 100644
index 00000000000..980b97a43a4
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Aggregation.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.JsonAdapter;
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * Base class for all {@link AggregationType}s.
+ */
+@JsonAdapter(AggregationAdapterFactory.class)
+public abstract class Aggregation extends GenericModel {
+ @SerializedName(QueryManager.AGGREGATION_ID)
+ private String id;
+ @SerializedName(QueryManager.TYPE)
+ private String type;
+ @SerializedName(QueryManager.FIELD)
+ private String field;
+ @SerializedName(QueryManager.LOGIC)
+ private Logic logic;
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getField() {
+ return field;
+ }
+
+ public Logic getLogic() {
+ return logic;
+ }
+
+ public void setLogic(Logic logic) {
+ this.logic = logic;
+ }
+
+ public enum Logic {
+ AND,
+ OR
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationAdapterFactory.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationAdapterFactory.java
new file mode 100644
index 00000000000..ba5228ff60c
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationAdapterFactory.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
+
+import java.io.IOException;
+
+/**
+ * Adapts the abstract {@link Aggregation} to its concrete implementations.
+ */
+public class AggregationAdapterFactory implements TypeAdapterFactory {
+ @Override
+ public TypeAdapter create(Gson gson, TypeToken typeToken) {
+ if (typeToken.getRawType() != Aggregation.class) {
+ return null;
+ }
+ return (TypeAdapter) new QueryAggregationTypeAdapter(gson);
+ }
+
+ private class QueryAggregationTypeAdapter extends TypeAdapter {
+ private final Gson gson;
+ private final TypeAdapter jsonElementTypeAdapter;
+
+ QueryAggregationTypeAdapter(Gson gson) {
+ this.gson = gson;
+ this.jsonElementTypeAdapter = gson.getAdapter(JsonElement.class);
+ }
+
+ @Override
+ public void write(JsonWriter out, Aggregation value) throws IOException {
+ JsonElement tree = null;
+ if (value instanceof Term) {
+ //order of keys not guaranteed
+ tree = gson.toJsonTree(value, Term.class);
+ } else if (value instanceof Histogram) {
+ tree = gson.toJsonTree(value, Histogram.class);
+ } else if (value instanceof Calculation) {
+ tree = gson.toJsonTree(value, Calculation.class);
+ }
+
+ if (tree == null) {
+ out.nullValue();
+ } else {
+ jsonElementTypeAdapter.write(out, tree);
+ }
+ }
+
+ @Override
+ public Aggregation read(JsonReader in) throws IOException {
+ JsonElement tree = jsonElementTypeAdapter.read(in);
+
+ if (tree.isJsonObject()) {
+ JsonObject object = tree.getAsJsonObject();
+ JsonElement typeElement = object.get(QueryManager.TYPE);
+ if (typeElement.isJsonPrimitive()) {
+ try {
+ AggregationType type = AggregationType.valueOfIgnoreCase(typeElement.getAsString());
+ switch (type) {
+ case TERM:
+ return gson.fromJson(tree, Term.class);
+ case HISTOGRAM:
+ return gson.fromJson(tree, Histogram.class);
+ case MAX:
+ case MIN:
+ case SUM:
+ case AVERAGE:
+ return gson.fromJson(tree, Calculation.class);
+ }
+ } catch (IllegalArgumentException e) {
+
+ }
+ }
+ }
+ return null;
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationType.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationType.java
new file mode 100644
index 00000000000..ceb747a4d86
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/AggregationType.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+/**
+ * Aggregation types.
+ */
+public enum AggregationType {
+ TERM("term"),
+ HISTOGRAM("histogram"),
+ MAX("max"),
+ MIN("min"),
+ AVERAGE("average"),
+ SUM("sum");
+
+ private final String name;
+
+ AggregationType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static AggregationType valueOfIgnoreCase(String value) throws IllegalArgumentException {
+ for (AggregationType aggregationType : values()) {
+ if (aggregationType.getName().equalsIgnoreCase(value)) {
+ return aggregationType;
+ }
+ }
+ throw new IllegalArgumentException(value + " is not a valid Aggregation");
+ }
+
+ @Override
+ public String toString() {
+ return name;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Calculation.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Calculation.java
new file mode 100644
index 00000000000..8ecb60e39e4
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Calculation.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.SerializedName;
+
+/**
+ * Aggregation that performs a calculation.
+ */
+public class Calculation extends Aggregation {
+ @SerializedName(QueryManager.VALUE)
+ private Double value;
+
+ public Double getValue() {
+ return value;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Histogram.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Histogram.java
new file mode 100644
index 00000000000..dacd819a4fa
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Histogram.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.JsonAdapter;
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.EagerNumberAdapterFactory;
+
+/**
+ * Aggregation that makes a histogram.
+ */
+public class Histogram extends NestableAggregation {
+ @SerializedName(QueryManager.INTERVAL)
+ @JsonAdapter(EagerNumberAdapterFactory.class)
+ private Number interval;
+
+ public Number getInterval() {
+ return interval;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregation.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregation.java
new file mode 100644
index 00000000000..b78688c485f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregation.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.List;
+
+/**
+ * Handles aggregations that can use the {@link Operator#NEST_AGGREGATION}.
+ */
+public abstract class NestableAggregation extends Aggregation {
+ @SerializedName(QueryManager.RESULTS)
+ private List results;
+
+ public List getResults() {
+ return results;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregationResult.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregationResult.java
new file mode 100644
index 00000000000..9d0fb0f8c65
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/NestableAggregationResult.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.List;
+
+/**
+ * Results contained within a Nestable Aggregation.
+ *
+ * @see NestableAggregation
+ */
+public class NestableAggregationResult extends GenericModel {
+ @SerializedName(QueryManager.KEY)
+ private String key;
+ @SerializedName(QueryManager.MATCHING_RESULTS)
+ private Long matchingResults;
+ @SerializedName(QueryManager.AGGREGATIONS)
+ private List aggregations;
+
+ public String getKey() {
+ return key;
+ }
+
+ public Long getMatchingResults() {
+ return matchingResults;
+ }
+
+ public List getAggregations() {
+ return aggregations;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Operator.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Operator.java
new file mode 100644
index 00000000000..885dfd0f7e0
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/Operator.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+/**
+ * Query Language Operator Syntax.
+ */
+public enum Operator {
+ FIELD_SEPARATOR("."),
+ EQUALS("::"),
+ CONTAINS(":"),
+ ESCAPE("\\"),
+ FUZZY("~"),
+ OR("|"),
+ AND(","),
+ NOT("!"),
+ NEST_AGGREGATION("."),
+ LESS_THAN("<"),
+ LESS_THAN_OR_EQUAL_TO("<="),
+ GREATER_THAN(">"),
+ GREATER_THAN_OR_EQUAL_TO(">="),
+ BOOST("^"),
+ WILDCARD("*", false),
+ OPENING_GROUPING("("),
+ CLOSING_GROUPING(")"),
+ OPENING_ARRAY("["),
+ CLOSING_ARRAY("]"),
+ DOUBLE_QUOTE("\"");
+
+ private final String symbol;
+ private final boolean escape;
+
+ Operator(String symbol) {
+ this(symbol, true);
+ }
+
+ Operator(String symbol, boolean escape) {
+ this.symbol = symbol;
+ this.escape = escape;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public boolean shouldEscape() {
+ return escape;
+ }
+
+ @Override
+ public String toString() {
+ return symbol;
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryManager.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryManager.java
new file mode 100644
index 00000000000..a848768c77b
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryManager.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.ibm.watson.developer_cloud.http.ServiceCall;
+
+/**
+ * Interface defining the constants and methods associated with Queries.
+ *
+ * @see QueryRequest
+ */
+public interface QueryManager {
+ // QueryRequest
+ String FILTER = "filter";
+ String QUERY = "query";
+ String AGGREGATION = "aggregation";
+ String COUNT = "count";
+ String OFFSET = "offset";
+ String RETURN = "return";
+
+ // QueryResponse
+ String MATCHING_RESULTS = "matching_results";
+ String RESULTS = "results";
+ String AGGREGATIONS = "aggregations";
+
+ // Result
+ String INTERNAL_ID = "_id";
+ String ID = "id";
+ String SCORE = "score";
+
+ // QueryAggregation
+ String AGGREGATION_ID = "id";
+ String TYPE = "type";
+ String FIELD = "field";
+ String LOGIC = "logic";
+ String COUNT_PARAM = "count";
+
+ // NestableAggregationResult
+ // includes RESULTS, MATCHING_RESULTS, AGGREGATIONS
+ String KEY = "key";
+
+ // Aggregations -> Histogram
+ String INTERVAL = "interval";
+
+ // Aggregations -> Calculation
+ String VALUE = "value";
+
+ /**
+ * Executes a query.
+ *
+ * @param queryRequest options for the query
+ * @return a {@link QueryResponse} containing the details from the {@link QueryRequest}
+ */
+ ServiceCall query(QueryRequest queryRequest);
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryRequest.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryRequest.java
new file mode 100644
index 00000000000..37823ffb5c7
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryRequest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+/**
+ * A query that will retrieve back documents from the Discovery service.
+ */
+public class QueryRequest extends GenericModel {
+ private final String environmentId;
+ private final String collectionId;
+ private final String filter;
+ private final String query;
+ private final String aggregation;
+ private final Integer count;
+ private final Integer offset;
+ private final Iterable returnFields;
+
+ private QueryRequest(Builder builder) {
+ this.environmentId = builder.environmentId;
+ this.collectionId = builder.collectionId;
+ this.filter = builder.filter;
+ this.query = builder.query;
+ this.aggregation = builder.aggregation;
+ this.count = builder.count;
+ this.offset = builder.offset;
+ this.returnFields = builder.returnFields;
+ }
+
+ public String getEnvironmentId() {
+ return environmentId;
+ }
+
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ public String getFilter() {
+ return filter;
+ }
+
+ public String getQuery() {
+ return query;
+ }
+
+ public String getAggregation() {
+ return aggregation;
+ }
+
+ public Integer getCount() {
+ return count;
+ }
+
+ public Integer getOffset() {
+ return offset;
+ }
+
+ public Iterable getReturnFields() {
+ return returnFields;
+ }
+
+ public static class Builder {
+ private final String environmentId;
+ private final String collectionId;
+ private String filter;
+ private String query;
+ private String aggregation;
+ private Integer count = 10;
+ private Integer offset = 0;
+ private Iterable returnFields;
+
+ public Builder(String environmentId, String collectionId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ }
+
+ public Builder filter(String filter) {
+ this.filter = filter;
+ return this;
+ }
+
+ public Builder query(String query) {
+ this.query = query;
+ return this;
+ }
+
+ public Builder aggregation(String aggregation) {
+ this.aggregation = aggregation;
+ return this;
+ }
+
+ public Builder count(Integer count) {
+ this.count = count;
+ return this;
+ }
+
+ public Builder offset(Integer offset) {
+ this.offset = offset;
+ return this;
+ }
+
+ public Builder returnFields(Iterable returnFields) {
+ this.returnFields = returnFields;
+ return this;
+ }
+
+ public QueryRequest build() {
+ return new QueryRequest(this);
+ }
+ }
+}
diff --git a/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryResponse.java b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryResponse.java
new file mode 100644
index 00000000000..223b6f2431f
--- /dev/null
+++ b/discovery/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/model/query/QueryResponse.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1.model.query;
+
+import com.google.gson.annotations.SerializedName;
+import com.ibm.watson.developer_cloud.service.model.GenericModel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * A response containing the documents and aggregations from the QueryRequest.
+ *
+ * @see QueryRequest
+ */
+public class QueryResponse extends GenericModel {
+ @SerializedName(QueryManager.MATCHING_RESULTS)
+ private Long matchingResults;
+ @SerializedName(QueryManager.RESULTS)
+ private List
+
+ ${project.groupId}
+ discovery
+ ${project.version}
+
${project.groupId}
document-conversion
diff --git a/tests/src/test/java/com/ibm/watson/developer_cloud/discovery/v1/DiscoveryServiceIT.java b/tests/src/test/java/com/ibm/watson/developer_cloud/discovery/v1/DiscoveryServiceIT.java
new file mode 100644
index 00000000000..0cd80f132b7
--- /dev/null
+++ b/tests/src/test/java/com/ibm/watson/developer_cloud/discovery/v1/DiscoveryServiceIT.java
@@ -0,0 +1,789 @@
+/**
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.discovery.v1;
+
+import static org.junit.Assert.*;
+
+import com.ibm.watson.developer_cloud.WatsonServiceTest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CreateCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.CreateCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.DeleteCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.DeleteCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.GetCollectionsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.collection.field.GetCollectionFieldsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.common.Status;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.Configuration;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.CreateConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.CreateConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.DeleteConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.DeleteConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.GetConfigurationsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.UpdateConfigurationRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.configuration.UpdateConfigurationResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.CreateDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.CreateDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.DeleteDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.DeleteDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.Document;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.GetDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.GetDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.UpdateDocumentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.document.UpdateDocumentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.CreateEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.CreateEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.DeleteEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.DeleteEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.Environment;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentsRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.GetEnvironmentsResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.UpdateEnvironmentRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.environment.UpdateEnvironmentResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.AggregationType;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.Calculation;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.Histogram;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.Operator;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryRequest;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.QueryResponse;
+import com.ibm.watson.developer_cloud.discovery.v1.model.query.Term;
+import com.ibm.watson.developer_cloud.http.HttpMediaType;
+import com.ibm.watson.developer_cloud.service.exception.ForbiddenException;
+import com.ibm.watson.developer_cloud.service.exception.UnauthorizedException;
+import com.ibm.watson.developer_cloud.util.GsonSingleton;
+import com.ibm.watson.developer_cloud.util.WaitFor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Integration tests for {@link Discovery}
+ *
+ * @author apturgeo
+ */
+public class DiscoveryServiceIT extends WatsonServiceTest {
+ private static final String DISCOVERY_TEST_CONFIG_FILE = "src/test/resources/discovery/test-config.json";
+ private static String environmentId;
+ private Discovery discovery;
+ private String uniqueName;
+
+ private Set configurationIds = new HashSet();
+ private Set collectionIds = new HashSet();
+
+ @BeforeClass
+ public static void setupClass() {
+ //get the properties
+ DiscoveryServiceIT dummyTest = new DiscoveryServiceIT();
+ String username = dummyTest.getProperty("discovery.username");
+ String password = dummyTest.getProperty("discovery.password");
+ String url = dummyTest.getProperty("discovery.url");
+ Discovery discovery = new Discovery("2016-12-16");
+ discovery.setEndPoint(url);
+ discovery.setUsernameAndPassword(username, password);
+
+ GetEnvironmentsRequest getRequest = new GetEnvironmentsRequest.Builder().build();
+ GetEnvironmentsResponse getResponse = discovery.getEnvironments(getRequest).execute();
+ for (Environment environment : getResponse.getEnvironments()) {
+ //look for an existing environment that isn't read only
+ if (!environment.isReadOnly()) {
+ environmentId = environment.getEnvironmentId();
+ break;
+ }
+ }
+
+ if (environmentId == null) {
+ //no environment found, create a new one (assuming we are a FREE plan)
+ String environmentName = "watson_developer_cloud_test_environment";
+ CreateEnvironmentRequest.Size size = CreateEnvironmentRequest.Size.FREE;
+ CreateEnvironmentRequest createRequest = new CreateEnvironmentRequest.Builder(environmentName, size)
+ .build();
+ CreateEnvironmentResponse createResponse = discovery.createEnvironment(createRequest).execute();
+ environmentId = createResponse.getEnvironmentId();
+ }
+ }
+
+ @Before
+ public void setup() throws Exception {
+ super.setUp();
+ String username = getProperty("discovery.username");
+ String password = getProperty("discovery.password");
+ String url = getProperty("discovery.url");
+ discovery = new Discovery("2016-12-16");
+ discovery.setEndPoint(url);
+ discovery.setUsernameAndPassword(username, password);
+
+ uniqueName = UUID.randomUUID().toString();
+ }
+
+ @After
+ public void cleanup() {
+ for (String collectionId : collectionIds) {
+ DeleteCollectionRequest deleteRequest = new DeleteCollectionRequest.Builder(environmentId, collectionId)
+ .build();
+ discovery.deleteCollection(deleteRequest).execute();
+ }
+
+ for (String configurationId : configurationIds) {
+ DeleteConfigurationRequest deleteRequest = new DeleteConfigurationRequest.Builder(environmentId,
+ configurationId).build();
+ discovery.deleteConfiguration(deleteRequest).execute();
+ }
+ }
+
+ @Test
+ public void ping_is_successful() {
+ assertTrue(discovery.ping());
+ }
+
+ @Test(expected = UnauthorizedException.class)
+ public void ping_bad_credentials_throws_exception() {
+ discovery.setUsernameAndPassword("foo", "bar");
+ discovery.ping();
+ }
+
+ @Test(expected = ForbiddenException.class)
+ public void ping_bad_url_throws_exception() {
+ discovery.setEndPoint("https://gateway.watsonplatform.net/discovery-foo/api");
+ discovery.ping();
+ }
+
+ @Test
+ public void get_environment_is_successful() {
+ GetEnvironmentRequest getRequest = new GetEnvironmentRequest.Builder(environmentId).build();
+ GetEnvironmentResponse getResponse = discovery.getEnvironment(getRequest).execute();
+
+ assertEquals(environmentId, getResponse.getEnvironmentId());
+ }
+
+ @Test
+ public void get_environments_is_successful() {
+ GetEnvironmentsRequest getRequest = new GetEnvironmentsRequest.Builder().build();
+ GetEnvironmentsResponse getResponse = discovery.getEnvironments(getRequest).execute();
+
+ assertFalse(getResponse.getEnvironments().isEmpty());
+ }
+
+ @Test
+ public void get_environments_has_news_environment() {
+ GetEnvironmentsRequest getRequest = new GetEnvironmentsRequest.Builder().build();
+ GetEnvironmentsResponse getResponse = discovery.getEnvironments(getRequest).execute();
+
+ boolean foundNews = false;
+ for (Environment environment : getResponse.getEnvironments()) {
+ if (environment.isReadOnly()) {
+ foundNews = true;
+ break;
+ }
+ }
+ assertTrue(foundNews);
+ }
+
+ @Test
+ public void get_environments_by_name_is_successful() {
+ GetEnvironmentRequest getRequest = new GetEnvironmentRequest.Builder(environmentId).build();
+ GetEnvironmentResponse getResponse = discovery.getEnvironment(getRequest).execute();
+
+ GetEnvironmentsRequest.Builder getBuilder = new GetEnvironmentsRequest.Builder();
+ getBuilder.name(getResponse.getName());
+ GetEnvironmentsResponse getsResponse = discovery.getEnvironments(getBuilder.build()).execute();
+
+ assertEquals(1, getsResponse.getEnvironments().size());
+ }
+
+ @Test
+ @Ignore("Environment creation/deletion is expensive")
+ public void create_environment_is_successful() {
+ String environmentName = uniqueName + "-environment";
+ CreateEnvironmentRequest createRequest = new CreateEnvironmentRequest.Builder(environmentName,
+ CreateEnvironmentRequest.Size.FREE).build();
+ CreateEnvironmentResponse createResponse = createEnvironment(createRequest);
+
+ assertEquals(environmentName, createResponse.getName());
+ }
+
+ @Test
+ @Ignore("Environment creation/deletion is expensive")
+ public void delete_environment_is_successful() {
+ String environmentName = uniqueName + "-environment";
+ CreateEnvironmentRequest createRequest = new CreateEnvironmentRequest.Builder(environmentName,
+ CreateEnvironmentRequest.Size.FREE).build();
+ CreateEnvironmentResponse createResponse = createEnvironment(createRequest);
+
+ DeleteEnvironmentRequest deleteRequest = new DeleteEnvironmentRequest.Builder(createResponse.getEnvironmentId())
+ .build();
+ DeleteEnvironmentResponse deleteRepsonse = deleteEnvironment(deleteRequest);
+
+ assertEquals(createResponse.getEnvironmentId(), deleteRepsonse.getEnvironmentId());
+ }
+
+ @Test
+ @Ignore("Environment creation/deletion is expensive")
+ public void update_environment_is_successful() {
+ String environmentName = uniqueName + "-environment";
+ CreateEnvironmentRequest createRequest = new CreateEnvironmentRequest.Builder(environmentName,
+ CreateEnvironmentRequest.Size.FREE).build();
+ CreateEnvironmentResponse createResponse = createEnvironment(createRequest);
+
+ String randomDescription = UUID.randomUUID().toString() + " appbuilder tests";
+ UpdateEnvironmentRequest.Builder updateBuilder = new UpdateEnvironmentRequest.Builder(
+ createResponse.getEnvironmentId(), environmentName);
+ updateBuilder.description(randomDescription);
+ UpdateEnvironmentResponse updateResponse = discovery.updateEnvironment(updateBuilder.build()).execute();
+
+ assertEquals(randomDescription, updateResponse.getDescription());
+ }
+
+ @Test
+ public void get_configurations_is_successful() {
+ GetConfigurationsRequest getRequest = new GetConfigurationsRequest.Builder(environmentId).build();
+ GetConfigurationsResponse getResponse = discovery.getConfigurations(getRequest).execute();
+
+ assertFalse(getResponse.getConfigurations().isEmpty());
+ }
+
+ @Test
+ public void create_configuration_is_successful() {
+ String uniqueConfigName = uniqueName + "-config";
+ CreateConfigurationRequest.Builder createBuilder = new CreateConfigurationRequest.Builder(environmentId);
+ Configuration configuration = getTestConfiguration();
+ configuration.setName(uniqueConfigName);
+ createBuilder.configuration(configuration);
+ CreateConfigurationResponse createResponse = createConfiguration(createBuilder.build());
+
+ assertEquals(uniqueConfigName, createResponse.getName());
+ }
+
+ @Test
+ public void delete_configuration_is_successful() {
+ CreateConfigurationResponse createResponse = createTestConfig();
+
+ DeleteConfigurationRequest deleteRequest = new DeleteConfigurationRequest.Builder(environmentId,
+ createResponse.getConfigurationId()).build();
+ DeleteConfigurationResponse deleteResponse = deleteConfiguration(deleteRequest);
+
+ assertEquals(createResponse.getConfigurationId(), deleteResponse.getConfigurationId());
+ }
+
+ @Test
+ public void get_configuration_is_successful() {
+ CreateConfigurationResponse createResponse = createTestConfig();
+
+ GetConfigurationRequest getRequest = new GetConfigurationRequest.Builder(environmentId,
+ createResponse.getConfigurationId()).build();
+ GetConfigurationResponse getResponse = discovery.getConfiguration(getRequest).execute();
+
+ assertEquals(createResponse.getName(), getResponse.getName());
+ }
+
+ @Test
+ public void get_configurations_by_name_is_successful() {
+ CreateConfigurationResponse createResponse = createTestConfig();
+
+ GetConfigurationsRequest.Builder getBuilder = new GetConfigurationsRequest.Builder(environmentId);
+ getBuilder.name(createResponse.getName());
+ GetConfigurationsResponse getResponse = discovery.getConfigurations(getBuilder.build()).execute();
+
+ assertEquals(1, getResponse.getConfigurations().size());
+ assertEquals(createResponse.getName(), getResponse.getConfigurations().get(0).getName());
+ }
+
+ @Test
+ public void update_configuration_is_successful() {
+ CreateConfigurationResponse createResponse = createTestConfig();
+
+ String newUniqueName = createResponse.getName() + UUID.randomUUID().toString();
+ UpdateConfigurationRequest.Builder updateBuilder = new UpdateConfigurationRequest.Builder(environmentId,
+ createResponse.getConfigurationId());
+ createResponse.setName(newUniqueName);
+ updateBuilder.configuration(createResponse);
+ UpdateConfigurationResponse updateResponse = discovery.updateConfiguration(updateBuilder.build()).execute();
+
+ assertEquals(newUniqueName, updateResponse.getName());
+ }
+
+ @Test
+ public void get_collections_is_successful() {
+ createTestCollection();
+ GetCollectionsRequest getRequest = new GetCollectionsRequest.Builder(environmentId).build();
+ GetCollectionsResponse getResponse = discovery.getCollections(getRequest).execute();
+
+ assertFalse(getResponse.getCollections().isEmpty());
+ }
+
+ @Test
+ public void create_collection_is_successful() {
+ CreateConfigurationResponse createConfigResponse = createTestConfig();
+
+ String uniqueCollectionName = uniqueName + "-collection";
+ CreateCollectionRequest.Builder createCollectionBuilder = new CreateCollectionRequest.Builder(environmentId,
+ createConfigResponse.getConfigurationId(), uniqueCollectionName);
+ CreateCollectionResponse createResponse = createCollection(createCollectionBuilder.build());
+
+ assertEquals(uniqueCollectionName, createResponse.getName());
+ }
+
+ @Test
+ public void delete_collection_is_successful() {
+ CreateConfigurationResponse createConfigResponse = createTestConfig();
+
+ String uniqueCollectionName = uniqueName + "-collection";
+ CreateCollectionRequest.Builder createCollectionBuilder = new CreateCollectionRequest.Builder(environmentId,
+ createConfigResponse.getConfigurationId(), uniqueCollectionName);
+ CreateCollectionResponse createResponse = createCollection(createCollectionBuilder.build());
+
+ //need to wait for collection to be ready
+
+ DeleteCollectionRequest deleteRequest = new DeleteCollectionRequest.Builder(environmentId,
+ createResponse.getCollectionId()).build();
+ DeleteCollectionResponse deleteResponse = deleteCollection(deleteRequest);
+
+ assertEquals(Status.DELETED, deleteResponse.getStatus());
+ }
+
+ @Test
+ public void get_collection_is_successful() {
+ CreateConfigurationResponse createConfigResponse = createTestConfig();
+
+ String uniqueCollectionName = uniqueName + "-collection";
+ CreateCollectionRequest.Builder createCollectionBuilder = new CreateCollectionRequest.Builder(environmentId,
+ createConfigResponse.getConfigurationId(), uniqueCollectionName);
+ CreateCollectionResponse createResponse = createCollection(createCollectionBuilder.build());
+
+ GetCollectionRequest getRequest = new GetCollectionRequest.Builder(environmentId,
+ createResponse.getCollectionId()).build();
+
+ //need to wait for collection to be ready
+
+ GetCollectionResponse getResponse = discovery.getCollection(getRequest).execute();
+
+ assertEquals(createResponse.getName(), getResponse.getName());
+ }
+
+ @Test
+ public void get_collections_by_name_is_successful() {
+ CreateConfigurationResponse createConfigResponse = createTestConfig();
+
+ String uniqueCollectionName = uniqueName + "-collection";
+ CreateCollectionRequest.Builder createCollectionBuilder = new CreateCollectionRequest.Builder(environmentId,
+ createConfigResponse.getConfigurationId(), uniqueCollectionName);
+ createCollection(createCollectionBuilder.build());
+
+ GetCollectionsRequest.Builder getBuilder = new GetCollectionsRequest.Builder(environmentId);
+ getBuilder.name(uniqueCollectionName);
+ GetCollectionsResponse getResponse = discovery.getCollections(getBuilder.build()).execute();
+
+ assertEquals(1, getResponse.getCollections().size());
+ assertEquals(uniqueCollectionName, getResponse.getCollections().get(0).getName());
+ }
+
+ @Test
+ public void create_document_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+
+ String myDocumentJson = "{\"field\":\"value\"}";
+ InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
+
+ CreateDocumentRequest.Builder builder = new CreateDocumentRequest.Builder(environmentId,
+ createCollectionResponse.getCollectionId());
+ builder.inputStream(documentStream, HttpMediaType.APPLICATION_JSON);
+
+ CreateDocumentResponse createResponse = discovery.createDocument(builder.build()).execute();
+ assertFalse(createResponse.getDocumentId().isEmpty());
+ assertNull(createResponse.getNotices());
+ }
+
+ @Test
+ public void delete_document_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ CreateDocumentResponse createDocumentResponse = createTestDocument(collectionId);
+
+ DeleteDocumentRequest deleteRequest = new DeleteDocumentRequest.Builder(environmentId, collectionId,
+ createDocumentResponse.getDocumentId()).build();
+ DeleteDocumentResponse deleteResponse = discovery.deleteDocument(deleteRequest).execute();
+ assertEquals(Status.DELETED, deleteResponse.getStatus());
+ }
+
+ @Test
+ public void get_document_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ CreateDocumentResponse createDocumentResponse = createTestDocument(collectionId);
+
+ GetDocumentRequest getRequest = new GetDocumentRequest.Builder(environmentId, collectionId,
+ createDocumentResponse.getDocumentId()).build();
+ GetDocumentResponse getResponse = discovery.getDocument(getRequest).execute();
+
+ assertEquals(Document.Status.AVAILABLE, getResponse.getStatus());
+ }
+
+ @Test
+ public void update_document_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ CreateDocumentResponse createDocumentResponse = createTestDocument(collectionId);
+
+ UpdateDocumentRequest.Builder updateBuilder = new UpdateDocumentRequest.Builder(environmentId, collectionId,
+ createDocumentResponse.getDocumentId());
+ String myDocumentJson = "{\"field\":\"value2\"}";
+ InputStream documentStream = new ByteArrayInputStream(myDocumentJson.getBytes());
+ updateBuilder.inputStream(documentStream, HttpMediaType.APPLICATION_JSON);
+ UpdateDocumentResponse updateResponse = discovery.updateDocument(updateBuilder.build()).execute();
+
+ GetDocumentRequest getRequest = new GetDocumentRequest.Builder(environmentId, collectionId,
+ updateResponse.getDocumentId()).build();
+ GetDocumentResponse getResponse = discovery.getDocument(getRequest).execute();
+
+ assertEquals(Document.Status.AVAILABLE, getResponse.getStatus());
+ }
+
+ @Test
+ public void get_collection_fields_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ createTestDocument(collectionId);
+
+ GetCollectionFieldsRequest getRequest = new GetCollectionFieldsRequest.Builder(environmentId, collectionId)
+ .build();
+ GetCollectionFieldsResponse getResponse = discovery.getCollectionFields(getRequest).execute();
+
+ assertFalse(getResponse.getFields().isEmpty());
+ }
+
+ @Test
+ public void query_with_count_is_successful() {
+ String collectionId = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ queryBuilder.count(5);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ assertEquals(new Long(10), queryResponse.getMatchingResults());
+ assertEquals(5, queryResponse.getResults().size());
+ }
+
+ @Test
+ public void query_with_offset_is_successful() {
+ String collectionId = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ queryBuilder.offset(5);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ assertEquals(new Long(10), queryResponse.getMatchingResults());
+ assertEquals(5, queryResponse.getResults().size());
+ }
+
+ @Test
+ public void query_with_return_fields_is_successful() {
+ String collectionId = setupTestDocuments();
+ createTestDocument("{\"field_2\":\"value_2\"}", collectionId);
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ Set fieldNames = new HashSet();
+ fieldNames.add("field");
+ queryBuilder.returnFields(fieldNames);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ String[] expected = new String[] { "id", "score", "field" };
+ assertArrayEquals(expected, queryResponse.getResults().get(0).keySet().toArray());
+ }
+
+ @Test
+ public void query_with_query_is_successful() {
+ String collectionId = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ queryBuilder.query("field" + Operator.CONTAINS + 1);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ assertEquals(new Long(1), queryResponse.getMatchingResults());
+ assertEquals(1, queryResponse.getResults().size());
+ assertTrue((double) queryResponse.getResults().get(0).get("score") > 1.0);
+ }
+
+ @Test
+ public void query_with_filter_is_successful() {
+ String collectionId = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ queryBuilder.filter("field" + Operator.CONTAINS + 1);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ assertEquals(new Long(1), queryResponse.getMatchingResults());
+ assertEquals(1, queryResponse.getResults().size());
+ }
+
+ @Test
+ public void query_with_aggregation_term_is_successful() {
+ String collectionId = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.TERM);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ assertEquals(1, queryResponse.getAggregations().size());
+ }
+
+ @Test
+ public void query_with_nested_aggregation_term_is_successful() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ createTestDocument(collectionId);
+ createTestDocument(collectionId);
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionId);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.TERM);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ sb.append(Operator.NEST_AGGREGATION);
+ sb.append(AggregationType.TERM);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Term term = (Term) queryResponse.getAggregations().get(0);
+ assertFalse(term.getResults().get(0).getAggregations().isEmpty());
+ }
+
+ @Test
+ public void query_with_aggregation_histogram_is_successful() throws InterruptedException {
+ String collectionName = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionName);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.HISTOGRAM);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.AND);
+ sb.append(5);
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Histogram histogram = (Histogram) queryResponse.getAggregations().get(0);
+ assertEquals(new Long(5), histogram.getInterval());
+ assertEquals(2, histogram.getResults().size());
+ }
+
+ @Test
+ public void query_with_aggregation_maximum_is_successful() throws InterruptedException {
+ String collectionName = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionName);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.MAX);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Calculation max = (Calculation) queryResponse.getAggregations().get(0);
+ assertEquals(AggregationType.MAX.getName(), max.getType());
+ assertEquals(new Double(9), max.getValue());
+ }
+
+ @Test
+ public void query_with_aggregation_minimum_is_successful() throws InterruptedException {
+ String collectionName = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionName);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.MIN);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Calculation min = (Calculation) queryResponse.getAggregations().get(0);
+ assertEquals(AggregationType.MIN.getName(), min.getType());
+ assertEquals(new Double(0), min.getValue());
+ }
+
+ @Test
+ public void query_with_aggregation_summation_is_successful() throws InterruptedException {
+ String collectionName = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionName);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.SUM);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Calculation sum = (Calculation) queryResponse.getAggregations().get(0);
+ assertEquals(AggregationType.SUM.getName(), sum.getType());
+ assertEquals(new Double(45), sum.getValue());
+ }
+
+ @Test
+ public void query_with_aggregation_average_is_successful() throws InterruptedException {
+ String collectionName = setupTestDocuments();
+
+ QueryRequest.Builder queryBuilder = new QueryRequest.Builder(environmentId, collectionName);
+ StringBuilder sb = new StringBuilder();
+ sb.append(AggregationType.AVERAGE);
+ sb.append(Operator.OPENING_GROUPING);
+ sb.append("field");
+ sb.append(Operator.CLOSING_GROUPING);
+ String aggregation = sb.toString();
+ queryBuilder.aggregation(aggregation);
+ QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
+ Calculation avg = (Calculation) queryResponse.getAggregations().get(0);
+ assertEquals(AggregationType.AVERAGE.getName(), avg.getType());
+ assertEquals(new Double(4.5), avg.getValue());
+ }
+
+ private CreateEnvironmentResponse createEnvironment(CreateEnvironmentRequest createRequest) {
+ CreateEnvironmentResponse createResponse = discovery.createEnvironment(createRequest).execute();
+ return createResponse;
+ }
+
+ private DeleteEnvironmentResponse deleteEnvironment(DeleteEnvironmentRequest deleteRequest) {
+ DeleteEnvironmentResponse deleteResponse = discovery.deleteEnvironment(deleteRequest).execute();
+ return deleteResponse;
+ }
+
+ private CreateConfigurationResponse createConfiguration(CreateConfigurationRequest createRequest) {
+ CreateConfigurationResponse createResponse = discovery.createConfiguration(createRequest).execute();
+ configurationIds.add(createResponse.getConfigurationId());
+ return createResponse;
+ }
+
+ private DeleteConfigurationResponse deleteConfiguration(DeleteConfigurationRequest deleteRequest) {
+ DeleteConfigurationResponse deleteResponse = discovery.deleteConfiguration(deleteRequest).execute();
+ configurationIds.remove(deleteResponse.getConfigurationId());
+ return deleteResponse;
+ }
+
+ private CreateConfigurationResponse createTestConfig() {
+ String uniqueConfigName = uniqueName + "-config";
+ CreateConfigurationRequest.Builder createBuilder = new CreateConfigurationRequest.Builder(environmentId);
+ Configuration configuration = getTestConfiguration();
+ configuration.setName(uniqueConfigName);
+ createBuilder.configuration(configuration);
+ return createConfiguration(createBuilder.build());
+ }
+
+ private CreateCollectionResponse createCollection(CreateCollectionRequest createRequest) {
+ CreateCollectionResponse createResponse = discovery.createCollection(createRequest).execute();
+ collectionIds.add(createResponse.getCollectionId());
+ return createResponse;
+ }
+
+ private DeleteCollectionResponse deleteCollection(DeleteCollectionRequest deleteRequest) {
+ DeleteCollectionResponse deleteResponse = discovery.deleteCollection(deleteRequest).execute();
+ collectionIds.remove(deleteResponse.getCollectionId());
+ return deleteResponse;
+ }
+
+ private CreateCollectionResponse createTestCollection() {
+ CreateConfigurationResponse createConfigResponse = createTestConfig();
+
+ String uniqueCollectionName = uniqueName + "-collection";
+ CreateCollectionRequest.Builder createCollectionBuilder = new CreateCollectionRequest.Builder(environmentId,
+ createConfigResponse.getConfigurationId(), uniqueCollectionName);
+ CreateCollectionResponse createResponse = createCollection(createCollectionBuilder.build());
+ return createResponse;
+ }
+
+ private CreateDocumentResponse createTestDocument(String collectionId) {
+ String myDocumentJson = "{\"field\":\"value\"}";
+ return createTestDocument(myDocumentJson, collectionId);
+ }
+
+ private CreateDocumentResponse createTestDocument(String json, String collectionId) {
+ InputStream documentStream = new ByteArrayInputStream(json.getBytes());
+ CreateDocumentRequest.Builder builder = new CreateDocumentRequest.Builder(environmentId, collectionId);
+ builder.inputStream(documentStream, HttpMediaType.APPLICATION_JSON);
+ CreateDocumentResponse createResponse = discovery.createDocument(builder.build()).execute();
+ WaitFor.Condition documentAccepted = new DocumentAccepted(environmentId, collectionId,
+ createResponse.getDocumentId());
+ WaitFor.waitFor(documentAccepted, 5, TimeUnit.SECONDS, 500);
+ return createResponse;
+ }
+
+ private List createTestDocuments(String collectionId, int totalDocuments) {
+ List responses = new ArrayList();
+ String baseDocumentJson = "{\"field\":";
+ for (int i = 0; i < totalDocuments; i++) {
+ String json = baseDocumentJson + i + "}";
+ responses.add(createTestDocument(json, collectionId));
+ }
+ return responses;
+ }
+
+ private String setupTestDocuments() {
+ CreateCollectionResponse createCollectionResponse = createTestCollection();
+ String collectionId = createCollectionResponse.getCollectionId();
+ List createDocumentResponses = createTestDocuments(collectionId, 10);
+ return collectionId;
+ }
+
+ public static Configuration getTestConfiguration() {
+ try {
+ return GsonSingleton.getGson().fromJson(new FileReader(DISCOVERY_TEST_CONFIG_FILE), Configuration.class);
+ } catch (FileNotFoundException e) {
+ return null;
+ }
+ }
+
+ private class DocumentAccepted implements WaitFor.Condition {
+ private final String environmentId;
+ private final String collectionId;
+ private final String documentId;
+
+ public DocumentAccepted(String environmentId, String collectionId, String documentId) {
+ this.environmentId = environmentId;
+ this.collectionId = collectionId;
+ this.documentId = documentId;
+ }
+
+ @Override
+ public boolean isSatisfied() {
+ GetDocumentRequest getRequest = new GetDocumentRequest.Builder(environmentId, collectionId, documentId)
+ .build();
+ Document.Status status = discovery.getDocument(getRequest).execute().getStatus();
+ return status.equals(Document.Status.AVAILABLE);
+ }
+ }
+}
diff --git a/tests/src/test/java/com/ibm/watson/developer_cloud/util/WaitFor.java b/tests/src/test/java/com/ibm/watson/developer_cloud/util/WaitFor.java
new file mode 100644
index 00000000000..dfe0bf6b3f9
--- /dev/null
+++ b/tests/src/test/java/com/ibm/watson/developer_cloud/util/WaitFor.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016 IBM Corp. All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+
+package com.ibm.watson.developer_cloud.util;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Wait for a certain condition to be true or for a timeout to expire.
+ *
+ */
+
+public class WaitFor {
+ /**
+ * Static method used to wait for a specific condition to be satisfied.
+ *
+ * @param condition
+ * The condition to check
+ * @param time
+ * The maximum time to wait for the condition to become true
+ * @param unit
+ * The time unit of the {@code time} argument
+ * @param sleepMs
+ * The time to wait between checks
+ *
+ * @return true if the condition was true before the timeout, false if it wasn't.
+ */
+ public static boolean waitFor(Condition condition, long time, TimeUnit unit, long sleepMs) {
+ long waitMs = unit.toMillis(time);
+ long startMs = System.currentTimeMillis();
+ while (System.currentTimeMillis() - startMs < waitMs) {
+ if (condition.isSatisfied()) {
+ return true;
+ }
+ try {
+ Thread.sleep(sleepMs);
+ } catch (InterruptedException e) {
+ throw new RuntimeException("WaitFor aborted", e);
+ }
+ }
+ return false;
+ }
+
+ public interface Condition {
+ /**
+ * @return true/false indicating whether or not the condition has been met.
+ */
+ boolean isSatisfied();
+ }
+}
diff --git a/tests/src/test/resources/config.properties b/tests/src/test/resources/config.properties
index d3a0a4a0f30..da7d55ece40 100644
--- a/tests/src/test/resources/config.properties
+++ b/tests/src/test/resources/config.properties
@@ -12,6 +12,10 @@ dialog.password=SERVICE_PASSWORD
dialog.url=SERVICE_URL
dialog.username=SERVICE_USERNAME
+discovery.password=SERVICE_PASSWORD
+discovery.url=SERVICE_URL
+discovery.username=SERVICE_USERNAME
+
document_conversion.password=SERVICE_PASSWORD
document_conversion.url=SERVICE_URL
document_conversion.username=SERVICE_USERNAME
diff --git a/tests/src/test/resources/discovery/test-config.json b/tests/src/test/resources/discovery/test-config.json
new file mode 100644
index 00000000000..120e8b6da26
--- /dev/null
+++ b/tests/src/test/resources/discovery/test-config.json
@@ -0,0 +1,3 @@
+{
+ "name": "watson_developer_cloud_config"
+}
diff --git a/tests/src/test/resources/vcap_services.json b/tests/src/test/resources/vcap_services.json
index 8478698a20e..b15d92024cd 100644
--- a/tests/src/test/resources/vcap_services.json
+++ b/tests/src/test/resources/vcap_services.json
@@ -35,6 +35,18 @@
}
}
],
+ "discovery": [
+ {
+ "name": "discovery",
+ "label": "discovery",
+ "plan": "experimental",
+ "credentials": {
+ "url": "https://gateway.watsonplatform.net/discovery-experimental/api",
+ "username": "not-a-username",
+ "password": "not-a-password"
+ }
+ }
+ ],
"document_conversion": [
{
"name": "document_conversion_experimental_docs",