Search in sources :

Example 6 with DialogNodeCollection

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

the class Assistant method listDialogNodes.

/**
 * List dialog nodes.
 *
 * List the dialog nodes for a workspace. This operation is limited to 2500 requests per 30 minutes. For more
 * information, see **Rate limiting**.
 *
 * @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.assistant.v1.model.DialogNodeCollection)

Example 7 with DialogNodeCollection

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

the class AssistantTest method testListDialogNodesWOptions.

// Test the listDialogNodes operation with a valid options model parameter
@Test
public void testListDialogNodesWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"dialog_nodes\": [{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"video\", \"source\": \"source\", \"title\": \"title\", \"description\": \"description\", \"channels\": [{\"channel\": \"chat\"}], \"channel_options\": {\"mapKey\": \"anyValue\"}, \"alt_text\": \"altText\"}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": true}}, \"context\": {\"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}}, \"metadata\": {\"mapKey\": \"anyValue\"}, \"next_step\": {\"behavior\": \"get_user_input\", \"dialog_node\": \"dialogNode\", \"selector\": \"condition\"}, \"title\": \"title\", \"type\": \"standard\", \"event_name\": \"focus\", \"variable\": \"variable\", \"actions\": [{\"name\": \"name\", \"type\": \"client\", \"parameters\": {\"mapKey\": \"anyValue\"}, \"result_variable\": \"resultVariable\", \"credentials\": \"credentials\"}], \"digress_in\": \"not_available\", \"digress_out\": \"allow_returning\", \"digress_out_slots\": \"not_allowed\", \"user_label\": \"userLabel\", \"disambiguation_opt_out\": false, \"disabled\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
    String listDialogNodesPath = "/v1/workspaces/testString/dialog_nodes";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
    // Construct an instance of the ListDialogNodesOptions model
    ListDialogNodesOptions listDialogNodesOptionsModel = new ListDialogNodesOptions.Builder().workspaceId("testString").pageLimit(Long.valueOf("26")).includeCount(false).sort("dialog_node").cursor("testString").includeAudit(false).build();
    // Invoke listDialogNodes() with a valid options model and verify the result
    Response<DialogNodeCollection> response = assistantService.listDialogNodes(listDialogNodesOptionsModel).execute();
    assertNotNull(response);
    DialogNodeCollection 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, listDialogNodesPath);
    // Verify query params
    Map<String, String> query = TestUtilities.parseQueryString(request);
    assertNotNull(query);
    assertEquals(query.get("version"), "testString");
    assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
    assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
    assertEquals(query.get("sort"), "dialog_node");
    assertEquals(query.get("cursor"), "testString");
    assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) ListDialogNodesOptions(com.ibm.watson.assistant.v1.model.ListDialogNodesOptions) DialogNodeCollection(com.ibm.watson.assistant.v1.model.DialogNodeCollection) Test(org.testng.annotations.Test)

Example 8 with DialogNodeCollection

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

the class Assistant method listDialogNodes.

/**
 * List dialog nodes.
 *
 * <p>List the dialog nodes for a workspace.
 *
 * @param listDialogNodesOptions the {@link ListDialogNodesOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link DialogNodeCollection}
 */
public ServiceCall<DialogNodeCollection> listDialogNodes(ListDialogNodesOptions listDialogNodesOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listDialogNodesOptions, "listDialogNodesOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", listDialogNodesOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/dialog_nodes", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "listDialogNodes");
    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));
    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", String.valueOf(listDialogNodesOptions.sort()));
    }
    if (listDialogNodesOptions.cursor() != null) {
        builder.query("cursor", String.valueOf(listDialogNodesOptions.cursor()));
    }
    if (listDialogNodesOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listDialogNodesOptions.includeAudit()));
    }
    ResponseConverter<DialogNodeCollection> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DialogNodeCollection>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DialogNodeCollection(com.ibm.watson.assistant.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