use of com.ibm.watson.assistant.v1.model.ValueCollection in project java-sdk by watson-developer-cloud.
the class ValuesIT method testListValuesWithPaging.
/**
* Test listValues with pagination.
*/
@Test
public void testListValuesWithPaging() {
String entity = "beverage";
String entityValue1 = "coffee";
String entityValue2 = "orange juice";
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, entityValue1).build();
try {
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
service.createValue(createOptions.newBuilder().value(entityValue2).build()).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
ListValuesOptions.Builder listOptionsBuilder = new ListValuesOptions.Builder(workspaceId, entity);
listOptionsBuilder.sort("updated");
listOptionsBuilder.pageLimit(1L);
listOptionsBuilder.export(true);
ValueCollection response = service.listValues(listOptionsBuilder.build()).execute();
assertNotNull(response);
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
boolean found1 = false, found2 = false;
while (true) {
assertNotNull(response.getValues());
assertTrue(response.getValues().size() == 1);
found1 |= response.getValues().get(0).getValueText().equals(entityValue1);
found2 |= response.getValues().get(0).getValueText().equals(entityValue2);
if (response.getPagination().getCursor() == null) {
break;
}
String cursor = response.getPagination().getCursor();
response = service.listValues(listOptionsBuilder.cursor(cursor).build()).execute();
}
assertTrue(found1 && found2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.deleteValue(deleteOptions).execute();
service.deleteValue(deleteOptions.newBuilder().value(entityValue2).build()).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ValueCollection in project java-sdk by watson-developer-cloud.
the class ValuesIT method testListValuesWithPaging.
/**
* Test listValues with pagination.
*/
@Test
public void testListValuesWithPaging() {
String entity = "beverage";
String entityValue1 = "coffee";
String entityValue2 = "orange juice";
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, entityValue1).build();
try {
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
service.createValue(createOptions.newBuilder().value(entityValue2).build()).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
ListValuesOptions.Builder listOptionsBuilder = new ListValuesOptions.Builder(workspaceId, entity);
listOptionsBuilder.sort("updated");
listOptionsBuilder.pageLimit(1L);
listOptionsBuilder.export(true);
ValueCollection response = service.listValues(listOptionsBuilder.build()).execute();
assertNotNull(response);
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
boolean found1 = false, found2 = false;
while (true) {
assertNotNull(response.getValues());
assertTrue(response.getValues().size() == 1);
found1 |= response.getValues().get(0).getValueText().equals(entityValue1);
found2 |= response.getValues().get(0).getValueText().equals(entityValue2);
if (response.getPagination().getCursor() == null) {
break;
}
String cursor = response.getPagination().getCursor();
response = service.listValues(listOptionsBuilder.cursor(cursor).build()).execute();
}
assertTrue(found1 && found2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.deleteValue(deleteOptions).execute();
service.deleteValue(deleteOptions.newBuilder().value(entityValue2).build()).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ValueCollection in project java-sdk by watson-developer-cloud.
the class Assistant method listValues.
/**
* List entity values.
*
* <p>List the values for an entity.
*
* @param listValuesOptions the {@link ListValuesOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link ValueCollection}
*/
public ServiceCall<ValueCollection> listValues(ListValuesOptions listValuesOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listValuesOptions, "listValuesOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", listValuesOptions.workspaceId());
pathParamsMap.put("entity", listValuesOptions.entity());
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}/values", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listValues");
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 (listValuesOptions.export() != null) {
builder.query("export", String.valueOf(listValuesOptions.export()));
}
if (listValuesOptions.pageLimit() != null) {
builder.query("page_limit", String.valueOf(listValuesOptions.pageLimit()));
}
if (listValuesOptions.includeCount() != null) {
builder.query("include_count", String.valueOf(listValuesOptions.includeCount()));
}
if (listValuesOptions.sort() != null) {
builder.query("sort", String.valueOf(listValuesOptions.sort()));
}
if (listValuesOptions.cursor() != null) {
builder.query("cursor", String.valueOf(listValuesOptions.cursor()));
}
if (listValuesOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(listValuesOptions.includeAudit()));
}
ResponseConverter<ValueCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<ValueCollection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v1.model.ValueCollection in project java-sdk by watson-developer-cloud.
the class ValuesIT method testListValues.
/**
* Test listValues.
*/
@Test
public void testListValues() {
String entity = "beverage";
String entityValue1 = "coffee";
String entityValue2 = "orange juice";
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, entityValue1).build();
try {
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
service.createValue(createOptions.newBuilder().value(entityValue2).build()).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
ListValuesOptions listOptions = new ListValuesOptions.Builder().workspaceId(workspaceId).entity(entity).build();
final ValueCollection response = service.listValues(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getValues());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
if (response.getPagination().getNextUrl() == null) {
assertNull(response.getPagination().getCursor());
} else {
assertNotNull(response.getPagination().getCursor());
}
assertTrue(response.getValues().size() >= 2);
// Should not be paginated, but just to be sure
if (response.getPagination().getNextUrl() == null) {
// assertTrue(response.getValues().stream().filter(r -> r.getValue().equals(synonym1)).count() == 1);
boolean found1 = false, found2 = false;
for (ValueExport valueResponse : response.getValues()) {
found1 |= valueResponse.getValueText().equals(entityValue1);
found2 |= valueResponse.getValueText().equals(entityValue2);
}
assertTrue(found1 && found2);
}
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.deleteValue(deleteOptions).execute();
service.deleteValue(deleteOptions.newBuilder().value(entityValue2).build()).execute();
}
}
use of com.ibm.watson.assistant.v1.model.ValueCollection in project java-sdk by watson-developer-cloud.
the class ValuesIT method testListValues.
/**
* Test listValues.
*/
@Test
public void testListValues() {
String entity = "beverage";
String entityValue1 = "coffee";
String entityValue2 = "orange juice";
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, entityValue1).build();
try {
service.createValue(createOptions).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
service.createValue(createOptions.newBuilder().value(entityValue2).build()).execute();
} catch (Exception ex) {
// Exception is okay if is for Unique Violation
assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
}
try {
ListValuesOptions listOptions = new ListValuesOptions.Builder().workspaceId(workspaceId).entity(entity).build();
final ValueCollection response = service.listValues(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getValues());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
if (response.getPagination().getNextUrl() == null) {
assertNull(response.getPagination().getCursor());
} else {
assertNotNull(response.getPagination().getCursor());
}
assertTrue(response.getValues().size() >= 2);
// Should not be paginated, but just to be sure
if (response.getPagination().getNextUrl() == null) {
// assertTrue(response.getValues().stream().filter(r -> r.getValue().equals(synonym1)).count() == 1);
boolean found1 = false, found2 = false;
for (ValueExport valueResponse : response.getValues()) {
found1 |= valueResponse.getValueText().equals(entityValue1);
found2 |= valueResponse.getValueText().equals(entityValue2);
}
assertTrue(found1 && found2);
}
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue1).build();
service.deleteValue(deleteOptions).execute();
service.deleteValue(deleteOptions.newBuilder().value(entityValue2).build()).execute();
}
}
Aggregations