Search in sources :

Example 1 with PersonNames

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

the class TriplePropertyConverterTest method toAddsTheValueTypePersonNames.

@Test
public void toAddsTheValueTypePersonNames() throws Exception {
    PersonNames value = new PersonNames();
    value.list.add(PersonName.newInstance("forename", "surname"));
    Tuple<String, List<Triple>> to = instance.to(new PersonNamesProperty(PROP_NAME, value));
    assertThat(to.getRight(), contains(allOf(hasProperty("datatype", is("http://timbuctoo.huygens.knaw.nl/personnames")))));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) List(java.util.List) PersonNamesProperty(nl.knaw.huygens.timbuctoo.core.dto.property.PersonNamesProperty) Test(org.junit.Test)

Example 2 with PersonNames

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

the class PersonNamesDefaultNamePropertyParserTest method parseReturnsTheShortNameOfTheFirstNameOfThePersonNames.

@Test
public void parseReturnsTheShortNameOfTheFirstNameOfThePersonNames() throws JsonProcessingException {
    PersonNames names = new PersonNames();
    PersonName name1 = PersonName.newInstance("forename", "surname");
    names.list.add(name1);
    names.list.add(PersonName.newInstance("forename2", "surname2"));
    String input = new ObjectMapper().writeValueAsString(names);
    String value = instance.parse(input);
    assertThat(value, is(name1.getShortName()));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with PersonNames

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

the class PersonNamesDefaultNamePropertyParser method parseForSort.

@Override
public Comparable<?> parseForSort(String value) {
    if (value != null) {
        try {
            PersonNames personNames = readPersonNames(value);
            String defaultName = personNames.defaultName().getSortName();
            if (StringUtils.isBlank(defaultName)) {
                return null;
            }
            return defaultName;
        } catch (IOException e) {
            LOG.error("Cannot parse '{}' as PersonNames", value);
            LOG.error("Exception thrown", e);
        }
    }
    return null;
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) IOException(java.io.IOException)

Example 4 with PersonNames

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

the class TriplePropertyConverterTest method toCreatesATripleWithAJsonVersionOfPersonNames.

@Test
public void toCreatesATripleWithAJsonVersionOfPersonNames() throws Exception {
    PersonNames value = new PersonNames();
    value.list.add(PersonName.newInstance("forename", "surname"));
    ObjectMapper objectMapper = new ObjectMapper();
    String objectValue = objectMapper.writeValueAsString(value);
    Tuple<String, List<Triple>> to = instance.to(new PersonNamesProperty(PROP_NAME, value));
    LiteralTriple triple = (LiteralTriple) to.getRight().get(0);
    assertThat(triple.getSubject(), is(SUBJECT_URI));
    assertThat(triple.getPredicate(), endsWith(PROP_NAME));
    assertThat(triple.getObject(), is(objectValue));
    assertThat(triple.getDatatype(), is("http://timbuctoo.huygens.knaw.nl/personnames"));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) LiteralTriple(nl.knaw.huygens.timbuctoo.rdf.LiteralTriple) List(java.util.List) PersonNamesProperty(nl.knaw.huygens.timbuctoo.core.dto.property.PersonNamesProperty) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with PersonNames

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

the class PersonNamesDefaultNamePropertyParserTest method parserToRawReturnsNullIfThePersonNamesIsEmpty.

@Test
public void parserToRawReturnsNullIfThePersonNamesIsEmpty() throws JsonProcessingException {
    PersonNames names = new PersonNames();
    String input = new ObjectMapper().writeValueAsString(names);
    Object value = instance.parseForSort(input);
    assertThat(value, is(nullValue()));
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

PersonNames (nl.knaw.huygens.timbuctoo.model.PersonNames)7 Test (org.junit.Test)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 PersonName (nl.knaw.huygens.timbuctoo.model.PersonName)3 IOException (java.io.IOException)2 List (java.util.List)2 PersonNamesProperty (nl.knaw.huygens.timbuctoo.core.dto.property.PersonNamesProperty)2 Entity (nl.knaw.huygens.timbuctoo.rdf.Entity)1 LiteralTriple (nl.knaw.huygens.timbuctoo.rdf.LiteralTriple)1