use of com.ibm.watson.assistant.v1.model.Workspace in project java-sdk by watson-developer-cloud.
the class Conversation 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.
*
* @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));
}
use of com.ibm.watson.assistant.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));
}
use of com.ibm.watson.assistant.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());
}
use of com.ibm.watson.assistant.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());
}
use of com.ibm.watson.assistant.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));
}
Aggregations