Search in sources :

Example 6 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class AssistantTest method testCreateWorkspaceWOptions.

// Test the createWorkspace operation with a valid options model parameter
@Test
public void testCreateWorkspaceWOptions() throws Throwable {
    // Register a mock response
    String mockResponseBody = "{\"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\"}]}]}";
    String createWorkspacePath = "/v1/workspaces";
    server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(201).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 DialogNode model
    DialogNode dialogNodeModel = new DialogNode.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(false).build();
    // Construct an instance of the Counterexample model
    Counterexample counterexampleModel = new Counterexample.Builder().text("testString").build();
    // Construct an instance of the WorkspaceSystemSettingsTooling model
    WorkspaceSystemSettingsTooling workspaceSystemSettingsToolingModel = new WorkspaceSystemSettingsTooling.Builder().storeGenericResponses(true).build();
    // Construct an instance of the WorkspaceSystemSettingsDisambiguation model
    WorkspaceSystemSettingsDisambiguation workspaceSystemSettingsDisambiguationModel = new WorkspaceSystemSettingsDisambiguation.Builder().prompt("testString").noneOfTheAbovePrompt("testString").enabled(false).sensitivity("auto").randomize(true).maxSuggestions(Long.valueOf("1")).suggestionTextPolicy("testString").build();
    // Construct an instance of the WorkspaceSystemSettingsSystemEntities model
    WorkspaceSystemSettingsSystemEntities workspaceSystemSettingsSystemEntitiesModel = new WorkspaceSystemSettingsSystemEntities.Builder().enabled(false).build();
    // Construct an instance of the WorkspaceSystemSettingsOffTopic model
    WorkspaceSystemSettingsOffTopic workspaceSystemSettingsOffTopicModel = new WorkspaceSystemSettingsOffTopic.Builder().enabled(false).build();
    // Construct an instance of the WorkspaceSystemSettings model
    WorkspaceSystemSettings workspaceSystemSettingsModel = new WorkspaceSystemSettings.Builder().tooling(workspaceSystemSettingsToolingModel).disambiguation(workspaceSystemSettingsDisambiguationModel).humanAgentAssist(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).spellingSuggestions(false).spellingAutoCorrect(false).systemEntities(workspaceSystemSettingsSystemEntitiesModel).offTopic(workspaceSystemSettingsOffTopicModel).add("foo", "testString").build();
    // Construct an instance of the WebhookHeader model
    WebhookHeader webhookHeaderModel = new WebhookHeader.Builder().name("testString").value("testString").build();
    // Construct an instance of the Webhook model
    Webhook webhookModel = new Webhook.Builder().url("testString").name("testString").headers(new java.util.ArrayList<WebhookHeader>(java.util.Arrays.asList(webhookHeaderModel))).build();
    // Construct an instance of the Mention model
    Mention mentionModel = new Mention.Builder().entity("testString").location(new java.util.ArrayList<Long>(java.util.Arrays.asList(Long.valueOf("26")))).build();
    // Construct an instance of the Example model
    Example exampleModel = new Example.Builder().text("testString").mentions(new java.util.ArrayList<Mention>(java.util.Arrays.asList(mentionModel))).build();
    // Construct an instance of the CreateIntent model
    CreateIntent createIntentModel = new CreateIntent.Builder().intent("testString").description("testString").examples(new java.util.ArrayList<Example>(java.util.Arrays.asList(exampleModel))).build();
    // Construct an instance of the CreateValue model
    CreateValue createValueModel = new CreateValue.Builder().value("testString").metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).type("synonyms").synonyms(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).patterns(new java.util.ArrayList<String>(java.util.Arrays.asList("testString"))).build();
    // Construct an instance of the CreateEntity model
    CreateEntity createEntityModel = new CreateEntity.Builder().entity("testString").description("testString").metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).fuzzyMatch(true).values(new java.util.ArrayList<CreateValue>(java.util.Arrays.asList(createValueModel))).build();
    // Construct an instance of the CreateWorkspaceOptions model
    CreateWorkspaceOptions createWorkspaceOptionsModel = new CreateWorkspaceOptions.Builder().name("testString").description("testString").language("testString").dialogNodes(new java.util.ArrayList<DialogNode>(java.util.Arrays.asList(dialogNodeModel))).counterexamples(new java.util.ArrayList<Counterexample>(java.util.Arrays.asList(counterexampleModel))).metadata(new java.util.HashMap<String, Object>() {

        {
            put("foo", "testString");
        }
    }).learningOptOut(false).systemSettings(workspaceSystemSettingsModel).webhooks(new java.util.ArrayList<Webhook>(java.util.Arrays.asList(webhookModel))).intents(new java.util.ArrayList<CreateIntent>(java.util.Arrays.asList(createIntentModel))).entities(new java.util.ArrayList<CreateEntity>(java.util.Arrays.asList(createEntityModel))).includeAudit(false).build();
    // Invoke createWorkspace() with a valid options model and verify the result
    Response<Workspace> response = assistantService.createWorkspace(createWorkspaceOptionsModel).execute();
    assertNotNull(response);
    Workspace 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, createWorkspacePath);
    // 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));
}
Also used : DialogNodeOutputGeneric(com.ibm.watson.assistant.v1.model.DialogNodeOutputGeneric) CreateEntity(com.ibm.watson.assistant.v1.model.CreateEntity) HashMap(java.util.HashMap) Counterexample(com.ibm.watson.assistant.v1.model.Counterexample) Mention(com.ibm.watson.assistant.v1.model.Mention) Example(com.ibm.watson.assistant.v1.model.Example) CreateWorkspaceOptions(com.ibm.watson.assistant.v1.model.CreateWorkspaceOptions) DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo(com.ibm.watson.assistant.v1.model.DialogNodeOutputGenericDialogNodeOutputResponseTypeVideo) MockResponse(okhttp3.mockwebserver.MockResponse) CreateIntent(com.ibm.watson.assistant.v1.model.CreateIntent) DialogNodeContext(com.ibm.watson.assistant.v1.model.DialogNodeContext) WorkspaceSystemSettingsTooling(com.ibm.watson.assistant.v1.model.WorkspaceSystemSettingsTooling) Map(java.util.Map) HashMap(java.util.HashMap) CreateValue(com.ibm.watson.assistant.v1.model.CreateValue) ResponseGenericChannel(com.ibm.watson.assistant.v1.model.ResponseGenericChannel) DialogNode(com.ibm.watson.assistant.v1.model.DialogNode) WorkspaceSystemSettings(com.ibm.watson.assistant.v1.model.WorkspaceSystemSettings) DialogNodeOutput(com.ibm.watson.assistant.v1.model.DialogNodeOutput) DialogNodeNextStep(com.ibm.watson.assistant.v1.model.DialogNodeNextStep) DialogNodeOutputModifiers(com.ibm.watson.assistant.v1.model.DialogNodeOutputModifiers) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) WorkspaceSystemSettingsDisambiguation(com.ibm.watson.assistant.v1.model.WorkspaceSystemSettingsDisambiguation) DialogNodeAction(com.ibm.watson.assistant.v1.model.DialogNodeAction) WebhookHeader(com.ibm.watson.assistant.v1.model.WebhookHeader) WorkspaceSystemSettingsSystemEntities(com.ibm.watson.assistant.v1.model.WorkspaceSystemSettingsSystemEntities) WorkspaceSystemSettingsOffTopic(com.ibm.watson.assistant.v1.model.WorkspaceSystemSettingsOffTopic) Webhook(com.ibm.watson.assistant.v1.model.Webhook) Workspace(com.ibm.watson.assistant.v1.model.Workspace) Test(org.testng.annotations.Test)

