Search in sources :

Example 11 with Enrichment

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

the class Discovery method updateEnrichment.

/**
 * Update an enrichment.
 *
 * <p>Updates an existing enrichment's name and description.
 *
 * @param updateEnrichmentOptions the {@link UpdateEnrichmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> updateEnrichment(UpdateEnrichmentOptions updateEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateEnrichmentOptions, "updateEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", updateEnrichmentOptions.projectId());
    pathParamsMap.put("enrichment_id", updateEnrichmentOptions.enrichmentId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "updateEnrichment");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("name", updateEnrichmentOptions.name());
    if (updateEnrichmentOptions.description() != null) {
        contentJson.addProperty("description", updateEnrichmentOptions.description());
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject)

Example 12 with Enrichment

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

the class Discovery method createEnrichment.

/**
 * Create an enrichment.
 *
 * <p>Create an enrichment for use with the specified project.
 *
 * @param createEnrichmentOptions the {@link CreateEnrichmentOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> createEnrichment(CreateEnrichmentOptions createEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createEnrichmentOptions, "createEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", createEnrichmentOptions.projectId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "createEnrichment");
    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);
    multipartBuilder.addFormDataPart("enrichment", createEnrichmentOptions.enrichment().toString());
    if (createEnrichmentOptions.file() != null) {
        okhttp3.RequestBody fileBody = RequestUtils.inputStreamBody(createEnrichmentOptions.file(), "application/octet-stream");
        multipartBuilder.addFormDataPart("file", "filename", fileBody);
    }
    builder.body(multipartBuilder.build());
    ResponseConverter<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody)

Example 13 with Enrichment

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

the class Discovery method getEnrichment.

/**
 * Get enrichment.
 *
 * <p>Get details about a specific enrichment.
 *
 * @param getEnrichmentOptions the {@link GetEnrichmentOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Enrichment}
 */
public ServiceCall<Enrichment> getEnrichment(GetEnrichmentOptions getEnrichmentOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getEnrichmentOptions, "getEnrichmentOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("project_id", getEnrichmentOptions.projectId());
    pathParamsMap.put("enrichment_id", getEnrichmentOptions.enrichmentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v2/projects/{project_id}/enrichments/{enrichment_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v2", "getEnrichment");
    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<Enrichment> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Enrichment>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : Enrichment(com.ibm.watson.discovery.v2.model.Enrichment) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Test (org.testng.annotations.Test)7 Enrichment (com.ibm.watson.discovery.v2.model.Enrichment)5 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 Configuration (com.ibm.watson.discovery.v1.model.Configuration)3 Conversions (com.ibm.watson.discovery.v1.model.Conversions)3 Enrichment (com.ibm.watson.discovery.v1.model.Enrichment)3 NormalizationOperation (com.ibm.watson.discovery.v1.model.NormalizationOperation)3 Source (com.ibm.watson.discovery.v1.model.Source)3 HashMap (java.util.HashMap)3 WatsonServiceTest (com.ibm.watson.developer_cloud.WatsonServiceTest)2 Configuration (com.ibm.watson.developer_cloud.discovery.v1.model.Configuration)2 Conversions (com.ibm.watson.developer_cloud.discovery.v1.model.Conversions)2 Enrichment (com.ibm.watson.developer_cloud.discovery.v1.model.Enrichment)2 CreateConfigurationOptions (com.ibm.watson.discovery.v1.model.CreateConfigurationOptions)2 EnrichmentOptions (com.ibm.watson.discovery.v1.model.EnrichmentOptions)2 FontSetting (com.ibm.watson.discovery.v1.model.FontSetting)2 HtmlSettings (com.ibm.watson.discovery.v1.model.HtmlSettings)2 NluEnrichmentConcepts (com.ibm.watson.discovery.v1.model.NluEnrichmentConcepts)2