Search in sources :

Example 6 with CreateDialogNode

use of com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNode 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)

Aggregations

JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)4 HashMap (java.util.HashMap)4 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)2 CreateDialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNode)2 CreateEntity (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntent)2 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)2 CreateDialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNode)2 CreateEntity (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.developer_cloud.conversation.v1.model.CreateIntent)2 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)2 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions)1 UpdateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateWorkspaceOptions)1 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions)1 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateWorkspaceOptions)1 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions)1 UpdateWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateWorkspaceOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1