Search in sources :

Example 6 with PersonNames

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

the class PersonNamesDefaultNamePropertyParserTest method parseForSortReturnsAStringThatConsistsOfSortNameVariantOfTheDefaultName.

@Test
public void parseForSortReturnsAStringThatConsistsOfSortNameVariantOfTheDefaultName() throws JsonProcessingException {
    PersonNames names = new PersonNames();
    PersonName name1 = PersonName.newInstance("forename", "surname");
    names.list.add(name1);
    PersonName name2 = PersonName.newInstance("forename2", "surname2");
    names.list.add(name2);
    String input = new ObjectMapper().writeValueAsString(names);
    Object value = instance.parseForSort(input);
    assertThat(value, is(names.defaultName().getSortName()));
}
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 7 with PersonNames

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

the class PersonNamesTripleProcessor method processAssertion.

@Override
protected void processAssertion(String vreName, String subject, String predicate, String lexicalValue, String typeUri) {
    LOG.debug("Process PersonNames triple for subject '{}' with value '{}'", subject, lexicalValue);
    Entity entity = database.findOrCreateEntity(vreName, subject);
    String propertyName = getLocalName(predicate);
    Optional<String> propertyValue = entity.getPropertyValue(propertyName);
    try {
        PersonName personName = objectMapper.readValue(lexicalValue, PersonName.class);
        PersonNames personNames = getPersonNames(objectMapper, propertyValue);
        personNames.list.add(personName);
        String names = objectMapper.writeValueAsString(personNames);
        // Because the person names is wrapped in a person names type, the type changes
        entity.addProperty(propertyName, names, NAMES_TYPE_ID);
    } catch (IOException e) {
        LOG.error("Could not convert '{}' to PersonName", lexicalValue);
    }
}
Also used : PersonNames(nl.knaw.huygens.timbuctoo.model.PersonNames) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) PersonName(nl.knaw.huygens.timbuctoo.model.PersonName) IOException(java.io.IOException)

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