+\r
+ logger.info("end make " + getPluralString() + " ... " + getSuccessString(true));\r
+ return;\r
+ }\r
+\r
+ /**\r
+ * @param authorAndYear\r
+ * @param zooName\r
+ */\r
+ protected void handleAuthorAndYear(String authorAndYear, ZoologicalName zooName, Integer id, GlobisImportState state) {\r
+ if (isBlank(authorAndYear)){\r
+ return;\r
+ }else if ("[Denis & Schifferm\u00FCller], 1775".equals(authorAndYear)){\r
+ handleDenisSchiffermueller(zooName, state);\r
+ return;\r
+ }else{\r
+ try {\r
+ String doubtfulAuthorAndYear = null;\r
+ if(authorAndYear.matches(".+\\,\\s\\[\\d{4}\\].*")){\r
+ doubtfulAuthorAndYear = authorAndYear;\r
+ authorAndYear = authorAndYear.replace("[", "").replace("]", "");\r
+ }\r
+\r
+ parser.parseAuthors(zooName, authorAndYear);\r
+ deduplicateAuthors(zooName, state);\r
+\r
+ if (doubtfulAuthorAndYear != null){\r
+ zooName.setAuthorshipCache(doubtfulAuthorAndYear, true);\r
+ }\r
+\r
+ } catch (StringNotParsableException e) {\r
+ logger.warn("Author could not be parsed: " + authorAndYear + " for id " +id);\r
+ zooName.setAuthorshipCache(authorAndYear, true);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @param zooName\r
+ * @param state\r
+ */\r
+ private void handleDenisSchiffermueller(ZoologicalName zooName,\r
+ GlobisImportState state) {\r
+ String teamStr = "Denis & Schifferm\u00FCller";\r
+ Team team = state.getTeam(teamStr);\r
+ if (team == null){\r
+ team = Team.NewInstance();\r
+ state.putTeam(teamStr, team);\r
+ getAgentService().save(team);\r
+ }\r
+ zooName.setCombinationAuthorship(team);\r
+ zooName.setPublicationYear(1775);\r
+ zooName.setAuthorshipCache("[Denis & Schifferm\u00FCller], 1775", true);\r
+ }\r
+\r
+\r
+ private void deduplicateAuthors(ZoologicalName zooName, GlobisImportState state) {\r
+ zooName.setCombinationAuthorship(getExistingAuthor(zooName.getCombinationAuthorship(), state));\r
+ zooName.setExCombinationAuthorship(getExistingAuthor(zooName.getExCombinationAuthorship(), state));\r
+ zooName.setBasionymAuthorship(getExistingAuthor(zooName.getBasionymAuthorship(), state));\r
+ zooName.setExBasionymAuthorship(getExistingAuthor(zooName.getExBasionymAuthorship(), state));\r
+ }\r
+\r
+ private TeamOrPersonBase<?> getExistingAuthor(INomenclaturalAuthor nomAuthor, GlobisImportState state) {\r
+ TeamOrPersonBase<?> author = (TeamOrPersonBase<?>)nomAuthor;\r
+ if (author == null){\r
+ return null;\r
+ }\r
+ if (author instanceof Person){\r
+ Person person = state.getPerson(author.getTitleCache());\r
+ return saveAndDecide(person, author, author.getTitleCache(), state);\r
+ }else if (author instanceof Team){\r
+ String key = GlobisAuthorImport.makeTeamKey((Team)author, state, getAgentService());\r
+ Team existingTeam = state.getTeam(key);\r
+ if (existingTeam == null){\r
+ Team newTeam = Team.NewInstance();\r
+ for (Person member :((Team) author).getTeamMembers()){\r
+ Person existingPerson = state.getPerson(member.getTitleCache());\r
+ if (existingPerson != null){\r
+ try {\r
+ getAgentService().update(existingPerson);\r
+ } catch (NonUniqueObjectException nuoe){\r
+ // person already exists in\r
+ existingPerson = CdmBase.deproxy(getAgentService().find(existingPerson.getUuid()), Person.class);\r
+ state.putPerson(existingPerson.getTitleCache(), existingPerson);\r
+ } catch (Exception e) {\r
+ throw new RuntimeException (e);\r
+ }\r
+ newTeam.addTeamMember(existingPerson);\r
+//\r
+// logger.warn("newTeam " + newTeam.getId());\r
+ }else{\r
+ newTeam.addTeamMember(member);\r
+ }\r
+ }\r
+ author = newTeam;\r
+ }\r
+\r
+ return saveAndDecide(existingTeam, author, key, state);\r
+ }else{\r
+ logger.warn("Author type not supported: " + author.getClass().getName());\r
+ return author;\r
+ }\r
+ }\r
+\r
+ private TeamOrPersonBase<?> saveAndDecide(TeamOrPersonBase<?> existing, TeamOrPersonBase<?> author, String key, GlobisImportState state) {\r
+ if (existing != null){\r
+ try {\r
+ getAgentService().update(existing);\r
+ } catch (NonUniqueObjectException nuoe){\r
+ // person already exists in\r
+ existing = CdmBase.deproxy(getAgentService().find(existing.getUuid()), TeamOrPersonBase.class);\r
+ putAgent(existing, key, state);\r
+ } catch (Exception e) {\r
+ throw new RuntimeException (e);\r
+ }\r
+ return existing;\r
+ }else{\r
+ getAgentService().save(author);\r
+ putAgent(author, key, state);\r
+ return author;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @param author\r
+ * @param key\r
+ * @param state\r
+ */\r
+ private void putAgent(TeamOrPersonBase<?> agent, String key, GlobisImportState state) {\r
+ if (agent instanceof Team){\r
+ state.putTeam(key, (Team)agent);\r
+ }else{\r
+ state.putPerson(key, (Person)agent);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * @param state\r
+ * @param countryStr\r
+ * @return\r
+ */\r
+ protected NamedArea getCountry(GlobisImportState state, String countryStr) {\r
+ NamedArea country = Country.getCountryByLabel(countryStr);\r
+ if (country == null){\r
+ try {\r
+ country = state.getTransformer().getNamedAreaByKey(countryStr);\r
+ } catch (UndefinedTransformerMethodException e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ return country;\r