Search in sources :

Example 56 with Collection

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

the class Discovery method createStopwordList.

/**
 * Create stopword list.
 *
 * <p>Upload a custom stopword list to use with the specified collection.
 *
 * @param createStopwordListOptions the {@link CreateStopwordListOptions} containing the options
 *     for the call
 * @return a {@link ServiceCall} with a result of type {@link TokenDictStatusResponse}
 */
public ServiceCall<TokenDictStatusResponse> createStopwordList(CreateStopwordListOptions createStopwordListOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createStopwordListOptions, "createStopwordListOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createStopwordListOptions.environmentId());
    pathParamsMap.put("collection_id", createStopwordListOptions.collectionId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/word_lists/stopwords", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createStopwordList");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
    multipartBuilder.setType(MultipartBody.FORM);
    okhttp3.RequestBody stopwordFileBody = RequestUtils.inputStreamBody(createStopwordListOptions.stopwordFile(), "application/octet-stream");
    multipartBuilder.addFormDataPart("stopword_file", createStopwordListOptions.stopwordFilename(), stopwordFileBody);
    builder.body(multipartBuilder.build());
    ResponseConverter<TokenDictStatusResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TokenDictStatusResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)

Example 57 with Collection

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

the class Discovery method getTokenizationDictionaryStatus.

/**
 * Get tokenization dictionary status.
 *
 * <p>Returns the current status of the tokenization dictionary for the specified collection.
 *
 * @param getTokenizationDictionaryStatusOptions the {@link
 *     GetTokenizationDictionaryStatusOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link TokenDictStatusResponse}
 */
public ServiceCall<TokenDictStatusResponse> getTokenizationDictionaryStatus(GetTokenizationDictionaryStatusOptions getTokenizationDictionaryStatusOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getTokenizationDictionaryStatusOptions, "getTokenizationDictionaryStatusOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", getTokenizationDictionaryStatusOptions.environmentId());
    pathParamsMap.put("collection_id", getTokenizationDictionaryStatusOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/word_lists/tokenization_dictionary", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "getTokenizationDictionaryStatus");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<TokenDictStatusResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<TokenDictStatusResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) TokenDictStatusResponse(com.ibm.watson.discovery.v1.model.TokenDictStatusResponse)

Example 58 with Collection

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

the class Discovery method deleteCollection.

/**
 * Delete a collection.
 *
 * @param deleteCollectionOptions the {@link DeleteCollectionOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link DeleteCollectionResponse}
 */
public ServiceCall<DeleteCollectionResponse> deleteCollection(DeleteCollectionOptions deleteCollectionOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(deleteCollectionOptions, "deleteCollectionOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", deleteCollectionOptions.environmentId());
    pathParamsMap.put("collection_id", deleteCollectionOptions.collectionId());
    RequestBuilder builder = RequestBuilder.delete(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "deleteCollection");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<DeleteCollectionResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DeleteCollectionResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DeleteCollectionResponse(com.ibm.watson.discovery.v1.model.DeleteCollectionResponse)

Example 59 with Collection

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

the class Discovery method createCredentials.

/**
 * Create credentials.
 *
 * <p>Creates a set of credentials to connect to a remote source. Created credentials are used in
 * a configuration to associate a collection with the remote source.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param createCredentialsOptions the {@link CreateCredentialsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Credentials}
 */
public ServiceCall<Credentials> createCredentials(CreateCredentialsOptions createCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCredentialsOptions, "createCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createCredentialsOptions.environmentId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createCredentials");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createCredentialsOptions.sourceType() != null) {
        contentJson.addProperty("source_type", createCredentialsOptions.sourceType());
    }
    if (createCredentialsOptions.credentialDetails() != null) {
        contentJson.add("credential_details", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.credentialDetails()));
    }
    if (createCredentialsOptions.status() != null) {
        contentJson.add("status", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.status()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Credentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Credentials>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Example 60 with Collection

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

the class Discovery method listCollectionFields.

/**
 * List collection fields.
 *
 * <p>Gets a list of the unique fields (and their types) stored in the index.
 *
 * @param listCollectionFieldsOptions the {@link ListCollectionFieldsOptions} containing the
 *     options for the call
 * @return a {@link ServiceCall} with a result of type {@link ListCollectionFieldsResponse}
 */
public ServiceCall<ListCollectionFieldsResponse> listCollectionFields(ListCollectionFieldsOptions listCollectionFieldsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCollectionFieldsOptions, "listCollectionFieldsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listCollectionFieldsOptions.environmentId());
    pathParamsMap.put("collection_id", listCollectionFieldsOptions.collectionId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/collections/{collection_id}/fields", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCollectionFields");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<ListCollectionFieldsResponse> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ListCollectionFieldsResponse>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) ListCollectionFieldsResponse(com.ibm.watson.discovery.v1.model.ListCollectionFieldsResponse)

Aggregations

Collection (com.ibm.watson.developer_cloud.discovery.v1.model.Collection)26 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)23 HashMap (java.util.HashMap)22 Test (org.junit.Test)22 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)18 JsonObject (com.google.gson.JsonObject)15 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)14 Collection (com.ibm.watson.visual_recognition.v4.model.Collection)11 DocumentAccepted (com.ibm.watson.developer_cloud.discovery.v1.model.DocumentAccepted)10 CreateCollectionOptions (com.ibm.watson.developer_cloud.discovery.v1.model.CreateCollectionOptions)9 Collection (com.ibm.watson.discovery.v1.model.Collection)9 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 MockResponse (okhttp3.mockwebserver.MockResponse)8 Test (org.testng.annotations.Test)7 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 AddDocumentOptions (com.ibm.watson.developer_cloud.discovery.v1.model.AddDocumentOptions)5 QueryOptions (com.ibm.watson.developer_cloud.discovery.v1.model.QueryOptions)5