specimen import/search changes
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / excel / taxa / NormalExplicitImport.java
index 0e57dcd0deea2efbfc7354e4fca0817eba213716..3c61e6c6ab6a01dec022dbac3b543b80eede2a78 100644 (file)
@@ -50,8 +50,10 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
+import eu.etaxonomy.cdm.model.reference.ReferenceType;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
@@ -139,7 +141,7 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
                } else if(key.equalsIgnoreCase(IMAGE_COLUMN)) {
                        normalExplicitRow.putImage(index, value);
 
-               } else if(key.equalsIgnoreCase(DATE_COLUMN)) {
+               } else if(key.equalsIgnoreCase(DATE_COLUMN) || key.equalsIgnoreCase(YEAR_COLUMN)) {
             normalExplicitRow.setDate(value);
 
         } else if(key.equalsIgnoreCase(FAMILY_COLUMN)) {
@@ -217,7 +219,7 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
                                }
 
                    //taxon
-                               taxonBase = createTaxon(state, rank, taxonNameStr, authorStr, referenceStr, nameStatus);
+                               taxonBase = createTaxon(state, rank, taxonNameStr, authorStr, referenceStr, dateStr, nameStatus);
                        }else{
                                return;
                        }
@@ -561,7 +563,7 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
         * @return
         */
        private TaxonBase createTaxon(TaxonExcelImportState state, Rank rank,
-                       String taxonNameStr, String authorStr, String reference, String nameStatus) {
+                       String taxonNameStr, String authorStr, String reference, String date, String nameStatus) {
                // Create the taxon name object depending on the setting of the nomenclatural code
                // in the configurator (botanical code, zoological code, etc.)
                if (StringUtils.isBlank(taxonNameStr)){
@@ -585,7 +587,7 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
                        logger.info("Matching taxon/synonym found for " + titleCache);
                        return null;
                }else {
-                       taxonBase = createTaxon(state, rank, taxonNameStr, authorStr, reference, nameStatus, nc);
+                       taxonBase = createTaxon(state, rank, taxonNameStr, authorStr, reference, date, nameStatus, nc);
                }
                return taxonBase;
        }
@@ -604,7 +606,7 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
         * @return
         */
        private TaxonBase<?> createTaxon(TaxonExcelImportState state, Rank rank, String taxonNameStr,
-                       String authorStr, String reference, String nameStatus, NomenclaturalCode nc) {
+                       String authorStr, String reference, String date, String nameStatus, NomenclaturalCode nc) {
                TaxonBase<?> taxonBase;
                NonViralName<?> taxonNameBase = null;
                if (nc == NomenclaturalCode.ICVCN){
@@ -628,6 +630,22 @@ public class NormalExplicitImport extends TaxonExcelImporterBase {
                                        taxonNameBase.setAuthorshipCache(authorStr);
                                }
                        }
+                       if (StringUtils.isNotBlank(reference)) {
+
+                           INomenclaturalReference ref = parser.parseReferenceTitle(reference, date, true);
+                           if (ref.getAuthorship() == null){
+                               ref.setAuthorship(taxonNameBase.getCombinationAuthorship());
+                           }
+
+                           if (ref.getAbbrevTitle() == null && !ref.isOfType(ReferenceType.Article)) {
+                    ref.setAbbrevTitle(reference);
+                    ref.setProtectedAbbrevTitleCache(false);
+                }
+
+                ref.setProtectedTitleCache(false);
+
+                           taxonNameBase.setNomenclaturalReference(ref);
+                       }
                }
 
                //Create the taxon