use of com.ibm.watson.developer_cloud.assistant.v1.model.Pagination in project java-sdk by watson-developer-cloud.
the class PaginationTypeAdapter method read.
/*
* (non-Javadoc)
* @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
*/
@Override
public Pagination read(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return null;
}
reader.beginObject();
Pagination pagination = new Pagination();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals(REFRESH_URL)) {
pagination.setRefreshUrl(reader.nextString());
} else if (name.equals(NEXT_URL)) {
String nextUrl = reader.nextString();
HttpUrl url = HttpUrl.parse(DEFAULT_ENDPOINT + nextUrl);
pagination.setCursor(url.queryParameter(CURSOR));
pagination.setNextUrl(nextUrl);
} else if (name.equals(TOTAL)) {
pagination.setTotal(reader.nextLong());
} else if (name.equals(MATCHED)) {
pagination.setMatched(reader.nextLong());
} else {
reader.skipValue();
}
}
reader.endObject();
return pagination;
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.Pagination in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListLogsWithPaging.
/**
* Test listLogs with pagination.
*/
@Test
@Ignore("To be run locally until we fix the Rate limitation issue")
public void testListLogsWithPaging() {
try {
ListLogsOptions.Builder listOptionsBuilder = new ListLogsOptions.Builder(workspaceId);
listOptionsBuilder.sort("-request_timestamp");
listOptionsBuilder.filter("request.intents:intent:off_topic");
listOptionsBuilder.pageLimit(1L);
LogCollection response = service.listLogs(listOptionsBuilder.build()).execute();
assertNotNull(response);
assertNotNull(response.getLogs());
assertNotNull(response.getPagination());
// Empirically -- no refresh_url in pagination of listLogs
// assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
assertTrue(response.getLogs().size() == 1);
LogExport logEntry1 = response.getLogs().get(0);
String cursor = response.getPagination().getCursor();
response = service.listLogs(listOptionsBuilder.cursor(cursor).build()).execute();
assertNotNull(response.getLogs());
assertTrue(response.getLogs().size() == 1);
LogExport logEntry2 = response.getLogs().get(0);
Date requestDate1 = isoDateFormat.parse(logEntry1.getRequestTimestamp());
Date requestDate2 = isoDateFormat.parse(logEntry2.getRequestTimestamp());
assertTrue(requestDate2.before(requestDate1));
} catch (Exception ex) {
fail(ex.getMessage());
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.Pagination in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListDialogNodesWithPaging.
/**
* Test listDialogNodes with pagination.
*/
@Test
public void testListDialogNodesWithPaging() {
String dialogNodeName1 = "First" + UUID.randomUUID().toString();
String dialogNodeName2 = "Second" + UUID.randomUUID().toString();
CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.createDialogNode(createOptions).execute();
service.createDialogNode(createOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
try {
ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder().workspaceId(workspaceId).pageLimit(1L).sort("dialog_node").build();
DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
assertNotNull(response);
assertNotNull(response.getDialogNodes());
assertNotNull(response.getPagination());
assertNotNull(response.getPagination().getRefreshUrl());
assertNotNull(response.getPagination().getNextUrl());
assertNotNull(response.getPagination().getCursor());
boolean found1 = false, found2 = false;
while (true) {
assertNotNull(response.getDialogNodes());
assertTrue(response.getDialogNodes().size() == 1);
found1 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName1);
found2 |= response.getDialogNodes().get(0).getDialogNodeId().equals(dialogNodeName2);
// verify sort
assertTrue(found1 || !found2);
if (response.getPagination().getCursor() == null) {
break;
}
String cursor = response.getPagination().getCursor();
response = service.listDialogNodes(listOptions.newBuilder().cursor(cursor).build()).execute();
}
assertTrue(found1 && found2);
} catch (Exception ex) {
fail(ex.getMessage());
} finally {
// Clean up
DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName1).build();
service.deleteDialogNode(deleteOptions).execute();
service.deleteDialogNode(deleteOptions.newBuilder().dialogNode(dialogNodeName2).build()).execute();
}
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.Pagination in project java-sdk by watson-developer-cloud.
the class PaginationTypeAdapterTest method testWriteTypeAdapter.
/**
* Test write type adapter.
*
* @throws FileNotFoundException the file not found exception
*/
@Test
public void testWriteTypeAdapter() throws FileNotFoundException {
Pagination pagination = loadFixture(FIXTURE, Pagination.class);
assertNotNull(GsonSingleton.getGson().toJson(pagination), pagination.toString());
}
use of com.ibm.watson.developer_cloud.assistant.v1.model.Pagination 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