+ return name;\r
+ }\r
+\r
+\r
+ /**\r
+ * General method to handle references used for multiple attributes.\r
+ * @param item\r
+ * @param resultList\r
+ * @param idTerm\r
+ * @param strTerm\r
+ * @param idIsInternal\r
+ * @return\r
+ */\r
+ private MappedCdmBase<Reference> getReference(CsvStreamItem item, List<MappedCdmBase> resultList, TermUri idTerm, TermUri strTerm, boolean idIsInternal) {\r
+ Reference<?> newRef = null;\r
+ Reference<?> sourceCitation = null;\r
+ \r
+ MappedCdmBase<Reference> result = null;\r
+ if (exists(idTerm, item) || exists(strTerm, item)){\r
+ String refId = CdmUtils.Nz(item.get(idTerm)).trim();\r
+ String refStr = CdmUtils.Nz(item.get(strTerm)).trim();\r
+ if (StringUtils.isNotBlank(refId)){\r
+ List<Reference> references = state.get(idTerm.toString(), refId, Reference.class);\r
+ if (references.size() == 0){\r
+ if (! idIsInternal){\r
+ //references should already exist in store if not linking to external links like URLs\r
+ String message = "External namePublishedInIDs are not yet supported";\r
+ fireWarningEvent(message, item, 4);\r
+ }else{\r
+ newRef = ReferenceFactory.newGeneric(); //TODO handle other types if possible\r
+ newRef.addSource(refId, idTerm.toString(), sourceCitation, null);\r
+ MappedCdmBase<Reference> idResult = new MappedCdmBase<Reference>(idTerm, refId, newRef);\r
+ resultList.add(idResult);\r
+ }\r
+ }else{\r
+ //TODO handle list.size > 1 , do we need a list here ?\r
+ result = new MappedCdmBase<Reference>(idTerm, refId , references.get(0));\r
+ }\r
+ }\r
+ if (result == null){\r
+ List<Reference> nomRefs = state.get(strTerm.toString(), refStr, Reference.class);\r
+ if (nomRefs.size() > 0){\r
+ //TODO handle list.size > 1 , do we need a list here ?\r
+ result = new MappedCdmBase<Reference>(strTerm, refStr , nomRefs.get(0));\r
+ }else{\r
+ // new Reference\r
+ if (newRef == null){\r
+ newRef = ReferenceFactory.newGeneric(); //TODO handle other types if possible\r
+ }\r
+ newRef.setTitleCache(refStr, true);\r
+ //TODO distinguish available year, authorship, etc. if\r
+ result = new MappedCdmBase<Reference>(strTerm, refStr, newRef);\r
+ resultList.add(result);\r
+ }\r
+ }\r
+ }\r
+ return result;\r
+ }\r
+\r
+\r
+ //TODO we may configure in configuration that scientific name never includes Authorship\r
+ private void checkAuthorship(TaxonNameBase nameBase, CsvStreamItem item) {\r
+ if (!nameBase.isInstanceOf(NonViralName.class)){\r
+ return;\r
+ }\r
+ NonViralName<?> nvName = CdmBase.deproxy(nameBase, NonViralName.class); \r
+ String strAuthors = getValue(item, TermUri.DWC_SCIENTIFIC_NAME_AUTHORS);\r
+ \r
+ if (! nvName.isProtectedTitleCache()){\r
+ if (StringUtils.isBlank(nvName.getAuthorshipCache())){\r
+ if (nvName.isInstanceOf(BotanicalName.class) || nvName.isInstanceOf(ZoologicalName.class)){\r
+ try {\r
+ parser.parseAuthors(nvName, strAuthors);\r
+ } catch (StringNotParsableException e) {\r
+ nvName.setAuthorshipCache(strAuthors);\r
+ } \r
+ }else{\r
+ nvName.setAuthorshipCache(strAuthors);\r
+ }\r
+ //TODO throw warning (scientific name should always include authorship) by DwC definition\r
+ }\r
+ }\r
+ \r