use of com.ibm.watson.assistant.v1.model.UpdateDialogNode in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateDialogNodeNullableWOptions.
@Test
public void testUpdateDialogNodeNullableWOptions() throws Throwable {
// Schedule some responses.
String mockResponseBody = "{\"dialog_node\": \"dialogNode\", \"description\": \"description\", \"conditions\": \"conditions\", \"parent\": \"parent\", \"previous_sibling\": \"previousSibling\", \"output\": {\"generic\": [{\"response_type\": \"search_skill\", \"query\": \"query\", \"query_type\": \"natural_language\", \"filter\": \"filter\", \"discovery_version\": \"discoveryVersion\", \"channels\": [{\"channel\": \"chat\"}]}], \"integrations\": {\"mapKey\": {\"mapKey\": \"anyValue\"}}, \"modifiers\": {\"overwrite\": false}}, \"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\": true, \"disabled\": true, \"created\": \"2019-01-01T12:00:00\", \"updated\": \"2019-01-01T12:00:00\"}";
String updateDialogNodeNullablePath = "/v1/workspaces/testString/dialog_nodes/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
constructClientService();
// Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill
// model
DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill dialogNodeOutputGenericModel = new DialogNodeOutputGenericDialogNodeOutputResponseTypeSearchSkill.Builder().responseType("search_skill").query("testString").queryType("natural_language").filter("testString").discoveryVersion("testString").build();
// Construct an instance of the DialogNodeOutputModifiers model
DialogNodeOutputModifiers dialogNodeOutputModifiersModel = new DialogNodeOutputModifiers.Builder().overwrite(true).build();
// Construct an instance of the DialogNodeOutput model
DialogNodeOutput dialogNodeOutputModel = new DialogNodeOutput.Builder().generic(new java.util.ArrayList<DialogNodeOutputGeneric>(java.util.Arrays.asList(dialogNodeOutputGenericModel))).integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).modifiers(dialogNodeOutputModifiersModel).add("foo", "testString").build();
// Construct an instance of the DialogNodeContext model
DialogNodeContext dialogNodeContextModel = new DialogNodeContext.Builder().integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).add("foo", "testString").build();
// Construct an instance of the DialogNodeNextStep model
DialogNodeNextStep dialogNodeNextStepModel = new DialogNodeNextStep.Builder().behavior("get_user_input").dialogNode("testString").selector("condition").build();
// Construct an instance of the DialogNodeAction model
DialogNodeAction dialogNodeActionModel = new DialogNodeAction.Builder().name("testString").type("client").parameters(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).resultVariable("testString").credentials("testString").build();
// Construct an instance of the UpdateDialogNode model
UpdateDialogNode updateDialogNodeModel = new UpdateDialogNode.Builder().dialogNode("testString").description("testString").conditions("testString").parent("testString").previousSibling("testString").output(dialogNodeOutputModel).context(dialogNodeContextModel).metadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).nextStep(dialogNodeNextStepModel).title("testString").type("standard").eventName("focus").variable("testString").actions(new java.util.ArrayList<DialogNodeAction>(java.util.Arrays.asList(dialogNodeActionModel))).digressIn("not_available").digressOut("allow_returning").digressOutSlots("not_allowed").userLabel("testString").disambiguationOptOut(true).build();
Map<String, Object> updateDialogNodeModelAsPatch = updateDialogNodeModel.asPatch();
// Construct an instance of the UpdateDialogNodeNullableOptions model
UpdateDialogNodeNullableOptions updateDialogNodeNullableOptionsModel = new UpdateDialogNodeNullableOptions.Builder().workspaceId("testString").dialogNode("testString").body(updateDialogNodeModelAsPatch).includeAudit(true).build();
// Invoke operation with valid options model (positive test)
Response<DialogNode> response = assistantService.updateDialogNodeNullable(updateDialogNodeNullableOptionsModel).execute();
assertNotNull(response);
DialogNode responseObj = response.getResult();
assertNotNull(responseObj);
// Verify the contents of the request
RecordedRequest request = server.takeRequest();
assertNotNull(request);
assertEquals(request.getMethod(), "POST");
// Check query
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
// Get query params
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(true));
// Check request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateDialogNodeNullablePath);
}
use of com.ibm.watson.assistant.v1.model.UpdateDialogNode 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.UpdateDialogNode in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateDialogNodeWOptions.
// Test the updateDialogNode operation with a valid options model parameter
@Test
public void testUpdateDialogNodeWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"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\"}";
String updateDialogNodePath = "/v1/workspaces/testString/dialog_nodes/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ResponseGenericChannel model
ResponseGenericChannel responseGenericChannelModel = new ResponseGenericChannel.Builder().channel("chat").build();
// Construct an instance of the DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo model
DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo dialogNodeOutputGenericModel = new DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo.Builder().responseType("video").source("testString").title("testString").description("testString").channels(new java.util.ArrayList<ResponseGenericChannel>(java.util.Arrays.asList(responseGenericChannelModel))).channelOptions(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).altText("testString").build();
// Construct an instance of the DialogNodeOutputModifiers model
DialogNodeOutputModifiers dialogNodeOutputModifiersModel = new DialogNodeOutputModifiers.Builder().overwrite(true).build();
// Construct an instance of the DialogNodeOutput model
DialogNodeOutput dialogNodeOutputModel = new DialogNodeOutput.Builder().generic(new java.util.ArrayList<DialogNodeOutputGeneric>(java.util.Arrays.asList(dialogNodeOutputGenericModel))).integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).modifiers(dialogNodeOutputModifiersModel).add("foo", "testString").build();
// Construct an instance of the DialogNodeContext model
DialogNodeContext dialogNodeContextModel = new DialogNodeContext.Builder().integrations(new java.util.HashMap<String, Map<String, Object>>() {
{
put("foo", new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
});
}
}).add("foo", "testString").build();
// Construct an instance of the DialogNodeNextStep model
DialogNodeNextStep dialogNodeNextStepModel = new DialogNodeNextStep.Builder().behavior("get_user_input").dialogNode("testString").selector("condition").build();
// Construct an instance of the DialogNodeAction model
DialogNodeAction dialogNodeActionModel = new DialogNodeAction.Builder().name("testString").type("client").parameters(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).resultVariable("testString").credentials("testString").build();
// Construct an instance of the UpdateDialogNodeOptions model
UpdateDialogNodeOptions updateDialogNodeOptionsModel = new UpdateDialogNodeOptions.Builder().workspaceId("testString").dialogNode("testString").newDialogNode("testString").newDescription("testString").newConditions("testString").newParent("testString").newPreviousSibling("testString").newOutput(dialogNodeOutputModel).newContext(dialogNodeContextModel).newMetadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).newNextStep(dialogNodeNextStepModel).newTitle("testString").newType("standard").newEventName("focus").newVariable("testString").newActions(new java.util.ArrayList<DialogNodeAction>(java.util.Arrays.asList(dialogNodeActionModel))).newDigressIn("not_available").newDigressOut("allow_returning").newDigressOutSlots("not_allowed").newUserLabel("testString").newDisambiguationOptOut(false).includeAudit(false).build();
// Invoke updateDialogNode() with a valid options model and verify the result
Response<DialogNode> response = assistantService.updateDialogNode(updateDialogNodeOptionsModel).execute();
assertNotNull(response);
DialogNode 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(), "POST");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, updateDialogNodePath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
Aggregations