use of com.ibm.watson.assistant.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();
}
}
use of com.ibm.watson.assistant.v1.model.UpdateDialogNodeOptions in project java-sdk by watson-developer-cloud.
the class Assistant method updateDialogNode.
/**
* Update dialog node.
*
* <p>Update an existing dialog node with new or modified data.
*
* <p>If you want to update multiple dialog nodes with a single API call, consider using the
* **[Update workspace](#update-workspace)** method instead.
*
* @param updateDialogNodeOptions the {@link UpdateDialogNodeOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link DialogNode}
*/
public ServiceCall<DialogNode> updateDialogNode(UpdateDialogNodeOptions updateDialogNodeOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateDialogNodeOptions, "updateDialogNodeOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", updateDialogNodeOptions.workspaceId());
pathParamsMap.put("dialog_node", updateDialogNodeOptions.dialogNode());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/dialog_nodes/{dialog_node}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateDialogNode");
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 (updateDialogNodeOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(updateDialogNodeOptions.includeAudit()));
}
final JsonObject contentJson = new JsonObject();
if (updateDialogNodeOptions.newDialogNode() != null) {
contentJson.addProperty("dialog_node", updateDialogNodeOptions.newDialogNode());
}
if (updateDialogNodeOptions.newDescription() != null) {
contentJson.addProperty("description", updateDialogNodeOptions.newDescription());
}
if (updateDialogNodeOptions.newConditions() != null) {
contentJson.addProperty("conditions", updateDialogNodeOptions.newConditions());
}
if (updateDialogNodeOptions.newParent() != null) {
contentJson.addProperty("parent", updateDialogNodeOptions.newParent());
}
if (updateDialogNodeOptions.newPreviousSibling() != null) {
contentJson.addProperty("previous_sibling", updateDialogNodeOptions.newPreviousSibling());
}
if (updateDialogNodeOptions.newOutput() != null) {
contentJson.add("output", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newOutput()));
}
if (updateDialogNodeOptions.newContext() != null) {
contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newContext()));
}
if (updateDialogNodeOptions.newMetadata() != null) {
contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newMetadata()));
}
if (updateDialogNodeOptions.newNextStep() != null) {
contentJson.add("next_step", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newNextStep()));
}
if (updateDialogNodeOptions.newTitle() != null) {
contentJson.addProperty("title", updateDialogNodeOptions.newTitle());
}
if (updateDialogNodeOptions.newType() != null) {
contentJson.addProperty("type", updateDialogNodeOptions.newType());
}
if (updateDialogNodeOptions.newEventName() != null) {
contentJson.addProperty("event_name", updateDialogNodeOptions.newEventName());
}
if (updateDialogNodeOptions.newVariable() != null) {
contentJson.addProperty("variable", updateDialogNodeOptions.newVariable());
}
if (updateDialogNodeOptions.newActions() != null) {
contentJson.add("actions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateDialogNodeOptions.newActions()));
}
if (updateDialogNodeOptions.newDigressIn() != null) {
contentJson.addProperty("digress_in", updateDialogNodeOptions.newDigressIn());
}
if (updateDialogNodeOptions.newDigressOut() != null) {
contentJson.addProperty("digress_out", updateDialogNodeOptions.newDigressOut());
}
if (updateDialogNodeOptions.newDigressOutSlots() != null) {
contentJson.addProperty("digress_out_slots", updateDialogNodeOptions.newDigressOutSlots());
}
if (updateDialogNodeOptions.newUserLabel() != null) {
contentJson.addProperty("user_label", updateDialogNodeOptions.newUserLabel());
}
if (updateDialogNodeOptions.newDisambiguationOptOut() != null) {
contentJson.addProperty("disambiguation_opt_out", updateDialogNodeOptions.newDisambiguationOptOut());
}
builder.bodyJson(contentJson);
ResponseConverter<DialogNode> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<DialogNode>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
use of com.ibm.watson.assistant.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();
}
}
use of com.ibm.watson.assistant.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);
}
use of com.ibm.watson.assistant.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");
}
Aggregations