Search in sources :

Example 31 with Example

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

the class Assistant method updateExample.

/**
 * Update user input example.
 *
 * <p>Update the text of a user input example.
 *
 * <p>If you want to update multiple examples with a single API call, consider using the **[Update
 * intent](#update-intent)** method instead.
 *
 * @param updateExampleOptions the {@link UpdateExampleOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Example}
 */
public ServiceCall<Example> updateExample(UpdateExampleOptions updateExampleOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateExampleOptions, "updateExampleOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateExampleOptions.workspaceId());
    pathParamsMap.put("intent", updateExampleOptions.intent());
    pathParamsMap.put("text", updateExampleOptions.text());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/intents/{intent}/examples/{text}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateExample");
    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));
    if (updateExampleOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateExampleOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateExampleOptions.newText() != null) {
        contentJson.addProperty("text", updateExampleOptions.newText());
    }
    if (updateExampleOptions.newMentions() != null) {
        contentJson.add("mentions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateExampleOptions.newMentions()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Example> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Example>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Example(com.ibm.watson.assistant.v1.model.Example) JsonObject(com.google.gson.JsonObject)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)14 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)14 Test (org.junit.Test)14 Example (com.ibm.watson.assistant.v1.model.Example)10 Example (com.ibm.watson.developer_cloud.assistant.v1.model.Example)10 Example (com.ibm.watson.developer_cloud.conversation.v1.model.Example)10 Date (java.util.Date)10 CreateExample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateExample)7 CreateExample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExample)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)7 Test (org.testng.annotations.Test)7 JsonObject (com.google.gson.JsonObject)6 Mention (com.ibm.watson.assistant.v1.model.Mention)6 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)4 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)4 CreateExampleOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateExampleOptions)4