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"))));
}
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));
}
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));
}
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));
}
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;
}
Aggregations