Search in sources :

Example 6 with UpdateWorkspaceOptions

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

the class Assistant method updateWorkspace.

/**
 * Update workspace.
 *
 * <p>Update an existing workspace with new or modified data. You must provide component objects
 * defining the content of the updated workspace.
 *
 * @param updateWorkspaceOptions the {@link UpdateWorkspaceOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link Workspace}
 */
public ServiceCall<Workspace> updateWorkspace(UpdateWorkspaceOptions updateWorkspaceOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(updateWorkspaceOptions, "updateWorkspaceOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("workspace_id", updateWorkspaceOptions.workspaceId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateWorkspace");
    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 (updateWorkspaceOptions.append() != null) {
        builder.query("append", String.valueOf(updateWorkspaceOptions.append()));
    }
    if (updateWorkspaceOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(updateWorkspaceOptions.includeAudit()));
    }
    final JsonObject contentJson = new JsonObject();
    if (updateWorkspaceOptions.name() != null) {
        contentJson.addProperty("name", updateWorkspaceOptions.name());
    }
    if (updateWorkspaceOptions.description() != null) {
        contentJson.addProperty("description", updateWorkspaceOptions.description());
    }
    if (updateWorkspaceOptions.language() != null) {
        contentJson.addProperty("language", updateWorkspaceOptions.language());
    }
    if (updateWorkspaceOptions.dialogNodes() != null) {
        contentJson.add("dialog_nodes", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.dialogNodes()));
    }
    if (updateWorkspaceOptions.counterexamples() != null) {
        contentJson.add("counterexamples", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.counterexamples()));
    }
    if (updateWorkspaceOptions.metadata() != null) {
        contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.metadata()));
    }
    if (updateWorkspaceOptions.learningOptOut() != null) {
        contentJson.addProperty("learning_opt_out", updateWorkspaceOptions.learningOptOut());
    }
    if (updateWorkspaceOptions.systemSettings() != null) {
        contentJson.add("system_settings", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.systemSettings()));
    }
    if (updateWorkspaceOptions.webhooks() != null) {
        contentJson.add("webhooks", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.webhooks()));
    }
    if (updateWorkspaceOptions.intents() != null) {
        contentJson.add("intents", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.intents()));
    }
    if (updateWorkspaceOptions.entities() != null) {
        contentJson.add("entities", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.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) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Workspace(com.ibm.watson.assistant.v1.model.Workspace)

Aggregations

HashMap (java.util.HashMap)4 Test (org.junit.Test)4 JsonObject (com.google.gson.JsonObject)3 Workspace (com.ibm.watson.assistant.v1.model.Workspace)2 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 CreateCounterexample (com.ibm.watson.developer_cloud.assistant.v1.model.CreateCounterexample)2 CreateEntity (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.developer_cloud.assistant.v1.model.CreateIntent)2 UpdateWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateWorkspaceOptions)2 NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)2 UnauthorizedException (com.ibm.watson.developer_cloud.service.exception.UnauthorizedException)2 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)1 Counterexample (com.ibm.watson.assistant.v1.model.Counterexample)1 CreateEntity (com.ibm.watson.assistant.v1.model.CreateEntity)1 CreateIntent (com.ibm.watson.assistant.v1.model.CreateIntent)1 CreateValue (com.ibm.watson.assistant.v1.model.CreateValue)1 DialogNode (com.ibm.watson.assistant.v1.model.DialogNode)1 DialogNodeAction (com.ibm.watson.assistant.v1.model.DialogNodeAction)1 DialogNodeContext (com.ibm.watson.assistant.v1.model.DialogNodeContext)1 DialogNodeNextStep (com.ibm.watson.assistant.v1.model.DialogNodeNextStep)1