use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testListEntitiesWithPaging.
/**
* Test listEntities with pagination.
*/
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntitiesWithPaging() {
// gotta be unique
String entity1 = "Hello" + UUID.randomUUID().toString();
// gotta be unique
String entity2 = "Goodbye" + UUID.randomUUID().toString();
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity1).build();
service.createEntity(createOptions).execute();
service.createEntity(createOptions.newBuilder().entity(entity2).build()).execute();
try {
ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).sort("entity").pageLimit(1L).build();
EntityCollection response = service.listEntities(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getEntities());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
assertTrue(!response.getEntities().get(0).getEntityName().equals(entity1));
EntityExport ieResponse = null;
while (response.getPagination().getCursor() != null) {
assertNotNull(response.getEntities());
assertTrue(response.getEntities().size() == 1);
if (response.getEntities().get(0).getEntityName().equals(entity1)) {
ieResponse = response.getEntities().get(0);
break;
}
String cursor = response.getPagination().getCursor();
response = service.listEntities(listOptions.newBuilder().cursor(cursor).build()).execute();
}
assertNotNull(ieResponse);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity1).build();
service.deleteEntity(deleteOptions).execute();
service.deleteEntity(deleteOptions.newBuilder().entity(entity2).build()).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testListEntities.
/**
* Test listEntities.
*/
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntities() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
try {
ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).build();
EntityCollection response = service.listEntities(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getEntities());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
// Now add an entity and make sure we get it back
String entityDescription = "Description of " + entity;
String entityValue = "Value of " + entity;
CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).description(entityDescription).addValue(new CreateValue.Builder(entityValue).build()).build();
service.createEntity(options).execute();
ListEntitiesOptions listOptions2 = listOptions.newBuilder().sort("-updated").pageLimit(5L).export(true).build();
EntityCollection response2 = service.listEntities(listOptions2).execute();
assertNotNull(response2);
assertNotNull(response2.getEntities());
List<EntityExport> entities = response2.getEntities();
EntityExport ieResponse = null;
for (EntityExport resp : entities) {
if (resp.getEntityName().equals(entity)) {
ieResponse = resp;
break;
}
}
assertNotNull(ieResponse);
assertNotNull(ieResponse.getDescription());
assertEquals(ieResponse.getDescription(), entityDescription);
assertNotNull(ieResponse.getValues());
assertTrue(ieResponse.getValues().size() == 1);
assertTrue(ieResponse.getValues().get(0).getValueText().equals(entityValue));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection in project java-sdk by watson-developer-cloud.
the class Assistant method listEntities.
/**
* List entities.
*
* List the entities for a workspace. With **export**=`false`, this operation is limited to 1000 requests per 30
* minutes. With **export**=`true`, the limit is 200 requests per 30 minutes. For more information, see **Rate
* limiting**.
*
* @param listEntitiesOptions the {@link ListEntitiesOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link EntityCollection}
*/
public ServiceCall<EntityCollection> listEntities(ListEntitiesOptions listEntitiesOptions) {
Validator.notNull(listEntitiesOptions, "listEntitiesOptions cannot be null");
String[] pathSegments = { "v1/workspaces", "entities" };
String[] pathParameters = { listEntitiesOptions.workspaceId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
builder.query(VERSION, versionDate);
if (listEntitiesOptions.export() != null) {
builder.query("export", String.valueOf(listEntitiesOptions.export()));
}
if (listEntitiesOptions.pageLimit() != null) {
builder.query("page_limit", String.valueOf(listEntitiesOptions.pageLimit()));
}
if (listEntitiesOptions.includeCount() != null) {
builder.query("include_count", String.valueOf(listEntitiesOptions.includeCount()));
}
if (listEntitiesOptions.sort() != null) {
builder.query("sort", listEntitiesOptions.sort());
}
if (listEntitiesOptions.cursor() != null) {
builder.query("cursor", listEntitiesOptions.cursor());
}
if (listEntitiesOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(listEntitiesOptions.includeAudit()));
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(EntityCollection.class));
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testListEntities.
/**
* Test listEntities.
*/
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntities() {
// gotta be unique
String entity = "Hello" + UUID.randomUUID().toString();
try {
ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).build();
EntityCollection response = service.listEntities(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getEntities());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
// nextUrl may be null
// Now add an entity and make sure we get it back
String entityDescription = "Description of " + entity;
String entityValue = "Value of " + entity;
CreateEntityOptions options = new CreateEntityOptions.Builder(workspaceId, entity).description(entityDescription).addValue(new CreateValue.Builder(entityValue).build()).build();
service.createEntity(options).execute();
ListEntitiesOptions listOptions2 = listOptions.newBuilder().sort("-updated").pageLimit(5L).export(true).build();
EntityCollection response2 = service.listEntities(listOptions2).execute();
assertNotNull(response2);
assertNotNull(response2.getEntities());
List<EntityExport> entities = response2.getEntities();
EntityExport ieResponse = null;
for (EntityExport resp : entities) {
if (resp.getEntityName().equals(entity)) {
ieResponse = resp;
break;
}
}
assertNotNull(ieResponse);
assertNotNull(ieResponse.getDescription());
assertEquals(ieResponse.getDescription(), entityDescription);
assertNotNull(ieResponse.getValues());
assertTrue(ieResponse.getValues().size() == 1);
assertTrue(ieResponse.getValues().get(0).getValueText().equals(entityValue));
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
service.deleteEntity(deleteOptions).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.EntityCollection in project java-sdk by watson-developer-cloud.
the class EntitiesIT method testListEntitiesWithPaging.
/**
* Test listEntities with pagination.
*/
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListEntitiesWithPaging() {
// gotta be unique
String entity1 = "Hello" + UUID.randomUUID().toString();
// gotta be unique
String entity2 = "Goodbye" + UUID.randomUUID().toString();
CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity1).build();
service.createEntity(createOptions).execute();
service.createEntity(createOptions.newBuilder().entity(entity2).build()).execute();
try {
ListEntitiesOptions listOptions = new ListEntitiesOptions.Builder(workspaceId).sort("entity").pageLimit(1L).build();
EntityCollection response = service.listEntities(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getEntities());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
assertTrue(!response.getEntities().get(0).getEntityName().equals(entity1));
EntityExport ieResponse = null;
while (response.getPagination().getCursor() != null) {
assertNotNull(response.getEntities());
assertTrue(response.getEntities().size() == 1);
if (response.getEntities().get(0).getEntityName().equals(entity1)) {
ieResponse = response.getEntities().get(0);
break;
}
String cursor = response.getPagination().getCursor();
response = service.listEntities(listOptions.newBuilder().cursor(cursor).build()).execute();
}
assertNotNull(ieResponse);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity1).build();
service.deleteEntity(deleteOptions).execute();
service.deleteEntity(deleteOptions.newBuilder().entity(entity2).build()).execute();
}
}
Aggregations