Search in sources :

Example 1 with ValueExport

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

the class ValuesIT method testUpdateValue.

/**
 * Test updateValue.
 */
@Test
public void testUpdateValue() {
    String entity = "beverage";
    String entityValue1 = "coffee" + UUID.randomUUID().toString();
    String entityValue2 = "coffee" + UUID.randomUUID().toString();
    String synonym1 = "java";
    String synonym2 = "joe";
    // metadata
    Map<String, Object> valueMetadata = new HashMap<String, Object>();
    String metadataValue = "value for " + entityValue2;
    valueMetadata.put("key", metadataValue);
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    try {
        CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue1).build();
        service.createValue(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    UpdateValueOptions updateOptions = new UpdateValueOptions.Builder().workspaceId(workspaceId).entity(entity).value(entityValue1).newValue(entityValue2).newSynonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).newMetadata(valueMetadata).build();
    Value response = service.updateValue(updateOptions).execute();
    try {
        assertNotNull(response);
        assertNotNull(response.getValueText());
        assertEquals(response.getValueText(), entityValue2);
        GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue2).export(true).includeAudit(true).build();
        ValueExport vResponse = service.getValue(getOptions).execute();
        assertNotNull(vResponse);
        assertNotNull(vResponse.getValueText());
        assertEquals(vResponse.getValueText(), entityValue2);
        assertNotNull(vResponse.getCreated());
        assertNotNull(vResponse.getUpdated());
        assertNotNull(vResponse.getSynonyms());
        assertTrue(vResponse.getSynonyms().size() == 2);
        assertTrue(vResponse.getSynonyms().contains(synonym1));
        assertTrue(vResponse.getSynonyms().contains(synonym2));
        // metadata
        assertNotNull(response.getMetadata());
        assertNotNull(response.getMetadata().get("key"));
        assertEquals(response.getMetadata().get("key"), metadataValue);
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue2).build();
        service.deleteValue(deleteOptions).execute();
    }
}
Also used : GetValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetValueOptions) HashMap(java.util.HashMap) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) DeleteValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions) CreateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions) UpdateValueOptions(com.ibm.watson.developer_cloud.conversation.v1.model.UpdateValueOptions) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) ValueExport(com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport) Value(com.ibm.watson.developer_cloud.conversation.v1.model.Value) Test(org.junit.Test)

Example 2 with ValueExport

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

the class ValuesIT method testGetValue.

/**
 * Test getValue.
 */
@Test
public void testGetValue() {
    String entity = "beverage";
    String entityValue = "coffee" + UUID.randomUUID().toString();
    String synonym1 = "java";
    String synonym2 = "joe";
    try {
        CreateEntityOptions createOptions = new CreateEntityOptions.Builder(workspaceId, entity).build();
        service.createEntity(createOptions).execute();
    } catch (Exception ex) {
        // Exception is okay if is for Unique Violation
        assertTrue(ex.getLocalizedMessage().startsWith("Unique Violation"));
    }
    CreateValueOptions createOptions = new CreateValueOptions.Builder(workspaceId, entity, entityValue).synonyms(new ArrayList<String>(Arrays.asList(synonym1, synonym2))).build();
    service.createValue(createOptions).execute();
    Date start = new Date();
    try {
        GetValueOptions getOptions = new GetValueOptions.Builder(workspaceId, entity, entityValue).export(true).includeAudit(true).build();
        ValueExport response = service.getValue(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getValueText());
        assertEquals(response.getValueText(), entityValue);
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
        assertNotNull(response.getSynonyms());
        assertTrue(response.getSynonyms().size() == 2);
        assertTrue(response.getSynonyms().contains(synonym1));
        assertTrue(response.getSynonyms().contains(synonym2));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        DeleteValueOptions deleteOptions = new DeleteValueOptions.Builder(workspaceId, entity, entityValue).build();
        service.deleteValue(deleteOptions).execute();
    }
}
Also used : GetValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.GetValueOptions) CreateEntityOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions) DeleteValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.DeleteValueOptions) CreateValueOptions(com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions) ArrayList(java.util.ArrayList) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) Date(java.util.Date) ValueExport(com.ibm.watson.developer_cloud.assistant.v1.model.ValueExport) Test(org.junit.Test)

Example 3 with ValueExport

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

the class Conversation method getValue.

/**
 * Get entity value.
 *
 * Get information about an entity value.
 *
 * @param getValueOptions the {@link GetValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link ValueExport}
 */