Example 7 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) DialogNode(com.ibm.watson.assistant.v1.model.DialogNode)

Example 8 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method getWorkspace.

/**
 * Get information about a workspace.
 *
 * <p>Get information about a workspace, optionally including all workspace content.
 *
 * @param getWorkspaceOptions the {@link GetWorkspaceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a result of type {@link Workspace}
 */
public ServiceCall<Workspace> getWorkspace(GetWorkspaceOptions getWorkspaceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(getWorkspaceOptions, "getWorkspaceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", getWorkspaceOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "getWorkspace");
    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 (getWorkspaceOptions.export() != null) {
        builder.query("export", String.valueOf(getWorkspaceOptions.export()));
    }
    if (getWorkspaceOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getWorkspaceOptions.includeAudit()));
    }
    if (getWorkspaceOptions.sort() != null) {
        builder.query("sort", String.valueOf(getWorkspaceOptions.sort()));
    }
    ResponseConverter<Workspace> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Workspace>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) Workspace(com.ibm.watson.assistant.v1.model.Workspace)

Example 9 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.

the class Assistant method createWorkspace.

/**
 * Create workspace.
 *
 * <p>Create a workspace based on component objects. You must provide workspace components
 * defining the content of the new workspace.
 *
 * @param createWorkspaceOptions the {@link CreateWorkspaceOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Workspace}
 */
