Search in sources :

Example 6 with LogCollection

use of com.ibm.watson.assistant.v1.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");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) LogCollection(com.ibm.watson.assistant.v1.model.LogCollection) ListAllLogsOptions(com.ibm.watson.assistant.v1.model.ListAllLogsOptions) Test(org.testng.annotations.Test)

Example 7 with LogCollection

use of com.ibm.watson.assistant.v1.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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) LogCollection(com.ibm.watson.assistant.v1.model.LogCollection)

Example 8 with LogCollection

use of com.ibm.watson.assistant.v1.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());
    }
}
Also used : ListLogsOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListLogsOptions) LogCollection(com.ibm.watson.developer_cloud.assistant.v1.model.LogCollection) LogExport(com.ibm.watson.developer_cloud.assistant.v1.model.LogExport) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with LogCollection

use of com.ibm.watson.assistant.v1.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());
    }
}
Also used : ListLogsOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListLogsOptions) LogCollection(com.ibm.watson.developer_cloud.conversation.v1.model.LogCollection) LogExport(com.ibm.watson.developer_cloud.conversation.v1.model.LogExport) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with LogCollection

use of com.ibm.watson.assistant.v1.model.LogCollection in project java-sdk by watson-developer-cloud.

the class Conversation method listAllLogs.

/**
 * List log events in all workspaces.
 *
 * List log events in all workspaces in the service instance.
 *
 * @param listAllLogsOptions the {@link ListAllLogsOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link LogCollection}
 */
public ServiceCall<LogCollection> listAllLogs(ListAllLogsOptions listAllLogsOptions) {
    Validator.notNull(listAllLogsOptions, "listAllLogsOptions cannot be null");
    String[] pathSegments = { "v1/logs" };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query(VERSION, versionDate);
    builder.query("filter", listAllLogsOptions.filter());
    if (listAllLogsOptions.sort() != null) {
        builder.query("sort", listAllLogsOptions.sort());
    }
    if (listAllLogsOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listAllLogsOptions.pageLimit()));
    }
    if (listAllLogsOptions.cursor() != null) {
        builder.query("cursor", listAllLogsOptions.cursor());
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(LogCollection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) LogCollection(com.ibm.watson.developer_cloud.conversation.v1.model.LogCollection)

Aggregations

LogCollection (com.ibm.watson.assistant.v1.model.LogCollection)4 LogCollection (com.ibm.watson.developer_cloud.assistant.v1.model.LogCollection)4 LogCollection (com.ibm.watson.developer_cloud.conversation.v1.model.LogCollection)4 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)4 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)4 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)4 Test (org.junit.Test)4 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 Test (org.testng.annotations.Test)3 LogCollection (com.ibm.watson.assistant.v2.model.LogCollection)2 ListLogsOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListLogsOptions)2 ListLogsOptions (com.ibm.watson.developer_cloud.conversation.v1.model.ListLogsOptions)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Ignore (org.junit.Ignore)2 ListAllLogsOptions (com.ibm.watson.assistant.v1.model.ListAllLogsOptions)1 ListLogsOptions (com.ibm.watson.assistant.v1.model.ListLogsOptions)1 ListLogsOptions (com.ibm.watson.assistant.v2.model.ListLogsOptions)1