Search in sources :

Example 1 with DialogNodeCollection

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

the class ConversationServiceIT method testListDialogNodes.

/**
 * Test listDialogNodes.
 */
@Test
public void testListDialogNodes() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add a dialog node and make sure we get it back
        String dialogNodeDescription = "Description of " + dialogNodeName;
        Date start = new Date();
        CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
        service.createDialogNode(createOptions).execute();
        long count = response.getDialogNodes().size();
        ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
        DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getDialogNodes());
        List<DialogNode> dialogNodes = response2.getDialogNodes();
        assertTrue(dialogNodes.size() > count);
        DialogNode dialogResponse = null;
        for (DialogNode node : dialogNodes) {
            if (node.getDialogNodeId().equals(dialogNodeName)) {
                dialogResponse = node;
                break;
            }
        }
        assertNotNull(dialogResponse);
        assertNotNull(dialogResponse.getDescription());
        assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
        Date now = new Date();
        assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
        assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) Test(org.junit.Test)

Example 2 with DialogNodeCollection

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

the class AssistantServiceIT method testListDialogNodes.

/**
 * Test listDialogNodes.
 */
@Test
public void testListDialogNodes() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    try {
        ListDialogNodesOptions listOptions = new ListDialogNodesOptions.Builder(workspaceId).build();
        DialogNodeCollection response = service.listDialogNodes(listOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodes());
        assertNotNull(response.getPagination());
        assertNotNull(response.getPagination().getRefreshUrl());
        // nextUrl may be null
        // Now add a dialog node and make sure we get it back
        String dialogNodeDescription = "Description of " + dialogNodeName;
        Date start = new Date();
        CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
        service.createDialogNode(createOptions).execute();
        long count = response.getDialogNodes().size();
        ListDialogNodesOptions listOptions2 = new ListDialogNodesOptions.Builder(workspaceId).pageLimit(count + 1).includeAudit(true).build();
        DialogNodeCollection response2 = service.listDialogNodes(listOptions2).execute();
        assertNotNull(response2);
        assertNotNull(response2.getDialogNodes());
        List<DialogNode> dialogNodes = response2.getDialogNodes();
        assertTrue(dialogNodes.size() > count);
        DialogNode dialogResponse = null;
        for (DialogNode node : dialogNodes) {
            if (node.getDialogNodeId().equals(dialogNodeName)) {
                dialogResponse = node;
                break;
            }
        }
        assertNotNull(dialogResponse);
        assertNotNull(dialogResponse.getDescription());
        assertEquals(dialogResponse.getDescription(), dialogNodeDescription);
        Date now = new Date();
        assertTrue(fuzzyBefore(dialogResponse.getCreated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getCreated(), start));
        assertTrue(fuzzyBefore(dialogResponse.getUpdated(), now));
        assertTrue(fuzzyAfter(dialogResponse.getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection) DialogNode(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode) Date(java.util.Date) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) Test(org.junit.Test)

Example 3 with DialogNodeCollection

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

the class ConversationServiceIT 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();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 4 with DialogNodeCollection

use of com.ibm.watson.assistant.v1.model.DialogNodeCollection 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();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) ListDialogNodesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 5 with DialogNodeCollection

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

the class Conversation method listDialogNodes.

/**
 * List dialog nodes.
 *
 * List the dialog nodes in the workspace.
 *
 * @param listDialogNodesOptions the {@link ListDialogNodesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNodeCollection}
 */
public ServiceCall<DialogNodeCollection> listDialogNodes(ListDialogNodesOptions listDialogNodesOptions) {
    Validator.notNull(listDialogNodesOptions, "listDialogNodesOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { listDialogNodesOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (listDialogNodesOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listDialogNodesOptions.pageLimit()));
    }
    if (listDialogNodesOptions.includeCount() != null) {
        builder.query("include_count", String.valueOf(listDialogNodesOptions.includeCount()));
    }
    if (listDialogNodesOptions.sort() != null) {
        builder.query("sort", listDialogNodesOptions.sort());
    }
    if (listDialogNodesOptions.cursor() != null) {
        builder.query("cursor", listDialogNodesOptions.cursor());
    }
    if (listDialogNodesOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listDialogNodesOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNodeCollection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) DialogNodeCollection(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection)

Aggregations

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 DialogNodeCollection (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection)3 DialogNodeCollection (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeCollection)3 DialogNodeCollection (com.ibm.watson.assistant.v1.model.DialogNodeCollection)2 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)2 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions)2 ListDialogNodesOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions)2 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions)2 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions)2 ListDialogNodesOptions (com.ibm.watson.developer_cloud.conversation.v1.model.ListDialogNodesOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 Date (java.util.Date)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 ListDialogNodesOptions (com.ibm.watson.assistant.v1.model.ListDialogNodesOptions)1 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)1 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)1 HashMap (java.util.HashMap)1 MockResponse (okhttp3.mockwebserver.MockResponse)1