Search in sources :

Example 1 with UpdateDialogNodeOptions

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

the class ConversationServiceIT method testUpdateDialogNode.

/**
 * Test updateDialogNode.
 */
@Test
public void testUpdateDialogNode() {
    String dialogNodeName = "Test" + UUID.randomUUID().toString();
    String dialogNodeDescription = "Description of " + dialogNodeName;
    CreateDialogNodeOptions createOptions = new CreateDialogNodeOptions.Builder(workspaceId, dialogNodeName).description(dialogNodeDescription).build();
    service.createDialogNode(createOptions).execute();
    String dialogNodeName2 = "Test2" + UUID.randomUUID().toString();
    try {
        String dialogNodeDescription2 = "Updated description of " + dialogNodeName;
        UpdateDialogNodeOptions updateOptions = new UpdateDialogNodeOptions.Builder().workspaceId(workspaceId).dialogNode(dialogNodeName).newDialogNode(dialogNodeName2).newDescription(dialogNodeDescription2).build();
        DialogNode response = service.updateDialogNode(updateOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getDialogNodeId());
        assertEquals(response.getDialogNodeId(), dialogNodeName2);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), dialogNodeDescription2);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteDialogNodeOptions deleteOptions = new DeleteDialogNodeOptions.Builder(workspaceId, dialogNodeName2).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) UpdateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateDialogNodeOptions) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Test(org.junit.Test)

Example 2 with UpdateDialogNodeOptions

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

the class AssistantServiceIT method testUpdateDialogNode.

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

Example 3 with UpdateDialogNodeOptions

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

the class AssistantTest method testUpdateDialogNodeOptionsBuilder.

/**
 * Test UpdateDialogNodeOptions builder.
 */
@Test
public void testUpdateDialogNodeOptionsBuilder() {
    String dialogNodeName = "aDialogNode";
    String newDialogNodeName = "renamedDialogNode";
    DialogNodeAction action0 = new DialogNodeAction();
    action0.setName("action0");
    action0.setCredentials("credential0");
    DialogNodeAction action1 = new DialogNodeAction();
    action1.setName("action1");
    action1.setCredentials("credential1");
    UpdateDialogNodeOptions updateOptions = new UpdateDialogNodeOptions.Builder().workspaceId(WORKSPACE_ID).dialogNode(dialogNodeName).newDialogNode(newDialogNodeName).addNewActions(action0).addNewActions(action1).newDigressIn(UpdateDialogNodeOptions.NewDigressIn.RETURNS).newDigressOut(UpdateDialogNodeOptions.NewDigressOut.ALLOW_ALL).newDigressOutSlots(UpdateDialogNodeOptions.NewDigressOutSlots.ALLOW_ALL).build();
    assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
    assertEquals(updateOptions.dialogNode(), dialogNodeName);
    assertEquals(updateOptions.newActions().size(), 2);
    assertEquals(updateOptions.newActions().get(0), action0);
    assertEquals(updateOptions.newActions().get(0).getCredentials(), "credential0");
    assertEquals(updateOptions.newActions().get(1), action1);
    assertEquals(updateOptions.newActions().get(1).getCredentials(), "credential1");
    assertEquals(updateOptions.newDigressIn(), UpdateDialogNodeOptions.NewDigressIn.RETURNS);
    assertEquals(updateOptions.newDigressOut(), UpdateDialogNodeOptions.NewDigressOut.ALLOW_ALL);
    assertEquals(updateOptions.newDigressOutSlots(), UpdateDialogNodeOptions.NewDigressOutSlots.ALLOW_ALL);
}
Also used : DialogNodeAction(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeAction) UpdateDialogNodeOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 4 with UpdateDialogNodeOptions

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

the class ConversationTest method testUpdateDialogNodeOptionsBuilder.

/**
 * Test UpdateDialogNodeOptions builder.
 */
@Test
public void testUpdateDialogNodeOptionsBuilder() {
    String dialogNodeName = "aDialogNode";
    String newDialogNodeName = "renamedDialogNode";
    DialogNodeAction action0 = new DialogNodeAction();
    action0.setName("action0");
    action0.setCredentials("credential0");
    DialogNodeAction action1 = new DialogNodeAction();
    action1.setName("action1");
    action1.setCredentials("credential1");
    UpdateDialogNodeOptions updateOptions = new UpdateDialogNodeOptions.Builder().workspaceId(WORKSPACE_ID).dialogNode(dialogNodeName).newDialogNode(newDialogNodeName).addNewActions(action0).addNewActions(action1).build();
    assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
    assertEquals(updateOptions.dialogNode(), dialogNodeName);
    assertEquals(updateOptions.newActions().size(), 2);
    assertEquals(updateOptions.newActions().get(0), action0);
    assertEquals(updateOptions.newActions().get(0).getCredentials(), "credential0");
    assertEquals(updateOptions.newActions().get(1), action1);
    assertEquals(updateOptions.newActions().get(1).getCredentials(), "credential1");
}
Also used : DialogNodeAction(com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeAction) UpdateDialogNodeOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateDialogNodeOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 5 with UpdateDialogNodeOptions

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

Aggregations

Test (org.junit.Test)4 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateDialogNodeOptions)2 DialogNode (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNode)2 UpdateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateDialogNodeOptions)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 JsonObject (com.google.gson.JsonObject)1 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateDialogNodeOptions)1 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteDialogNodeOptions)1 DialogNode (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNode)1 DialogNodeAction (com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeAction)1 CreateDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateDialogNodeOptions)1 DeleteDialogNodeOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteDialogNodeOptions)1 DialogNodeAction (com.ibm.watson.developer_cloud.conversation.v1.model.DialogNodeAction)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1