public ServiceCall<ValueExport> getValue(GetValueOptions getValueOptions) {
    Validator.notNull(getValueOptions, "getValueOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values" };
    String[] pathParameters = { getValueOptions.workspaceId(), getValueOptions.entity(), getValueOptions.value() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getValueOptions.export() != null) {
        builder.query("export", String.valueOf(getValueOptions.export()));
    }
    if (getValueOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getValueOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ValueExport.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) ValueExport(com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport)

Example 4 with ValueExport

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

the class Assistant method getValue.

/**
 * Get entity value.
 *
 * Get information about an entity value. This operation is limited to 6000 requests per 5 minutes. For more
 * information, see **Rate limiting**.
 *
 * @param getValueOptions the {@link GetValueOptions} containing the options for the call
 * @return a {@link ServiceCall} with a response type of {@link ValueExport}
 */
public ServiceCall<ValueExport> getValue(GetValueOptions getValueOptions) {
    Validator.notNull(getValueOptions, "getValueOptions cannot be null");
    String[] pathSegments = { "v1/workspaces", "entities", "values" };
    String[] pathParameters = { getValueOptions.workspaceId(), getValueOptions.entity(), getValueOptions.value() };
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
    builder.query(VERSION, versionDate);
    if (getValueOptions.export() != null) {
        builder.query("export", String.valueOf(getValueOptions.export()));
    }
    if (getValueOptions.includeAudit() != null) {
        builder.query("include_audit", String.valueOf(getValueOptions.includeAudit()));
    }
    return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ValueExport.class));
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) ValueExport(com.ibm.watson.developer_cloud.assistant.v1.model.ValueExport)

Example 5 with ValueExport

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

the class EntitiesIT method testGetEntity.

/**
 * Test getEntity.
 */
@Test
public void testGetEntity() {
    // gotta be unique
    String entity = "Hello" + UUID.randomUUID().toString();
    String entityDescription = "Description of " + entity;
    String entityValue = "Value of " + entity;
    List<CreateValue> entityValues = new ArrayList<CreateValue>();
    entityValues.add(new CreateValue.Builder().value(entityValue).build());
    CreateEntityOptions.Builder optionsBuilder = new CreateEntityOptions.Builder();
    optionsBuilder.workspaceId(workspaceId);
    optionsBuilder.entity(entity);
    optionsBuilder.description(entityDescription);
    optionsBuilder.values(entityValues);
    service.createEntity(optionsBuilder.build()).execute();
    Date start = new Date();
    try {
        GetEntityOptions getOptions = new GetEntityOptions.Builder(workspaceId, entity).export(true).includeAudit(true).build();
        EntityExport response = service.getEntity(getOptions).execute();
        assertNotNull(response);
        assertNotNull(response.getEntityName());
        assertEquals(response.getEntityName(), entity);
        assertNotNull(response.getDescription());
        assertEquals(response.getDescription(), entityDescription);
        assertNotNull(response.getValues());
        assertNotNull(response.getCreated());
        assertNotNull(response.getUpdated());
        Date now = new Date();
        assertTrue(fuzzyBefore(response.getCreated(), now));
        assertTrue(fuzzyAfter(response.getCreated(), start));
        assertTrue(fuzzyBefore(response.getUpdated(), now));
        assertTrue(fuzzyAfter(response.getUpdated(), start));
        List<ValueExport> values = response.getValues();
        assertTrue(values.size() == 1);
        assertEquals(values.get(0).getValueText(), entityValue);
        assertTrue(fuzzyBefore(values.get(0).getCreated(), now));
        assertTrue(fuzzyAfter(values.get(0).getCreated(), start));
        assertTrue(fuzzyBefore(values.get(0).getUpdated(), now));
        assertTrue(fuzzyAfter(values.get(0).getUpdated(), start));
    } catch (Exception ex) {
        fail(ex.getMessage());
    } finally {
        // Clean up
        DeleteEntityOptions deleteOptions = new DeleteEntityOptions.Builder(workspaceId, entity).build();
        service.deleteEntity(deleteOptions).execute();
    }
}
Also used : CreateValue(com.ibm.watson.developer_cloud.conversation.v1.model.CreateValue) CreateEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions) ArrayList(java.util.ArrayList) Date(java.util.Date) NotFoundException(com.ibm.watson.developer_cloud.service.exception.NotFoundException) EntityExport(com.ibm.watson.developer_cloud.conversation.v1.model.EntityExport) ValueExport(com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport) DeleteEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.DeleteEntityOptions) GetEntityOptions(com.ibm.watson.developer_cloud.conversation.v1.model.GetEntityOptions) Test(org.junit.Test)

Aggregations

NotFoundException (com.ibm.watson.developer_cloud.service.exception.NotFoundException)8 Test (org.junit.Test)8 ValueExport (com.ibm.watson.developer_cloud.assistant.v1.model.ValueExport)5 ValueExport (com.ibm.watson.developer_cloud.conversation.v1.model.ValueExport)5 CreateEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateEntityOptions)4 CreateEntityOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateEntityOptions)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 CreateValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteValueOptions)3 CreateValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.CreateValueOptions)3 DeleteValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.DeleteValueOptions)3 GetValueOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetValueOptions)2 GetValueOptions (com.ibm.watson.developer_cloud.conversation.v1.model.GetValueOptions)2 RequestBuilder (com.ibm.watson.developer_cloud.http.RequestBuilder)2 HashMap (java.util.HashMap)2 CreateValue (com.ibm.watson.developer_cloud.assistant.v1.model.CreateValue)1 DeleteEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.DeleteEntityOptions)1 EntityExport (com.ibm.watson.developer_cloud.assistant.v1.model.EntityExport)1 GetEntityOptions (com.ibm.watson.developer_cloud.assistant.v1.model.GetEntityOptions)1