use of com.ibm.watson.assistant.v2.model.LogCollection in project java-sdk by watson-developer-cloud.
the class AssistantTest method testListAllLogsWOptions.
// Test the listAllLogs operation with a valid options model parameter
@Test
public void testListAllLogsWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"logs\": [{\"request\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"alternate_intents\": false, \"context\": {\"conversation_id\": \"conversationId\", \"system\": {\"mapKey\": \"anyValue\"}, \"metadata\": {\"deployment\": \"deployment\", \"user_id\": \"userId\"}}, \"output\": {\"nodes_visited\": [\"nodesVisited\"], \"nodes_visited_details\": [{\"dialog_node\": \"dialogNode\", \"title\": \"title\", \"conditions\": \"conditions\"}], \"log_messages\": [{\"level\": \"info\", \"msg\": \"msg\", \"code\": \"code\", \"source\": {\"type\": \"dialog_node\", \"dialog_node\": \"dialogNode\"}}], \"generic\": [{\"response_type\": \"option\", \"title\": \"title\", \"description\": \"description\", \"preference\": \"dropdown\", \"options\": [{\"label\": \"label\", \"value\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}]}}], \"channels\": [{\"channel\": \"chat\"}]}]}, \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"user_id\": \"userId\"}, \"response\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}], \"alternate_intents\": false, \"context\": {\"conversation_id\": \"conversationId\", \"system\": {\"mapKey\": \"anyValue\"}, \"metadata\": {\"deployment\": \"deployment\", \"user_id\": \"userId\"}}, \"output\": {\"nodes_visited\": [\"nodesVisited\"], \"nodes_visited_details\": [{\"dialog_node\": \"dialogNode\", \"title\": \"title\", \"conditions\": \"conditions\"}], \"log_messages\": [{\"level\": \"info\", \"msg\": \"msg\", \"code\": \"code\", \"source\": {\"type\": \"dialog_node\", \"dialog_node\": \"dialogNode\"}}], \"generic\": [{\"response_type\": \"option\", \"title\": \"title\", \"description\": \"description\", \"preference\": \"dropdown\", \"options\": [{\"label\": \"label\", \"value\": {\"input\": {\"text\": \"text\", \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"suggested_text\": \"suggestedText\", \"original_text\": \"originalText\"}, \"intents\": [{\"intent\": \"intent\", \"confidence\": 10}], \"entities\": [{\"entity\": \"entity\", \"location\": [8], \"value\": \"value\", \"confidence\": 10, \"groups\": [{\"group\": \"group\", \"location\": [8]}], \"interpretation\": {\"calendar_type\": \"calendarType\", \"datetime_link\": \"datetimeLink\", \"festival\": \"festival\", \"granularity\": \"day\", \"range_link\": \"rangeLink\", \"range_modifier\": \"rangeModifier\", \"relative_day\": 11, \"relative_month\": 13, \"relative_week\": 12, \"relative_weekend\": 15, \"relative_year\": 12, \"specific_day\": 11, \"specific_day_of_week\": \"specificDayOfWeek\", \"specific_month\": 13, \"specific_quarter\": 15, \"specific_year\": 12, \"numeric_value\": 12, \"subtype\": \"subtype\", \"part_of_day\": \"partOfDay\", \"relative_hour\": 12, \"relative_minute\": 14, \"relative_second\": 14, \"specific_hour\": 12, \"specific_minute\": 14, \"specific_second\": 14, \"timezone\": \"timezone\"}, \"alternatives\": [{\"value\": \"value\", \"confidence\": 10}], \"role\": {\"type\": \"date_from\"}}]}}], \"channels\": [{\"channel\": \"chat\"}]}]}, \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"user_id\": \"userId\"}, \"log_id\": \"logId\", \"request_timestamp\": \"requestTimestamp\", \"response_timestamp\": \"responseTimestamp\", \"workspace_id\": \"workspaceId\", \"language\": \"language\"}], \"pagination\": {\"next_url\": \"nextUrl\", \"matched\": 7, \"next_cursor\": \"nextCursor\"}}";
String listAllLogsPath = "/v1/logs";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListAllLogsOptions model
ListAllLogsOptions listAllLogsOptionsModel = new ListAllLogsOptions.Builder().filter("testString").sort("testString").pageLimit(Long.valueOf("26")).cursor("testString").build();
// Invoke listAllLogs() with a valid options model and verify the result
Response<LogCollection> response = assistantService.listAllLogs(listAllLogsOptionsModel).execute();
assertNotNull(response);
LogCollection 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, listAllLogsPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(query.get("filter"), "testString");
assertEquals(query.get("sort"), "testString");
assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
assertEquals(query.get("cursor"), "testString");
}
use of com.ibm.watson.assistant.v2.model.LogCollection in project java-sdk by watson-developer-cloud.
the class Assistant method listAllLogs.
/**
* List log events in all workspaces.
*
* <p>List the events from the logs of all workspaces in the service instance.
*
* @param listAllLogsOptions the {@link ListAllLogsOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link LogCollection}
*/
public ServiceCall<LogCollection> listAllLogs(ListAllLogsOptions listAllLogsOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(listAllLogsOptions, "listAllLogsOptions cannot be null");
RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/logs"));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listAllLogs");
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));
builder.query("filter", String.valueOf(listAllLogsOptions.filter()));
if (listAllLogsOptions.sort() != null) {
builder.query("sort", String.valueOf(listAllLogsOptions.sort()));
}
if (listAllLogsOptions.pageLimit() != null) {
builder.query("page_limit", String.valueOf(listAllLogsOptions.pageLimit()));
}
if (listAllLogsOptions.cursor() != null) {
builder.query("cursor", String.valueOf(listAllLogsOptions.cursor()));
}
ResponseConverter<LogCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<LogCollection>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.v2.model.LogCollection in project java-sdk by watson-developer-cloud.
the class AssistantServiceIT method testListLogs.
/**
* Test List Logs.
*/
// @Test
public void testListLogs() {
// list logs sorted by timestamp and that contain the text Hello
Builder builder = new ListLogsOptions.Builder();
builder.assistantId(assistantId);
builder.sort("request_timestamp");
builder.filter("request.input.text::\"Hello\"");
builder.pageLimit(5);
LogCollection logCollection = service.listLogs(builder.build()).execute().getResult();
assertNotNull(logCollection);
assertTrue(logCollection.getLogs().get(0).getRequest().input().text().contains("Hello"));
assertTrue(logCollection.getLogs().get(0).getLanguage().equals("en"));
}
use of com.ibm.watson.assistant.v2.model.LogCollection 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.assistant.v2.model.LogCollection in project java-sdk by watson-developer-cloud.
the class ConversationServiceIT 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());
}
}
Aggregations