Search in sources :

Example 6 with Workspace

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

the class Conversation method createCounterexample.

/**
 * Create counterexample.
 *
 * Add a new counterexample to a workspace. Counterexamples are examples that have been marked as irrelevant input.
 *
 * @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.conversation.v1.model.Counterexample)

Example 7 with Workspace

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

the class Conversation method createWorkspace.

/**
 * Create workspace.
 *
 * 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 response type of {@link Workspace}
 */
public ServiceCall<Workspace> createWorkspace(CreateWorkspaceOptions createWorkspaceOptions) {
    String[] pathSegments = { "v1/workspaces" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query(VERSION, versionDate);
    if (createWorkspaceOptions != null) {
        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.intents() != null) {
            contentJson.add("intents", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.intents()));
        }
        if (createWorkspaceOptions.entities() != null) {
            contentJson.add("entities", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.entities()));
        }
        if (createWorkspaceOptions.dialogNodes() != null) {
            contentJson.add("dialog_nodes", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.dialogNodes()));
        }
        if (createWorkspaceOptions.counterexamples() != null) {
            contentJson.add("counterexamples", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.counterexamples()));
        }
        if (createWorkspaceOptions.metadata() != null) {
            contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.metadata()));
        }
        if (createWorkspaceOptions.learningOptOut() != null) {
            contentJson.addProperty("learning_opt_out", createWorkspaceOptions.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.conversation.v1.model.Workspace)

Example 8 with Workspace

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

the class AssistantServiceIT method testListWorkspaces.

/**
 * Test listWorkspaces.
 */
@Test
public void testListWorkspaces() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getWorkspaces());
    assertTrue(response.getWorkspaces().size() > 0);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    Workspace wResponse = null;
    for (Workspace resp : response.getWorkspaces()) {
        if (resp.getWorkspaceId().equals(workspaceId)) {
            wResponse = resp;
            break;
        }
    }
    assertNotNull(wResponse);
    assertNotNull(wResponse.getName());
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.assistant.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.assistant.v1.model.WorkspaceCollection) Workspace(com.ibm.watson.developer_cloud.assistant.v1.model.Workspace) Test(org.junit.Test)

Example 9 with Workspace

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

the class ConversationServiceIT method testListWorkspaces.

/**
 * Test listWorkspaces.
 */
@Test
public void testListWorkspaces() {
    ListWorkspacesOptions listOptions = new ListWorkspacesOptions.Builder().build();
    WorkspaceCollection response = service.listWorkspaces(listOptions).execute();
    assertNotNull(response);
    assertNotNull(response.getWorkspaces());
    assertTrue(response.getWorkspaces().size() > 0);
    assertNotNull(response.getPagination());
    assertNotNull(response.getPagination().getRefreshUrl());
    Workspace wResponse = null;
    for (Workspace resp : response.getWorkspaces()) {
        if (resp.getWorkspaceId().equals(workspaceId)) {
            wResponse = resp;
            break;
        }
    }
    assertNotNull(wResponse);
    assertNotNull(wResponse.getName());
}
Also used : ListWorkspacesOptions(com.ibm.watson.developer_cloud.conversation.v1.model.ListWorkspacesOptions) WorkspaceCollection(com.ibm.watson.developer_cloud.conversation.v1.model.WorkspaceCollection) Workspace(com.ibm.watson.developer_cloud.conversation.v1.model.Workspace) Test(org.junit.Test)

Example 10 with Workspace

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

the class Assistant method createWorkspace.

/**
 * Create workspace.
 *
 * Create a workspace based on component objects. You must provide workspace components defining the content of the
 * new workspace. This operation is limited to 30 requests per 30 minutes. For more information, see **Rate
 * limiting**.
 *
 * @param createWorkspaceOptions the {@link CreateWorkspaceOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Workspace}
 */
public ServiceCall<Workspace> createWorkspace(CreateWorkspaceOptions createWorkspaceOptions) {
    String[] pathSegments = { "v1/workspaces" };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
    builder.query(VERSION, versionDate);
    if (createWorkspaceOptions != null) {
        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.intents() != null) {
            contentJson.add("intents", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.intents()));
        }
        if (createWorkspaceOptions.entities() != null) {
            contentJson.add("entities", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.entities()));
        }
        if (createWorkspaceOptions.dialogNodes() != null) {
            contentJson.add("dialog_nodes", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.dialogNodes()));
        }
        if (createWorkspaceOptions.counterexamples() != null) {
            contentJson.add("counterexamples", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.counterexamples()));
        }
        if (createWorkspaceOptions.metadata() != null) {
            contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(createWorkspaceOptions.metadata()));
        }
        if (createWorkspaceOptions.learningOptOut() != null) {
            contentJson.addProperty("learning_opt_out", createWorkspaceOptions.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)

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 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 Counterexample (com.ibm.watson.developer_cloud.conversation.v1.model.Counterexample)2 CreateCounterexample (com.ibm.watson.developer_cloud.conversation.v1.model.CreateCounterexample)2 CreateEntity (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntity)2 CreateIntent (com.ibm.watson.developer_cloud.conversation.v1.model.CreateIntent)2 GetWorkspaceOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetWorkspaceOptions)2