use of com.ibm.watson.assistant.v1.model.GetValueOptions 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.GetValueOptions in project java-sdk by watson-developer-cloud.
the class ValuesIT method testGetValue.
/**
* Test getValue.
*/
@Test
public void testGetValue() {
String entity = "beverage";
String entityValue = "coffee" + UUID.randomUUID().toString();
String synonym1 = "java";
String synonym2 = "joe";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute().getResult();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).synonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).build();
service.createValue(createOptions).execute().getResult();
Date start = new Date();
try {
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).export(true).includeAudit(true).build();
Value response = service.getValue(getOptions).execute().getResult();
assertNotNull(response);
assertNotNull(response.value());
assertEquals(response.value(), entityValue);
assertNotNull(response.created());
assertNotNull(response.updated());
Date now = new Date();
assertTrue(fuzzyBefore(response.created(), now));
assertTrue(fuzzyAfter(response.created(), start));
assertTrue(fuzzyBefore(response.updated(), now));
assertTrue(fuzzyAfter(response.updated(), start));
assertNotNull(response.synonyms());
assertTrue(response.synonyms().size() == 2);
assertTrue(response.synonyms().contains(synonym1));
assertTrue(response.synonyms().contains(synonym2));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute().getResult();
}
}
use of com.ibm.watson.assistant.v1.model.GetValueOptions in project java-sdk by watson-developer-cloud.
the class ValuesIT method testGetValue.
/**
* Test getValue.
*/
@Test
public void testGetValue() {
String entity = "beverage";
String entityValue = "coffee" + UUID.randomUUID().toString();
String synonym1 = "java";
String synonym2 = "joe";
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).synonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).build();
service.createValue(createOptions).execute();
Date start = new Date();
try {
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).export(true).includeAudit(true).build();
ValueExport response = service.getValue(getOptions).execute();
assertNotNull(response);
assertNotNull(response.getValueText());
assertEquals(response.getValueText(), entityValue);
assertNotNull(response.getCreated());
assertNotNull(response.getUpdated());
Date now = new Date();
assertTrue(fuzzyBefore(response.getCreated(), now));
assertTrue(fuzzyAfter(response.getCreated(), start));
assertTrue(fuzzyBefore(response.getUpdated(), now));
assertTrue(fuzzyAfter(response.getUpdated(), start));
assertNotNull(response.getSynonyms());
assertTrue(response.getSynonyms().size() == 2);
assertTrue(response.getSynonyms().contains(synonym1));
assertTrue(response.getSynonyms().contains(synonym2));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
service.deleteValue(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.GetValueOptions in project java-sdk by watson-developer-cloud.
the class ValuesIT method testUpdateValue.
/**
* Test updateValue.
*/
@Test
public void testUpdateValue() {
String entity = "beverage";
String entityValue1 = "coffee" + UUID.randomUUID().toString();
String entityValue2 = "coffee" + UUID.randomUUID().toString();
String synonym1 = "java";
String synonym2 = "joe";
// metadata
Map<String, Object> valueMetadata = new HashMap<String, Object>();
String metadataValue = "value for " + entityValue2;
valueMetadata.put("key", metadataValue);
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
UpdateValueOptions updateOptions = new UpdateValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue1).newValue(entityValue2).newSynonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).newMetadata(valueMetadata).build();
Value response = service.updateValue(updateOptions).execute();
try {
assertNotNull(response);
assertNotNull(response.getValueText());
assertEquals(response.getValueText(), entityValue2);
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue2).export(true).includeAudit(true).build();
ValueExport vResponse = service.getValue(getOptions).execute();
assertNotNull(vResponse);
assertNotNull(vResponse.getValueText());
assertEquals(vResponse.getValueText(), entityValue2);
assertNotNull(vResponse.getCreated());
assertNotNull(vResponse.getUpdated());
assertNotNull(vResponse.getSynonyms());
assertTrue(vResponse.getSynonyms().size() == 2);
assertTrue(vResponse.getSynonyms().contains(synonym1));
assertTrue(vResponse.getSynonyms().contains(synonym2));
// metadata
assertNotNull(response.getMetadata());
assertNotNull(response.getMetadata().get("key"));
assertEquals(response.getMetadata().get("key"), metadataValue);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue2).build();
service.deleteValue(deleteOptions).execute();
}
}
use of com.ibm.watson.assistant.v1.model.GetValueOptions in project java-sdk by watson-developer-cloud.
the class ValuesIT method testUpdateValue.
/**
* Test updateValue.
*/
@Test
public void testUpdateValue() {
String entity = "beverage";
String entityValue1 = "coffee" + UUID.randomUUID().toString();
String entityValue2 = "coffee" + UUID.randomUUID().toString();
String synonym1 = "java";
String synonym2 = "joe";
// metadata
Map<String, Object> valueMetadata = new HashMap<>();
String metadataValue = "value for " + entityValue2;
valueMetadata.put("key", metadataValue);
try {
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
service.createEntity(createOptions).execute().getResult();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.createValue(createOptions).execute().getResult();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
UpdateValueOptions updateOptions = new UpdateValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue1).newValue(entityValue2).newSynonyms(new ArrayList<>(Arrays.asList(synonym1, synonym2))).newMetadata(valueMetadata).build();
Value response = service.updateValue(updateOptions).execute().getResult();
try {
assertNotNull(response);
assertNotNull(response.value());
assertEquals(response.value(), entityValue2);
GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue2).export(true).includeAudit(true).build();
Value vResponse = service.getValue(getOptions).execute().getResult();
assertNotNull(vResponse);
assertNotNull(vResponse.value());
assertEquals(vResponse.value(), entityValue2);
assertNotNull(vResponse.created());
assertNotNull(vResponse.updated());
assertNotNull(vResponse.synonyms());
assertTrue(vResponse.synonyms().size() == 2);
assertTrue(vResponse.synonyms().contains(synonym1));
assertTrue(vResponse.synonyms().contains(synonym2));
// metadata
assertNotNull(response.metadata());
assertNotNull(response.metadata().get("key"));
assertEquals(response.metadata().get("key"), metadataValue);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue2).build();
service.deleteValue(deleteOptions).execute().getResult();
}
}
Aggregations