Search in sources :

Example 16 with Workspace

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

the class ConversationServiceIT method testDeleteWorkspace.

/**
 * Test deleteWorkspace.
 */
@Test
public void testDeleteWorkspace() {
    CreateWorkspaceOptions createOptions = new CreateWorkspaceOptions.Builder().build();
    String workspaceId = null;
    try {
        Workspace response = service.createWorkspace(createOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getWorkspaceId());
        workspaceId = response.getWorkspaceId();
        DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
        service.deleteWorkspace(deleteOptions).execute();
        GetWorkspaceOptions getOptions = new GetWorkspaceOptions.Builder(workspaceId).export(true).build();
        service.getWorkspace(getOptions).execute();
    } catch (Exception ex) {
        // Expected result
        assertTrue(ex instanceof NotFoundException);
        workspaceId = null;
    } finally {
        // Clean up
        if (workspaceId != null) {
            DeleteWorkspaceOptions deleteOptions = new DeleteWorkspaceOptions.Builder(workspaceId).build();
            service.deleteWorkspace(deleteOptions).execute();
        }
    }
}
Also used : DeleteWorkspaceOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteWorkspaceOptions) CreateWorkspaceOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateWorkspaceOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) UnauthorizedException(com.ibm.watson.developer_cloud.service.exception.UnauthorizedException) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Workspace(com.ibm.watson.developer_cloud.conversation.v1.model.Workspace) GetWorkspaceOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetWorkspaceOptions) Test(org.junit.Test)

Example 17 with Workspace

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

the class Assistant method listDialogNodes.

/**
 * List dialog nodes.
 *
 * List the dialog nodes for a workspace. This operation is limited to 2500 requests per 30 minutes. For more
 * information, see **Rate limiting**.
 *
 * @param listDialogNodesOptions the {@link ListDialogNodesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link DialogNodeCollection}
 */
public ServiceCall<DialogNodeCollection> listDialogNodes(ListDialogNodesOptions listDialogNodesOptions) {
    Validator.notNull(listDialogNodesOptions, "listDialogNodesOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "dialog_nodes" };
    String[] pathParameters = { listDialogNodesOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (listDialogNodesOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listDialogNodesOptions.pageLimit()));
    }
    if (listDialogNodesOptions.includeCount() != null) {
        builder.query("include_count", String.valueOf(listDialogNodesOptions.includeCount()));
    }
    if (listDialogNodesOptions.sort() != null) {
        builder.query("sort", listDialogNodesOptions.sort());
    }
    if (listDialogNodesOptions.cursor() != null) {
        builder.query("cursor", listDialogNodesOptions.cursor());
    }
    if (listDialogNodesOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listDialogNodesOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(DialogNodeCollection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) DialogNodeCollection(com.ibm.watson.developer_cloud.assistant.v1.model.DialogNodeCollection)

Example 18 with Workspace

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

the class Assistant method listCounterexamples.

/**
 * List counterexamples.
 *
 * List the counterexamples for a workspace. Counterexamples are examples that have been marked as irrelevant input.
 * This operation is limited to 2500 requests per 30 minutes. For more information, see **Rate limiting**.
 *
 * @param listCounterexamplesOptions the {@link ListCounterexamplesOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link CounterexampleCollection}
 */
public ServiceCall<CounterexampleCollection> listCounterexamples(ListCounterexamplesOptions listCounterexamplesOptions) {
    Validator.notNull(listCounterexamplesOptions, "listCounterexamplesOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "counterexamples" };
    String[] pathParameters = { listCounterexamplesOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (listCounterexamplesOptions.pageLimit() != null) {
        builder.query("page_limit", String.valueOf(listCounterexamplesOptions.pageLimit()));
    }
    if (listCounterexamplesOptions.includeCount() != null) {
        builder.query("include_count", String.valueOf(listCounterexamplesOptions.includeCount()));
    }
    if (listCounterexamplesOptions.sort() != null) {
        builder.query("sort", listCounterexamplesOptions.sort());
    }
    if (listCounterexamplesOptions.cursor() != null) {
        builder.query("cursor", listCounterexamplesOptions.cursor());
    }
    if (listCounterexamplesOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(listCounterexamplesOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(CounterexampleCollection.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) CounterexampleCollection(com.ibm.watson.developer_cloud.assistant.v1.model.CounterexampleCollection)

Example 19 with Workspace

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

the class Assistant method updateWorkspace.

/**
 * Update workspace.
 *
 * Update an existing workspace with new or modified data. You must provide component objects defining the content of
 * the updated workspace. This operation is limited to 30 request per 30 minutes. For more information, see **Rate
 * limiting**.
 *
 * @param updateWorkspaceOptions the {@link UpdateWorkspaceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Workspace}
 */
public ServiceCall<Workspace> updateWorkspace(UpdateWorkspaceOptions updateWorkspaceOptions) {
    Validator.notNull(updateWorkspaceOptions, "updateWorkspaceOptions cannot be null");
    String[] pathSegments = { "v1/workspaces" };
    String[] pathParameters = { updateWorkspaceOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (updateWorkspaceOptions.append() != null) {
        builder.query("append", String.valueOf(updateWorkspaceOptions.append()));
    }
    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.intents() != null) {
        contentJson.add("intents", GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.intents()));
    }
    if (updateWorkspaceOptions.entities() != null) {
        contentJson.add("entities", GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.entities()));
    }
    if (updateWorkspaceOptions.dialogNodes() != null) {
        contentJson.add("dialog_nodes", GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.dialogNodes()));
    }
    if (updateWorkspaceOptions.counterexamples() != null) {
        contentJson.add("counterexamples", GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.counterexamples()));
    }
    if (updateWorkspaceOptions.metadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateWorkspaceOptions.metadata()));
    }
    if (updateWorkspaceOptions.learningOptOut() != null) {
        contentJson.addProperty("learning_opt_out", updateWorkspaceOptions.learningOptOut());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Workspace.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Workspace(com.ibm.watson.developer_cloud.assistant.v1.model.Workspace)

Example 20 with Workspace

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

the class Assistant method createCounterexample.

/**
 * Create counterexample.
 *
 * Add a new counterexample to a workspace. Counterexamples are examples that have been marked as irrelevant input.
 * This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate limiting**.
 *
 * @param createCounterexampleOptions the {@link CreateCounterexampleOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Counterexample}
 */
public ServiceCall<Counterexample> createCounterexample(CreateCounterexampleOptions createCounterexampleOptions) {
    Validator.notNull(createCounterexampleOptions, "createCounterexampleOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "counterexamples" };
    String[] pathParameters = { createCounterexampleOptions.workspaceId() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    contentJson.addProperty("text", createCounterexampleOptions.text());
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Counterexample.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject) Counterexample(com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)

Aggregations

RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)11 Test (org.junit.Test)9 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 JsonObject (com.google.gson.JsonObject)5 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 HashMap (java.util.HashMap)3 Counterexample (com.ibm.watson.developer_cloud.assistant.v1.model.Counterexample)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 GetWorkspaceOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetWorkspaceOptions)2 MessageOptions (com.ibm.watson.developer_cloud.assistant.v1.model.MessageOptions)2 WorkspaceExport (com.ibm.watson.developer_cloud.assistant.v1.model.WorkspaceExport)2 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)2