use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class AssistantTest method testListWorkspacesWOptions.
// Test the listWorkspaces operation with a valid options model parameter
@Test
public void testListWorkspacesWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"workspaces\": [{\"name\": \"name\", \"description\": \"description\", \"language\": \"language\", \"workspace_id\": \"workspaceId\", \"dialog_nodes\": [{\"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\"}], \"counterexamples\": [{\"text\": \"text\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"learning_opt_out\": false, \"system_settings\": {\"tooling\": {\"store_generic_responses\": false}, \"disambiguation\": {\"prompt\": \"prompt\", \"none_of_the_above_prompt\": \"noneOfTheAbovePrompt\", \"enabled\": false, \"sensitivity\": \"auto\", \"randomize\": false, \"max_suggestions\": 1, \"suggestion_text_policy\": \"suggestionTextPolicy\"}, \"human_agent_assist\": {\"mapKey\": \"anyValue\"}, \"spelling_suggestions\": false, \"spelling_auto_correct\": false, \"system_entities\": {\"enabled\": false}, \"off_topic\": {\"enabled\": false}}, \"status\": \"Non Existent\", \"webhooks\": [{\"url\": \"url\", \"name\": \"name\", \"headers\": [{\"name\": \"name\", \"value\": \"value\"}]}], \"intents\": [{\"intent\": \"intent\", \"description\": \"description\", \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"examples\": [{\"text\": \"text\", \"mentions\": [{\"entity\": \"entity\", \"location\": [8]}], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}], \"entities\": [{\"entity\": \"entity\", \"description\": \"description\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"fuzzy_match\": true, \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\", \"values\": [{\"value\": \"value\", \"metadata\": {\"mapKey\": \"anyValue\"}, \"type\": \"synonyms\", \"synonyms\": [\"synonym\"], \"patterns\": [\"pattern\"], \"created\": \"2019-01-01T12:00:00.000Z\", \"updated\": \"2019-01-01T12:00:00.000Z\"}]}]}], \"pagination\": {\"refresh_url\": \"refreshUrl\", \"next_url\": \"nextUrl\", \"total\": 5, \"matched\": 7, \"refresh_cursor\": \"refreshCursor\", \"next_cursor\": \"nextCursor\"}}";
String listWorkspacesPath = "/v1/workspaces";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// Construct an instance of the ListWorkspacesOptions model
ListWorkspacesOptions listWorkspacesOptionsModel = new ListWorkspacesOptions.Builder().pageLimit(Long.valueOf("26")).includeCount(false).sort("name").cursor("testString").includeAudit(false).build();
// Invoke listWorkspaces() with a valid options model and verify the result
Response<WorkspaceCollection> response = assistantService.listWorkspaces(listWorkspacesOptionsModel).execute();
assertNotNull(response);
WorkspaceCollection 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(), "GET");
// Verify request path
String parsedPath = TestUtilities.parseReqPath(request);
assertEquals(parsedPath, listWorkspacesPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Long.valueOf(query.get("page_limit")), Long.valueOf("26"));
assertEquals(Boolean.valueOf(query.get("include_count")), Boolean.valueOf(false));
assertEquals(query.get("sort"), "name");
assertEquals(query.get("cursor"), "testString");
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.DialogNode in project java-sdk by watson-developer-cloud.
the class Assistant method createDialogNode.
/**
* Create dialog node.
*
* <p>Create a new dialog node.
*
* <p>If you want to create multiple dialog nodes with a single API call, consider using the
* **[Update workspace](#update-workspace)** method instead.
*
* @param createDialogNodeOptions the {@link CreateDialogNodeOptions} containing the options for
* the call
* @return a {@link ServiceCall} with a result of type {@link DialogNode}
*/
public ServiceCall<DialogNode> createDialogNode(CreateDialogNodeOptions createDialogNodeOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(createDialogNodeOptions, "createDialogNodeOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", createDialogNodeOptions.workspaceId());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/dialog_nodes", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createDialogNode");
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 (createDialogNodeOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(createDialogNodeOptions.includeAudit()));
}
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", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.output()));
}
if (createDialogNodeOptions.context() != null) {
contentJson.add("context", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.context()));
}
if (createDialogNodeOptions.metadata() != null) {
contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.metadata()));
}
if (createDialogNodeOptions.nextStep() != null) {
contentJson.add("next_step", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.nextStep()));
}
if (createDialogNodeOptions.title() != null) {
contentJson.addProperty("title", createDialogNodeOptions.title());
}
if (createDialogNodeOptions.type() != null) {
contentJson.addProperty("type", createDialogNodeOptions.type());
}
if (createDialogNodeOptions.eventName() != null) {
contentJson.addProperty("event_name", createDialogNodeOptions.eventName());
}
if (createDialogNodeOptions.variable() != null) {
contentJson.addProperty("variable", createDialogNodeOptions.variable());
}
if (createDialogNodeOptions.actions() != null) {
contentJson.add("actions", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createDialogNodeOptions.actions()));
}
if (createDialogNodeOptions.digressIn() != null) {
contentJson.addProperty("digress_in", createDialogNodeOptions.digressIn());
}
if (createDialogNodeOptions.digressOut() != null) {
contentJson.addProperty("digress_out", createDialogNodeOptions.digressOut());
}
if (createDialogNodeOptions.digressOutSlots() != null) {
contentJson.addProperty("digress_out_slots", createDialogNodeOptions.digressOutSlots());
}
if (createDialogNodeOptions.userLabel() != null) {
contentJson.addProperty("user_label", createDialogNodeOptions.userLabel());
}
if (createDialogNodeOptions.disambiguationOptOut() != null) {
contentJson.addProperty("disambiguation_opt_out", createDialogNodeOptions.disambiguationOptOut());
}
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.DialogNode in project java-sdk by watson-developer-cloud.
the class Assistant method updateDialogNodeNullable.
/**
* 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 UpdateDialogNodeNullableOptions the {@link UpdateDialogNodeNullableOptions} containing
* the options for the call
* @return a {@link ServiceCall} with a result of type {@link DialogNode}
*/
public ServiceCall<DialogNode> updateDialogNodeNullable(UpdateDialogNodeNullableOptions UpdateDialogNodeNullableOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(UpdateDialogNodeNullableOptions, "UpdateDialogNodeNullableOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", UpdateDialogNodeNullableOptions.workspaceId());
pathParamsMap.put("dialog_node", UpdateDialogNodeNullableOptions.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", "testUpdateDialogNode");
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 (UpdateDialogNodeNullableOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(UpdateDialogNodeNullableOptions.includeAudit()));
}
builder.bodyContent(com.ibm.cloud.sdk.core.util.GsonSingleton.getGsonWithSerializeNulls().toJson(UpdateDialogNodeNullableOptions.body()), "application/json");
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.DialogNode 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.DialogNode 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();
}
}
Aggregations