public ServiceCall<Workspace> createWorkspace(CreateWorkspaceOptions createWorkspaceOptions) {
    boolean skipBody = false;
    if (createWorkspaceOptions == null) {
        createWorkspaceOptions = new CreateWorkspaceOptions.Builder().build();
        skipBody = true;
    }
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces"));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "createWorkspace");
    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 (createWorkspaceOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(createWorkspaceOptions.includeAudit()));
    }
    if (!skipBody) {
        final JsonObject contentJson = new JsonObject();
        if (createWorkspaceOptions.name() != null) {
            contentJson.addProperty("name", createWorkspaceOptions.name());
        }
        if (createWorkspaceOptions.description() != null) {
            contentJson.addProperty("description", createWorkspaceOptions.description());
        }
        if (createWorkspaceOptions.language() != null) {
            contentJson.addProperty("language", createWorkspaceOptions.language());
        }
        if (createWorkspaceOptions.dialogNodes() != null) {
            contentJson.add("dialog_nodes", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.dialogNodes()));
        }
        if (createWorkspaceOptions.counterexamples() != null) {
            contentJson.add("counterexamples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.counterexamples()));
        }
        if (createWorkspaceOptions.metadata() != null) {
            contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.metadata()));
        }
        if (createWorkspaceOptions.learningOptOut() != null) {
            contentJson.addProperty("learning_opt_out", createWorkspaceOptions.learningOptOut());
        }
        if (createWorkspaceOptions.systemSettings() != null) {
            contentJson.add("system_settings", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.systemSettings()));
        }
        if (createWorkspaceOptions.webhooks() != null) {
            contentJson.add("webhooks", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.webhooks()));
        }
        if (createWorkspaceOptions.intents() != null) {
            contentJson.add("intents", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.intents()));
        }
        if (createWorkspaceOptions.entities() != null) {
            contentJson.add("entities", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.entities()));
        }
        builder.bodyJson(contentJson);
    }
    ResponseConverter<Workspace> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Workspace>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Workspace(com.ibm.watson.assistant.v1.model.Workspace)

Example 10 with Workspace

use of com.ibm.watson.assistant.v1.model.Workspace 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);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) DialogNode(com.ibm.watson.assistant.v1.model.DialogNode)

Aggregations

HashMap (java.util.HashMap)21 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)18 JsonObject (com.google.gson.JsonObject)15 Test (org.junit.Test)8 Workspace (com.ibm.watson.assistant.v1.model.Workspace)6 Workspace (com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)6 Workspace (com.ibm.watson.developer_cloud.conversation.v1.model.Workspace)6 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)6 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)6 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)5 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)3 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateWorkspaceOptions)3 DeleteWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteWorkspaceOptions)3 CreateWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateWorkspaceOptions)3 DeleteWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteWorkspaceOptions)3 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)3 MockResponse (okhttp3.mockwebserver.MockResponse)3 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)2