use of nl.knaw.huygens.timbuctoo.model.PersonName 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()));
}
use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.
the class WwPersonDisplayNameTest method getPersonName.
private String getPersonName(String foreName, String surName) {
PersonName name = new PersonName();
name.addNameComponent(PersonNameComponent.Type.FORENAME, foreName);
name.addNameComponent(PersonNameComponent.Type.SURNAME, surName);
String nameProp;
try {
nameProp = new ObjectMapper().writeValueAsString(name);
} catch (IOException e) {
nameProp = "";
}
return "{\"list\": [" + nameProp + "]}";
}
use of nl.knaw.huygens.timbuctoo.model.PersonName 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()));
}
use of nl.knaw.huygens.timbuctoo.model.PersonName 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);
}
}
use of nl.knaw.huygens.timbuctoo.model.PersonName in project timbuctoo by HuygensING.
the class UriBearingPersonNames method removeComponent.
public void removeComponent(String nameUri, PersonNameComponent.Type nameType, String value) {
if (!nameUris.containsKey(nameUri)) {
LoggerFactory.getLogger(UriBearingPersonNames.class).error("Uri '{}' not known", nameUri);
return;
}
PersonName personName = list.get(nameUris.get(nameUri));
personName.getComponents().remove(new PersonNameComponent(nameType, value));
if (personName.getComponents().isEmpty()) {
list.remove(personName);
Integer indexOfRemoved = nameUris.remove(nameUri);
// reindex the name uri's, because the list will do this automatically.
Map<String, Integer> newNameUris = Maps.newHashMap();
nameUris.forEach((key, val) -> {
if (val > indexOfRemoved) {
val--;
}
newNameUris.put(key, val);
});
nameUris = newNameUris;
}
}
Aggregations