Search in sources :

Example 1 with AltNames

use of nl.knaw.huygens.timbuctoo.model.AltNames in project timbuctoo by HuygensING.

the class JsonPropertyConverterTest method toConvertsTheListOfAltNamesToAnArrayNode.

@Test
public void toConvertsTheListOfAltNamesToAnArrayNode() throws Exception {
    JsonPropertyConverter jsonPropertyConverter = new JsonPropertyConverter(null);
    AltNames altNames = new AltNames();
    altNames.list = Lists.newArrayList(new AltName("type1", "name1"), new AltName("type2", "name2"));
    Tuple<String, JsonNode> valueTuple = jsonPropertyConverter.to(new AltNamesProperty("test", altNames));
    JsonNode value = valueTuple.getRight();
    assertThat(value.isArray(), is(true));
    assertThat(Lists.newArrayList(value.iterator()), containsInAnyOrder(jsnO("nametype", jsn("type1"), "displayName", jsn("name1")), jsnO("nametype", jsn("type2"), "displayName", jsn("name2"))));
}
Also used : AltNamesProperty(nl.knaw.huygens.timbuctoo.core.dto.property.AltNamesProperty) AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) JsonNode(com.fasterxml.jackson.databind.JsonNode) AltName(nl.knaw.huygens.timbuctoo.model.AltName) JsonPropertyConverter(nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter) Test(org.junit.Test)

Example 2 with AltNames

use of nl.knaw.huygens.timbuctoo.model.AltNames in project timbuctoo by HuygensING.

the class AltNamesConverterTest method jsonToTinkerpopConvertsASerializedAltNamesValuesToADbSerializedAsString.

@Test
public void jsonToTinkerpopConvertsASerializedAltNamesValuesToADbSerializedAsString() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    JsonNode jsonNode = objectMapper.valueToTree(Lists.newArrayList(ALT_NAME_1, ALT_NAME_2));
    String value = instance.jsonToTinkerpop(jsonNode);
    AltNames altNamesValue = objectMapper.readValue(value, AltNames.class);
    assertThat(altNamesValue.list, containsInAnyOrder(ALT_NAME_1, ALT_NAME_2));
}
Also used : AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with AltNames

use of nl.knaw.huygens.timbuctoo.model.AltNames in project timbuctoo by HuygensING.

the class AltNamesConverterTest method tinkerpopToJsonReadsTheListOfTheAltNamesValues.

@Test
public void tinkerpopToJsonReadsTheListOfTheAltNamesValues() throws Exception {
    AltNames altNames = new AltNames();
    altNames.list = Lists.newArrayList(ALT_NAME_1, ALT_NAME_2);
    String dbValue = objectMapper.writeValueAsString(altNames);
    JsonNode jsonNode = instance.tinkerpopToJson(dbValue);
    List<AltName> altNameList = objectMapper.readValue(jsonNode.toString(), new TypeReference<List<AltName>>() {
    });
    assertThat(altNameList, containsInAnyOrder(ALT_NAME_1, ALT_NAME_2));
}
Also used : AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) JsonNode(com.fasterxml.jackson.databind.JsonNode) List(java.util.List) AltName(nl.knaw.huygens.timbuctoo.model.AltName) Test(org.junit.Test)

Example 4 with AltNames

use of nl.knaw.huygens.timbuctoo.model.AltNames in project timbuctoo by HuygensING.

the class AltNameFacetDescriptionTest method getValuesReturnsTheDisplayNamesOfAllTheAltNames.

@Test
public void getValuesReturnsTheDisplayNamesOfAllTheAltNames() throws Exception {
    String displayName1 = "displayName1";
    String displayName2 = "displayName2";
    AltNames altNames = new AltNames();
    altNames.list = Lists.newArrayList(new AltName("nameType", displayName1), new AltName("nameType", displayName2));
    String altNamesPropValue = new ObjectMapper().writeValueAsString(altNames);
    Vertex vertex = vertex().withProperty(PROPERTY_NAME, altNamesPropValue).build();
    AltNameFacetDescription instance = new AltNameFacetDescription("facetName", PROPERTY_NAME);
    List<String> values = instance.getValues(vertex);
    assertThat(values, containsInAnyOrder(displayName1, displayName2));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) AltName(nl.knaw.huygens.timbuctoo.model.AltName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with AltNames

use of nl.knaw.huygens.timbuctoo.model.AltNames in project timbuctoo by HuygensING.

the class AltNameFacetDescription method getValues.

@Override
public List<String> getValues(Vertex vertex) {
    List<String> values = Lists.newArrayList();
    VertexProperty<String> property = vertex.property(propertyName);
    if (property.isPresent()) {
        String value = property.value();
        try {
            AltNames altNames = objectMapper.readValue(value, AltNames.class);
            altNames.list.forEach(altName -> values.add(altName.getDisplayName()));
        } catch (IOException e) {
            LOG.error("Could not convert '{}'", value);
            LOG.error("Exception throw.", e);
        }
    }
    return values;
}
Also used : AltNames(nl.knaw.huygens.timbuctoo.model.AltNames) IOException(java.io.IOException)

Aggregations

AltNames (nl.knaw.huygens.timbuctoo.model.AltNames)5 Test (org.junit.Test)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 AltName (nl.knaw.huygens.timbuctoo.model.AltName)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)1 List (java.util.List)1 AltNamesProperty (nl.knaw.huygens.timbuctoo.core.dto.property.AltNamesProperty)1 JsonPropertyConverter (nl.knaw.huygens.timbuctoo.crud.conversion.JsonPropertyConverter)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1