use of com.ibm.watson.assistant.v1.model.UpdateEntityOptions in project java-sdk by watson-developer-cloud.
the class ConversationTest method testUpdateEntityOptionsBuilder.
/**
* Test UpdateEntityOptions builder.
*/
@Test
public void testUpdateEntityOptionsBuilder() {
String entity = "anEntity";
String newEntity = "renamedEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
UpdateEntityOptions updateOptions = new UpdateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).newEntity(newEntity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
assertEquals(updateOptions.entity(), entity);
assertEquals(updateOptions.newEntity(), newEntity);
assertEquals(updateOptions.newValues().size(), 2);
assertEquals(updateOptions.newValues().get(0), entityValue0);
assertEquals(updateOptions.newValues().get(1), entityValue1);
UpdateEntityOptions.Builder builder = updateOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.newValues(Arrays.asList(entityValue2));
UpdateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.newEntity(), newEntity);
assertEquals(options2.newValues().size(), 1);
assertEquals(options2.newValues().get(0), entityValue2);
}
use of com.ibm.watson.assistant.v1.model.UpdateEntityOptions in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateEntityOptionsBuilder.
/**
* Test UpdateEntityOptions builder.
*/
@Test
public void testUpdateEntityOptionsBuilder() {
String entity = "anEntity";
String newEntity = "renamedEntity";
CreateValue entityValue0 = new CreateValue.Builder().value("entityValue0").addPattern("pattern0").build();
CreateValue entityValue1 = new CreateValue.Builder().value("entityValue1").addPattern("pattern1").build();
UpdateEntityOptions updateOptions = new UpdateEntityOptions.Builder().workspaceId(WORKSPACE_ID).entity(entity).newEntity(newEntity).addValue(entityValue0).addValue(entityValue1).build();
assertEquals(updateOptions.workspaceId(), WORKSPACE_ID);
assertEquals(updateOptions.entity(), entity);
assertEquals(updateOptions.newEntity(), newEntity);
assertEquals(updateOptions.newValues().size(), 2);
assertEquals(updateOptions.newValues().get(0), entityValue0);
assertEquals(updateOptions.newValues().get(1), entityValue1);
UpdateEntityOptions.Builder builder = updateOptions.newBuilder();
CreateValue entityValue2 = new CreateValue.Builder().value("entityValue2").addPattern("pattern2").build();
builder.newValues(Arrays.asList(entityValue2));
UpdateEntityOptions options2 = builder.build();
assertEquals(options2.workspaceId(), WORKSPACE_ID);
assertEquals(options2.entity(), entity);
assertEquals(options2.newEntity(), newEntity);
assertEquals(options2.newValues().size(), 1);
assertEquals(options2.newValues().get(0), entityValue2);
}
use of com.ibm.watson.assistant.v1.model.UpdateEntityOptions in project java-sdk by watson-developer-cloud.
the class AssistantTest method testUpdateEntityWOptions.
// Test the updateEntity operation with a valid options model parameter
@Test
public void testUpdateEntityWOptions() throws Throwable {
// Register a mock response
String mockResponseBody = "{\"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 updateEntityPath = "/v1/workspaces/testString/entities/testString";
server.enqueue(new MockResponse().setHeader("Content-type", "application/json").setResponseCode(200).setBody(mockResponseBody));
// 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 UpdateEntityOptions model
UpdateEntityOptions updateEntityOptionsModel = new UpdateEntityOptions.Builder().workspaceId("testString").entity("testString").newEntity("testString").newDescription("testString").newMetadata(new java.util.HashMap<String, Object>() {
{
put("foo", "testString");
}
}).newFuzzyMatch(true).newValues(new java.util.ArrayList<CreateValue>(java.util.Arrays.asList(createValueModel))).append(false).includeAudit(false).build();
// Invoke updateEntity() with a valid options model and verify the result
Response<Entity> response = assistantService.updateEntity(updateEntityOptionsModel).execute();
assertNotNull(response);
Entity 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, updateEntityPath);
// Verify query params
Map<String, String> query = TestUtilities.parseQueryString(request);
assertNotNull(query);
assertEquals(query.get("version"), "testString");
assertEquals(Boolean.valueOf(query.get("append")), Boolean.valueOf(false));
assertEquals(Boolean.valueOf(query.get("include_audit")), Boolean.valueOf(false));
}
use of com.ibm.watson.assistant.v1.model.UpdateEntityOptions in project java-sdk by watson-developer-cloud.
the class Assistant method updateEntity.
/**
* Update entity.
*
* <p>Update an existing entity with new or modified data. You must provide component objects
* defining the content of the updated entity.
*
* <p>If you want to update multiple entities with a single API call, consider using the **[Update
* workspace](#update-workspace)** method instead.
*
* @param updateEntityOptions the {@link UpdateEntityOptions} containing the options for the call
* @return a {@link ServiceCall} with a result of type {@link Entity}
*/
public ServiceCall<Entity> updateEntity(UpdateEntityOptions updateEntityOptions) {
com.ibm.cloud.sdk.core.util.Validator.notNull(updateEntityOptions, "updateEntityOptions cannot be null");
Map<String, String> pathParamsMap = new HashMap<String, String>();
pathParamsMap.put("workspace_id", updateEntityOptions.workspaceId());
pathParamsMap.put("entity", updateEntityOptions.entity());
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/workspaces/{workspace_id}/entities/{entity}", pathParamsMap));
Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("conversation", "v1", "updateEntity");
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 (updateEntityOptions.append() != null) {
builder.query("append", String.valueOf(updateEntityOptions.append()));
}
if (updateEntityOptions.includeAudit() != null) {
builder.query("include_audit", String.valueOf(updateEntityOptions.includeAudit()));
}
final JsonObject contentJson = new JsonObject();
if (updateEntityOptions.newEntity() != null) {
contentJson.addProperty("entity", updateEntityOptions.newEntity());
}
if (updateEntityOptions.newDescription() != null) {
contentJson.addProperty("description", updateEntityOptions.newDescription());
}
if (updateEntityOptions.newMetadata() != null) {
contentJson.add("metadata", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateEntityOptions.newMetadata()));
}
if (updateEntityOptions.newFuzzyMatch() != null) {
contentJson.addProperty("fuzzy_match", updateEntityOptions.newFuzzyMatch());
}
if (updateEntityOptions.newValues() != null) {
contentJson.add("values", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(updateEntityOptions.newValues()));
}
builder.bodyJson(contentJson);
ResponseConverter<Entity> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Entity>() {
}.getType());
return createServiceCall(builder.build(), responseConverter);
}
Aggregations