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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations