Search in sources :

Example 16 with Value

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

the class Assistant method getValue.

/**
 * Get entity value.
 *
 * <p>Get information about an entity value.
 *
 * @param getValueOptions the {@link GetValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Value}
 */
public ServiceCall<Value> getValue(GetValueOptions getValueOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getValueOptions, "getValueOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getValueOptions.workspaceId());
    pathParamsMap.put("entity", getValueOptions.entity());
    pathParamsMap.put("value", getValueOptions.value());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getValue");
    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 (getValueOptions.export() != null) {
        builder.query("export", String.valueOf(getValueOptions.export()));
    }
    if (getValueOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getValueOptions.includeAudit()));
    }
    ResponseConverter<Value> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Value>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Value(com.ibm.watson.assistant.v1.model.Value)

Example 17 with Value

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

the class Assistant method createValue.

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

Example 18 with Value

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

the class Assistant method updateValue.

/**
 * Update entity value.
 *
 * <p>Update an existing entity value with new or modified data. You must provide component
 * objects defining the content of the updated entity value.
 *
 * <p>If you want to update multiple entity values with a single API call, consider using the
 * **[Update entity](#update-entity)** method instead.
 *
 * @param updateValueOptions the {@link UpdateValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Value}
 */
public ServiceCall<Value> updateValue(UpdateValueOptions updateValueOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateValueOptions, "updateValueOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateValueOptions.workspaceId());
    pathParamsMap.put("entity", updateValueOptions.entity());
    pathParamsMap.put("value", updateValueOptions.value());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateValue");
    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 (updateValueOptions.append() != null) {
        builder.query("append", String.valueOf(updateValueOptions.append()));
    }
    if (updateValueOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateValueOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateValueOptions.newValue() != null) {
        contentJson.addProperty("value", updateValueOptions.newValue());
    }
    if (updateValueOptions.newMetadata() != null) {
        contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateValueOptions.newMetadata()));
    }
    if (updateValueOptions.newType() != null) {
        contentJson.addProperty("type", updateValueOptions.newType());
    }
    if (updateValueOptions.newSynonyms() != null) {
        contentJson.add("synonyms", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateValueOptions.newSynonyms()));
    }
    if (updateValueOptions.newPatterns() != null) {
        contentJson.add("patterns", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateValueOptions.newPatterns()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Value> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Value>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Value(com.ibm.watson.assistant.v1.model.Value) JsonObject(com.google.gson.JsonObject)

Example 19 with Value

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

the class Assistant method listSynonyms.

/**
 * List entity value synonyms.
 *
 * <p>List the synonyms for an entity value.
 *
 * @param listSynonymsOptions the {@link ListSynonymsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link SynonymCollection}
 */
public ServiceCall<SynonymCollection> listSynonyms(ListSynonymsOptions listSynonymsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listSynonymsOptions, "listSynonymsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", listSynonymsOptions.workspaceId());
    pathParamsMap.put("entity", listSynonymsOptions.entity());
    pathParamsMap.put("value", listSynonymsOptions.value());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values/{value}/synonyms", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listSynonyms");
    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 (listSynonymsOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listSynonymsOptions.pageLimit()));
    }
    if (listSynonymsOptions.includeCount() != null) {
        builder.query("include_count", String.valueOf(listSynonymsOptions.includeCount()));
    }
    if (listSynonymsOptions.sort() != null) {
        builder.query("sort", String.valueOf(listSynonymsOptions.sort()));
    }
    if (listSynonymsOptions.cursor() != null) {
        builder.query("cursor", String.valueOf(listSynonymsOptions.cursor()));
    }
    if (listSynonymsOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listSynonymsOptions.includeAudit()));
    }
    ResponseConverter<SynonymCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<SynonymCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) SynonymCollection(com.ibm.watson.assistant.v1.model.SynonymCollection)

Example 20 with Value

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

the class AssistantTest method testGetSynonymWOptions.

// Test the getSynonym operation with a valid options model parameter
@Test
public void testGetSynonymWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"synonym\": \"synonym\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}";
    String getSynonymPath = "/v1/workspaces/testString/entities/testString/values/testString/synonyms/testString";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the GetSynonymOptions model
    GetSynonymOptions getSynonymOptionsModel = new GetSynonymOptions.Builder().workspaceId("testString").entity("testString").value("testString").synonym("testString").includeAudit(false).build();
    // Invoke getSynonym() with a valid options model and verify the result
    Response<Synonym> response = assistantService.getSynonym(getSynonymOptionsModel).execute();
    assertNotNull(response);
    Synonym responseObj = response.getResult();
    assertNotNull(responseObj);
    // Verify the contents of the request sent to the mock server
    RecordedRequest request = server.takeRequest();
    assertNotNull(request);
    assertEquals(request.getMethod(), "GET");
    // Verify request path
    String parsedPath = TestUtilities.parseReqPath(request);
    assertEquals(parsedPath, getSynonymPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) GetSynonymOptions(com.ibm.watson.assistant.v1.model.GetSynonymOptions) Synonym(com.ibm.watson.assistant.v1.model.Synonym) Test(org.testng.annotations.Test)

Aggregations

MockResponse (okhttp3.mockwebserver.MockResponse)22 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)22 Test (org.testng.annotations.Test)22 HashMap (java.util.HashMap)21 Test (org.junit.Test)20 CreateEntityOptions (com.ibm.watson.assistant.v1.model.CreateEntityOptions)15 NotFoundException (com.ibm.cloud.sdk.core.service.exception.NotFoundException)14 Value (com.ibm.watson.assistant.v1.model.Value)12 CreateValueOptions (com.ibm.watson.assistant.v1.model.CreateValueOptions)11 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)10 Synonym (com.ibm.watson.assistant.v1.model.Synonym)10 JsonObject (com.google.gson.JsonObject)8 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)7 DeleteValueOptions (com.ibm.watson.assistant.v1.model.DeleteValueOptions)7 Entity (com.ibm.watson.assistant.v1.model.Entity)7 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)5 CreateSynonymOptions (com.ibm.watson.assistant.v1.model.CreateSynonymOptions)5 DeleteSynonymOptions (com.ibm.watson.assistant.v1.model.DeleteSynonymOptions)5 Value (com.ibm.watson.developer_cloud.assistant.v1.model.Value)5 Value (com.ibm.watson.developer_cloud.conversation.v1.model.Value)5