Search in sources :

Example 11 with DialogNode

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

the class AssistantTest method testCreateDialogNodeOptionsBuilder.

/**
 * Test CreateDialogNodeOptions builder.
 */
@Test
public void testCreateDialogNodeOptionsBuilder() {
    String dialogNodeName = "aDialogNode";
    DialogNodeAction action0 = new DialogNodeAction();
    action0.setName("action0");
    action0.setCredentials("credential0");
    DialogNodeAction action1 = new DialogNodeAction();
    action1.setName("action1");
    action1.setCredentials("credential1");
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder().workspaceId(WORKSPACE_ID).dialogNode(dialogNodeName).addActions(action0).addActions(action1).digressIn(CreateDialogNodeOptions.DigressIn.RETURNS).digressOut(CreateDialogNodeOptions.DigressOut.ALLOW_ALL).digressOutSlots(CreateDialogNodeOptions.DigressOutSlots.ALLOW_ALL).build();
    assertEquals(createOptions.workspaceId(), WORKSPACE_ID);
    assertEquals(createOptions.dialogNode(), dialogNodeName);
    assertEquals(createOptions.actions().size(), 2);
    assertEquals(createOptions.actions().get(0), action0);
    assertEquals(createOptions.actions().get(0).getCredentials(), "credential0");
    assertEquals(createOptions.actions().get(1), action1);
    assertEquals(createOptions.actions().get(1).getCredentials(), "credential1");
    assertEquals(createOptions.digressIn(), CreateDialogNodeOptions.DigressIn.RETURNS);
    assertEquals(createOptions.digressOut(), CreateDialogNodeOptions.DigressOut.ALLOW_ALL);
    assertEquals(createOptions.digressOutSlots(), CreateDialogNodeOptions.DigressOutSlots.ALLOW_ALL);
}
Also used : DialogNodeAction(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeAction) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 12 with DialogNode

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

the class ConversationServiceIT method testCreateDialogNode.

/**
 * Test createDialogNode.
 */
@Test
public void testCreateDialogNode() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    String dialogNodeDescription = "Description of " + dialogNodeName;
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
    DialogNode response = service.createDialogNode(createOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getDialogNodeId());
        assertEquals(response.getDialogNodeId(), dialogNodeName);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), dialogNodeDescription);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName).build();
        service.deleteDialogNode(deleteOptions).execute();
    }
}
Also used : DeleteDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions) CreateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 13 with DialogNode

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

the class Conversation method createDialogNode.

/**
 * Create dialog node.
 *
 * Create a dialog node.
 *
 * @param createDialogNodeOptions the {@link CreateDialogNodeOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNode}
 */
public ServiceCall<DialogNode> createDialogNode(CreateDialogNodeOptions createDialogNodeOptions) {
    Validator.notNull(createDialogNodeOptions, "createDialogNodeOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { createDialogNodeOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("dialog_node", createDialogNodeOptions.dialogNode());
    if (createDialogNodeOptions.description() != null) {
        contentJson.addProperty("description", createDialogNodeOptions.description());
    }
    if (createDialogNodeOptions.conditions() != null) {
        contentJson.addProperty("conditions", createDialogNodeOptions.conditions());
    }
    if (createDialogNodeOptions.parent() != null) {
        contentJson.addProperty("parent", createDialogNodeOptions.parent());
    }
    if (createDialogNodeOptions.previousSibling() != null) {
        contentJson.addProperty("previous_sibling", createDialogNodeOptions.previousSibling());
    }
    if (createDialogNodeOptions.output() != null) {
        contentJson.add("output", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.output()));
    }
    if (createDialogNodeOptions.context() != null) {
        contentJson.add("context", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.context()));
    }
    if (createDialogNodeOptions.metadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.metadata()));
    }
    if (createDialogNodeOptions.nextStep() != null) {
        contentJson.add("next_step", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.nextStep()));
    }
    if (createDialogNodeOptions.actions() != null) {
        contentJson.add("actions", GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.actions()));
    }
    if (createDialogNodeOptions.title() != null) {
        contentJson.addProperty("title", createDialogNodeOptions.title());
    }
    if (createDialogNodeOptions.nodeType() != null) {
        contentJson.addProperty("type", createDialogNodeOptions.nodeType());
    }
    if (createDialogNodeOptions.eventName() != null) {
        contentJson.addProperty("event_name", createDialogNodeOptions.eventName());
    }
    if (createDialogNodeOptions.variable() != null) {
        contentJson.addProperty("variable", createDialogNodeOptions.variable());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)

