Search in sources :

Example 1 with UpdateEntityOptions

use of com.ibm.watson.developer_cloud.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) UpdateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 2 with UpdateEntityOptions

use of com.ibm.watson.developer_cloud.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);
}
Also used : CreateValue(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue) UpdateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.UpdateEntityOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 3 with UpdateEntityOptions

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

the class Assistant method updateEntity.

/**
 * Update entity.
 *
 * Update an existing entity with new or modified data. You must provide component objects defining the content of the
 * updated entity. This operation is limited to 1000 requests per 30 minutes. For more information, see **Rate
 * limiting**.
 *
 * @param updateEntityOptions the {@link UpdateEntityOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link Entity}
 */
public ServiceCall<Entity> updateEntity(UpdateEntityOptions updateEntityOptions) {
    Validator.notNull(updateEntityOptions, "updateEntityOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities" };
    String[] pathParameters = { updateEntityOptions.workspaceId(), updateEntityOptions.entity() };
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    final JsonObject contentJson = new JsonObject();
    if (updateEntityOptions.newFuzzyMatch() != null) {
        contentJson.addProperty("fuzzy_match", updateEntityOptions.newFuzzyMatch());
    }
    if (updateEntityOptions.newEntity() != null) {
        contentJson.addProperty("entity", updateEntityOptions.newEntity());
    }
    if (updateEntityOptions.newMetadata() != null) {
        contentJson.add("metadata", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newMetadata()));
    }
    if (updateEntityOptions.newValues() != null) {
        contentJson.add("values", GsonSingleton.getGson().toJsonTree(updateEntityOptions.newValues()));
    }
    if (updateEntityOptions.newDescription() != null) {
        contentJson.addProperty("description", updateEntityOptions.newDescription());
    }
    builder.bodyJson(contentJson);
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Entity.class));
}
Also used : Entity(com.ibm.watson.developer_cloud.assistant.v1.model.Entity) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) JsonObject(com.google.gson.JsonObject)

Aggregations

WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)2 Test (org.junit.Test)2 JsonObject (com.google.gson.JsonObject)1 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)1 Entity (com.ibm.watson.developer_cloud.assistant.v1.model.Entity)1 UpdateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.UpdateEntityOptions)1 CreateValue (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue)1 UpdateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.UpdateEntityOptions)1 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)1