+ private Person getExistingPerson(SimpleExcelTaxonImportState<CONFIG> state, String line, Person newPerson) {
+ String authorsStr = newPerson.getNomenclaturalTitle();
+ if (authorMap.get(authorsStr)!= null){
+ return (Person)authorMap.get(authorsStr);
+ }else{
+ Set<String> includeProperties = new HashSet<>();
+ includeProperties.add("nomenclaturalTitle");
+ List<Person> existingPersons = getAgentService().list(newPerson, includeProperties, null, null, null, null);
+ if (existingPersons.isEmpty()){
+ logger.warn(line+"New person: " + authorsStr);
+ authorMap.put(authorsStr, newPerson);
+ addImportSource(state, newPerson);
+ return newPerson;
+ }else{
+ if(existingPersons.size()>1){
+ existingPersons = findBestMatchingPerson(state, line, existingPersons, authorsStr);
+ if(existingPersons.size()>1){
+ existingPersons = findBestMatchingPerson(state, line, existingPersons, authorsStr);
+ logger.warn(line+"More than 1 person with same matching found for '" + authorsStr + "'. Use arbitrary one.");
+ }else{
+ logger.debug(line+"Found exactly 1 person with same matching for " +authorsStr);
+ }
+ }else{
+ logger.debug(line+"Found exactly 1 person");
+ }
+ Person result = existingPersons.get(0);
+ authorMap.put(authorsStr, result);
+ return result;
+ }
+ }
+ }
+
+ private List<TeamOrPersonBase<?>> findBestMatchingAuthor(SimpleExcelTaxonImportState<CONFIG> state, String line,
+ List<TeamOrPersonBase<?>> existingAuthors, String authorsStr) {
+ Set<TeamOrPersonBase<?>> noTitleCandidates = new HashSet<>();
+ Set<TeamOrPersonBase<?>> sameTitleCandidates = new HashSet<>();
+ for(TeamOrPersonBase<?> author : existingAuthors){
+ if (author.getTitleCache().equals(authorsStr)){
+ sameTitleCandidates.add(author);
+ }
+ }
+ if(!noTitleCandidates.isEmpty()){
+ return new ArrayList<>(noTitleCandidates);
+ }else if(!sameTitleCandidates.isEmpty()){
+ return new ArrayList<>(sameTitleCandidates);
+ }else{
+ return existingAuthors;
+ }
+ }
+
+ private List<Person> findBestMatchingPerson(SimpleExcelTaxonImportState<CONFIG> state, String line,
+ List<Person> existingPersons, String authorsStr) {
+ Set<Person> noTitleCandidates = new HashSet<>();
+ Set<Person> sameTitleCandidates = new HashSet<>();
+ for(Person person : existingPersons){
+ if (person.getTitleCache().equals(authorsStr)){
+ sameTitleCandidates.add(person);
+ }
+ }
+ if(!noTitleCandidates.isEmpty()){
+ return new ArrayList<>(noTitleCandidates);
+ }else if(!sameTitleCandidates.isEmpty()){
+ return new ArrayList<>(sameTitleCandidates);
+ }else{
+ return existingPersons;