Example 14 with DialogNode

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

the class Conversation method updateDialogNode.

/**
 * Update dialog node.
 *
 * Update information for a dialog node.
 *
 * @param updateDialogNodeOptions the {@link UpdateDialogNodeOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNode}
 */
public ServiceCall<DialogNode> updateDialogNode(UpdateDialogNodeOptions updateDialogNodeOptions) {
    Validator.notNull(updateDialogNodeOptions, "updateDialogNodeOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { updateDialogNodeOptions.workspaceId(), updateDialogNodeOptions.dialogNode() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateDialogNodeOptions.nodeType() != null) {
        contentJson.addProperty("type", updateDialogNodeOptions.nodeType());
    }
    if (updateDialogNodeOptions.newActions() != null) {
        contentJson.add("actions", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newActions()));
    }
    if (updateDialogNodeOptions.newConditions() != null) {
        contentJson.addProperty("conditions", updateDialogNodeOptions.newConditions());
    }
    if (updateDialogNodeOptions.newContext() != null) {
        contentJson.add("context", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newContext()));
    }
    if (updateDialogNodeOptions.newPreviousSibling() != null) {
        contentJson.addProperty("previous_sibling", updateDialogNodeOptions.newPreviousSibling());
    }
    if (updateDialogNodeOptions.newVariable() != null) {
        contentJson.addProperty("variable", updateDialogNodeOptions.newVariable());
    }
    if (updateDialogNodeOptions.newMetadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newMetadata()));
    }
    if (updateDialogNodeOptions.newTitle() != null) {
        contentJson.addProperty("title", updateDialogNodeOptions.newTitle());
    }
    if (updateDialogNodeOptions.newDescription() != null) {
        contentJson.addProperty("description", updateDialogNodeOptions.newDescription());
    }
    if (updateDialogNodeOptions.newEventName() != null) {
        contentJson.addProperty("event_name", updateDialogNodeOptions.newEventName());
    }
    if (updateDialogNodeOptions.newNextStep() != null) {
        contentJson.add("next_step", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newNextStep()));
    }
    if (updateDialogNodeOptions.newOutput() != null) {
        contentJson.add("output", GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newOutput()));
    }
    if (updateDialogNodeOptions.newParent() != null) {
        contentJson.addProperty("parent", updateDialogNodeOptions.newParent());
    }
    if (updateDialogNodeOptions.newDialogNode() != null) {
        contentJson.addProperty("dialog_node", updateDialogNodeOptions.newDialogNode());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) DialogNode(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)

Example 15 with DialogNode

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

the class Assistant method getDialogNode.

/**
 * Get dialog node.
 *
 * Get information about a dialog node. This operation is limited to 6000 requests per 5 minutes. For more
 * information, see **Rate limiting**.
 *
 * @param getDialogNodeOptions the {@link GetDialogNodeOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNode}
 */
public ServiceCall<DialogNode> getDialogNode(GetDialogNodeOptions getDialogNodeOptions) {
    Validator.notNull(getDialogNodeOptions, "getDialogNodeOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { getDialogNodeOptions.workspaceId(), getDialogNodeOptions.dialogNode() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getDialogNodeOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getDialogNodeOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNode.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) DialogNode(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)

Aggregations

Test (org.junit.Test)12 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)9 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)9 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)7 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)7 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)6 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)6 JsonObject (com.google.gson.JsonObject)5 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions)5 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions)4 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions)4 Date (java.util.Date)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)3 DialogNodeAction (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeAction)2 DialogNodeCollection (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection)2 ListDialogNodesOptions (com.ibm.watson.developer_cloud.assistant.v1.model.ListDialogNodesOptions)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions)2 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)1 CreateDialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNode)1 CreateEntity (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity)1