fix merge problems
authorKatja Luther <k.luther@bgbm.org>
Tue, 19 Jul 2016 13:46:35 +0000 (15:46 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 6 Oct 2016 15:02:08 +0000 (17:02 +0200)
21 files changed:
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenDataHolder.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportBase.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportConfiguratorBase.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportStateBase.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/UnitsGatheringEvent.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206DataHolder.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportConfigurator.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportReport.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206ImportState.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206XMLFieldGetter.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdImportUtility.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdParseUtility.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdPersonParser.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/molecular/AbcdDnaParser.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/molecular/AbcdGgbnParser.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/gbif/in/GbifDataHolder.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/gbif/in/GbifImport.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/gbif/in/GbifImportConfigurator.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/gbif/in/GbifImportReport.java [changed mode: 0755->0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/gbif/in/GbifImportState.java [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index 0ea12df..044657b
@@ -1,60 +1,60 @@
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen;
-
-import java.util.HashMap;
-import java.util.List;
-
-/**
- * @author k.luther
- * @date 18.07.2016
- *
- */
-public class SpecimenDataHolder {
-
-    private String nomenclatureCode;
-    private List<HashMap<String, String>> atomisedIdentificationList;
-
-
-
-    /**
-     * @return the nomenclatureCode
-     */
-    public String getNomenclatureCode() {
-        return nomenclatureCode;
-    }
-
-
-
-    /**
-     * @param nomenclatureCode the nomenclatureCode to set
-     */
-    public void setNomenclatureCode(String nomenclatureCode) {
-        this.nomenclatureCode = nomenclatureCode;
-    }
-
-
-
-    /**
-     * @return the atomisedIdentificationList
-     */
-    public List<HashMap<String, String>> getAtomisedIdentificationList() {
-        return atomisedIdentificationList;
-    }
-
-
-
-    /**
-     * @param atomisedIdentificationList the atomisedIdentificationList to set
-     */
-    public void setAtomisedIdentificationList(List<HashMap<String, String>> atomisedIdentificationList) {
-        this.atomisedIdentificationList = atomisedIdentificationList;
-    }
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen;\r
+\r
+import java.util.HashMap;\r
+import java.util.List;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 18.07.2016\r
+ *\r
+ */\r
+public class SpecimenDataHolder {\r
+\r
+    private String nomenclatureCode;\r
+    private List<HashMap<String, String>> atomisedIdentificationList;\r
+\r
+\r
+\r
+    /**\r
+     * @return the nomenclatureCode\r
+     */\r
+    public String getNomenclatureCode() {\r
+        return nomenclatureCode;\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * @param nomenclatureCode the nomenclatureCode to set\r
+     */\r
+    public void setNomenclatureCode(String nomenclatureCode) {\r
+        this.nomenclatureCode = nomenclatureCode;\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * @return the atomisedIdentificationList\r
+     */\r
+    public List<HashMap<String, String>> getAtomisedIdentificationList() {\r
+        return atomisedIdentificationList;\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * @param atomisedIdentificationList the atomisedIdentificationList to set\r
+     */\r
+    public void setAtomisedIdentificationList(List<HashMap<String, String>> atomisedIdentificationList) {\r
+        this.atomisedIdentificationList = atomisedIdentificationList;\r
+    }\r
+}\r
index 801ff9cb7c10aec8f3cf3fa1deb9930bc4b86027..8c6989efd55f7db0a40133df550f6d42c6f3e70e 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 package eu.etaxonomy.cdm.io.specimen;
 
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Set;
+
 import org.apache.log4j.Logger;
 
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
+import eu.etaxonomy.cdm.api.service.pager.Pager;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.io.common.CdmImportBase;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator;
-import eu.etaxonomy.cdm.io.common.ImportStateBase;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
+import eu.etaxonomy.cdm.model.agent.AgentBase;
+import eu.etaxonomy.cdm.model.agent.Team;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.LanguageString;
+import eu.etaxonomy.cdm.model.description.DescriptionBase;
+import eu.etaxonomy.cdm.model.name.BacterialName;
+import eu.etaxonomy.cdm.model.name.BotanicalName;
+import eu.etaxonomy.cdm.model.name.CultivarPlantName;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+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.name.ZoologicalName;
+import eu.etaxonomy.cdm.model.occurrence.Collection;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.persistence.query.MatchMode;
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
+import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 
 
 /**
  * @author p.kelbert
  * @created 20.10.2008
  */
-public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STATE extends ImportStateBase>  extends CdmImportBase<CONFIG, STATE> {
+public abstract class SpecimenImportBase<CONFIG extends IImportConfigurator, STATE extends SpecimenImportStateBase>  extends CdmImportBase<CONFIG, STATE> {
+
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(SpecimenImportBase.class);
+       protected final boolean DEBUG = true;
+
+       @Override
+    protected abstract void doInvoke(STATE state);
+
+       /**
+        * Handle a single unit
+        * @param state
+        * @param item
+        */
+       @SuppressWarnings("rawtypes")
+       protected abstract void handleSingleUnit(STATE state, Object item) ;
+
+
+
+       protected TaxonNameBase<?, ?> getOrCreateTaxonName(String scientificName, Rank rank, boolean preferredFlag, STATE state, int unitIndexInAbcdFile){
+        TaxonNameBase<?, ?> taxonName = null;
+        SpecimenImportConfiguratorBase config = (SpecimenImportConfiguratorBase) state.getConfig();
+
+        //check atomised name data for rank
+        //new name will be created
+        NonViralName<?> atomisedTaxonName = null;
+        if (rank==null && unitIndexInAbcdFile>=0 && (state.getDataHolder().getAtomisedIdentificationList() != null || state.getDataHolder().getAtomisedIdentificationList().size() > 0)) {
+            atomisedTaxonName = setTaxonNameByType(state.getDataHolder().getAtomisedIdentificationList().get(unitIndexInAbcdFile), scientificName, state);
+            if(atomisedTaxonName!=null){
+                rank = atomisedTaxonName.getRank();
+            }
+        }
+        if(config.isReuseExistingTaxaWhenPossible()){
+            NonViralName<?> parsedName = atomisedTaxonName;
+            if(parsedName==null){
+                parsedName = parseScientificName(scientificName, state, state.getReport());
+            }
+            if(config.isIgnoreAuthorship() && parsedName!=null && preferredFlag){
+                // do not ignore authorship for non-preferred names because they need
+                // to be created for the determination history
+                String nameCache = parsedName.getNameCache();
+                List<NonViralName> names = getNameService().findNamesByNameCache(nameCache, MatchMode.EXACT, null);
+                taxonName = getBestMatchingName(scientificName, new ArrayList<TaxonNameBase>(names), state);
+            }
+            else {
+                //search for existing names
+                List<TaxonNameBase> names = getNameService().listByTitle(TaxonNameBase.class, scientificName, MatchMode.EXACT, null, null, null, null, null);
+                taxonName = getBestMatchingName(scientificName, names, state);
+                //still nothing found -> try with the atomised name full title cache
+                if(taxonName==null && atomisedTaxonName!=null){
+                    names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getFullTitleCache(), MatchMode.EXACT, null, null, null, null, null);
+                    taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
+                    //still nothing found -> try with the atomised name title cache
+                    if(taxonName==null){
+                        names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getTitleCache(), MatchMode.EXACT, null, null, null, null, null);
+                        taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
+                    }
+                }
+            }
+        }
+
+        if(taxonName==null && atomisedTaxonName!=null){
+            taxonName = atomisedTaxonName;
+            state.getReport().addName(taxonName);
+            logger.info("Created new taxon name "+taxonName);
+            if(taxonName.hasProblem()){
+                state.getReport().addInfoMessage(String.format("Created %s with parsing problems", taxonName));
+            }
+            if(!atomisedTaxonName.getTitleCache().equals(scientificName)){
+                state.getReport().addInfoMessage(String.format("Taxon %s was parsed as %s", scientificName, atomisedTaxonName.getTitleCache()));
+            }
+        }
+        else if(taxonName==null){
+            //create new taxon name
+            taxonName = NonViralName.NewInstance(rank);
+            taxonName.setFullTitleCache(scientificName,true);
+            taxonName.setTitleCache(scientificName, true);
+            state.getReport().addName(taxonName);
+            logger.info("Created new taxon name "+taxonName);
+        }
+        save(taxonName, state);
+        return taxonName;
+    }
+
+        protected TaxonNameBase<?, ?> getBestMatchingName(String scientificName, java.util.Collection<TaxonNameBase> names, STATE state){
+               List<TaxonNameBase> namesWithAcceptedTaxa = new ArrayList<TaxonNameBase>();
+               for (TaxonNameBase name : names) {
+                   if(!name.getTaxa().isEmpty()){
+                       namesWithAcceptedTaxa.add(name);
+                   }
+               }
+               String message = "More than one taxon name was found for "+scientificName+"!";
+               //check for names with accepted taxa
+               if(namesWithAcceptedTaxa.size()>0){
+                   if(namesWithAcceptedTaxa.size()>1){
+                       state.getReport().addInfoMessage(message);
+                       logger.warn(message);
+                       return null;
+                   }
+                   return namesWithAcceptedTaxa.iterator().next();
+               }
+               //no names with accepted taxa found -> check accepted taxa of synonyms
+               List<Taxon> taxaFromSynonyms = new ArrayList<Taxon>();
+               for (TaxonNameBase name : names) {
+                   Set<TaxonBase> taxonBases = name.getTaxonBases();
+                   for (TaxonBase taxonBase : taxonBases) {
+                       if(taxonBase.isInstanceOf(Synonym.class)){
+                           Synonym synonym = HibernateProxyHelper.deproxy(taxonBase, Synonym.class);
+                           taxaFromSynonyms.addAll(synonym.getAcceptedTaxa());
+                       }
+                   }
+               }
+               if(taxaFromSynonyms.size()>0){
+                   if(taxaFromSynonyms.size()>1){
+                       state.getReport().addInfoMessage(message);
+                       logger.warn(message);
+                       return null;
+                   }
+                   return taxaFromSynonyms.iterator().next().getName();
+               }
+               return null;
+           }
+        /**
+            * Parse automatically the scientific name
+            * @param scientificName the scientific name to parse
+            * @param state the current import state
+            * @param report the import report
+            * @return a parsed name
+            */
+           protected NonViralName<?> parseScientificName(String scientificName, STATE state, SpecimenImportReport report) {
+               NonViralNameParserImpl nvnpi = NonViralNameParserImpl.NewInstance();
+               NonViralName<?> taxonName = null;
+               boolean problem = false;
+
+               if(DEBUG){
+                   logger.info("parseScientificName " + state.getDataHolder().getNomenclatureCode().toString());
+               }
+
+               if (state.getDataHolder().getNomenclatureCode().toString().equals("Zoological") || state.getDataHolder().getNomenclatureCode().toString().contains("ICZN")) {
+                   taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICZN, null);
+                   if (taxonName.hasProblem()) {
+                       problem = true;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().toString().equals("Botanical") || state.getDataHolder().getNomenclatureCode().toString().contains("ICBN")) {
+                   taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNAFP, null);
+                   if (taxonName.hasProblem()) {
+                       problem = true;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().toString().equals("Bacterial") || state.getDataHolder().getNomenclatureCode().toString().contains("ICBN")) {
+                   taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNB, null);
+                   if (taxonName.hasProblem()) {
+                       problem = true;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().toString().equals("Cultivar") || state.getDataHolder().getNomenclatureCode().toString().contains("ICNCP")) {
+                   taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNCP, null);
+                   if (taxonName.hasProblem()) {
+                       problem = true;
+                   }
+               }
+               if (problem) {
+                   String message = String.format("Parsing problems for %s", scientificName);
+                   if(taxonName!=null){
+                       for (ParserProblem parserProblem : taxonName.getParsingProblems()) {
+                           message += "\n\t- "+parserProblem;
+                       }
+                   }
+                   report.addInfoMessage(message);
+                   logger.info(message);
+               }
+               return taxonName;
+
+           }
+
+           /**
+            * Create the name without automatic parsing, either because it failed, or because the user deactivated it.
+            * The name is built upon the ABCD fields
+            * @param atomisedMap : the ABCD atomised fields
+            * @param fullName : the full scientific name
+            * @param state
+            * @return the corresponding Botanical or Zoological or... name
+            */
+           protected NonViralName<?> setTaxonNameByType(
+                   HashMap<String, String> atomisedMap, String fullName, STATE state) {
+               boolean problem = false;
+               if(DEBUG) {
+                   logger.info("settaxonnamebytype " + state.getDataHolder().getNomenclatureCode().toString());
+               }
+
+               if (state.getDataHolder().getNomenclatureCode().equals("Zoological")) {
+                   NonViralName<ZoologicalName> taxonName = ZoologicalName.NewInstance(null);
+                   taxonName.setFullTitleCache(fullName, true);
+                   taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
+                   taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
+                   taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap,"SpeciesEpithet")));
+                   taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap,"SubspeciesEpithet")));
+
+                   if (taxonName.getGenusOrUninomial() != null){
+                       taxonName.setRank(Rank.GENUS());
+                   }
+
+                   if (taxonName.getInfraGenericEpithet() != null){
+                       taxonName.setRank(Rank.SUBGENUS());
+                   }
+
+                   if (taxonName.getSpecificEpithet() != null){
+                       taxonName.setRank(Rank.SPECIES());
+                   }
+
+                   if (taxonName.getInfraSpecificEpithet() != null){
+                       taxonName.setRank(Rank.SUBSPECIES());
+                   }
+
+                   Team team = null;
+                   if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
+                       team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
+                   }
+                   else {
+                       if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
+                           team = Team.NewInstance();
+                           team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
+                       }
+                   }
+                   if (team != null) {
+                       taxonName.setBasionymAuthorship(team);
+                   }
+                   else {
+                       if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
+                           taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
+                       }
+                       else if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
+                           taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamAndYear"));
+                       }
+                   }
+                   if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
+                       team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
+                       taxonName.setCombinationAuthorship(team);
+                   }
+                   if (taxonName.hasProblem()) {
+                       logger.info("pb ICZN");
+                       problem = true;
+                   }
+                   else {
+                       return taxonName;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().equals("Botanical")) {
+                   BotanicalName taxonName = (BotanicalName) parseScientificName(fullName, state, state.getReport());
+                   if (taxonName != null){
+                       return taxonName;
+                   }
+                   else{
+                       taxonName = BotanicalName.NewInstance(null);
+                   }
+                   taxonName.setFullTitleCache(fullName, true);
+                   taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
+                   taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "FirstEpithet")));
+                   taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "InfraSpeEpithet")));
+                   try {
+                       taxonName.setRank(Rank.getRankByName(getFromMap(atomisedMap, "Rank")));
+                   } catch (Exception e) {
+                       if (taxonName.getInfraSpecificEpithet() != null){
+                           taxonName.setRank(Rank.SUBSPECIES());
+                       }
+                       else if (taxonName.getSpecificEpithet() != null){
+                           taxonName.setRank(Rank.SPECIES());
+                       }
+                       else if (taxonName.getInfraGenericEpithet() != null){
+                           taxonName.setRank(Rank.SUBGENUS());
+                       }
+                       else if (taxonName.getGenusOrUninomial() != null){
+                           taxonName.setRank(Rank.GENUS());
+                       }
+                   }
+                   Team team = null;
+                   if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
+                       team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
+                       taxonName.setBasionymAuthorship(team);
+                   }
+                   if (getFromMap(atomisedMap, "AuthorTeam") != null) {
+                       team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "AuthorTeam"), true);
+                       taxonName.setCombinationAuthorship(team);
+                   }
+                   if (team == null) {
+                       if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
+                           taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
+                       }
+                       else if (getFromMap(atomisedMap, "AuthorTeam") != null) {
+                           taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeam"));
+                       }
+                   }
+                   if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
+                       team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
+                       taxonName.setCombinationAuthorship(team);
+                   }
+                   if (taxonName.hasProblem()) {
+                       logger.info("pb ICBN");
+                       problem = true;
+                   }
+                   else {
+                       return taxonName;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().equals("Bacterial")) {
+                   NonViralName<BacterialName> taxonName = BacterialName.NewInstance(null);
+                   taxonName.setFullTitleCache(fullName, true);
+                   taxonName.setGenusOrUninomial(getFromMap(atomisedMap, "Genus"));
+                   taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
+                   taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "Species")));
+                   taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "SubspeciesEpithet")));
+
+                   if (taxonName.getGenusOrUninomial() != null){
+                       taxonName.setRank(Rank.GENUS());
+                   }
+                   else if (taxonName.getInfraGenericEpithet() != null){
+                       taxonName.setRank(Rank.SUBGENUS());
+                   }
+                   else if (taxonName.getSpecificEpithet() != null){
+                       taxonName.setRank(Rank.SPECIES());
+                   }
+                   else if (taxonName.getInfraSpecificEpithet() != null){
+                       taxonName.setRank(Rank.SUBSPECIES());
+                   }
+
+                   if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
+                       Team team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
+                       taxonName.setCombinationAuthorship(team);
+                   }
+                   if (getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear") != null) {
+                       Team team = Team.NewInstance();
+                       team.setTitleCache(getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear"), true);
+                       taxonName.setBasionymAuthorship(team);
+                   }
+                   if (taxonName.hasProblem()) {
+                       logger.info("pb ICNB");
+                       problem = true;
+                   }
+                   else {
+                       return taxonName;
+                   }
+               }
+               else if (state.getDataHolder().getNomenclatureCode().equals("Cultivar")) {
+                   CultivarPlantName taxonName = CultivarPlantName.NewInstance(null);
+
+                   if (taxonName.hasProblem()) {
+                       logger.info("pb ICNCP");
+                       problem = true;
+                   }
+                   else {
+                       return taxonName;
+                   }
+                   return taxonName;
+               }
+
+               if (problem) {
+                   logger.info("Problem im setTaxonNameByType ");
+                   NonViralName<?> taxonName = NonViralName.NewInstance(null);
+                   taxonName.setFullTitleCache(fullName, true);
+                   return taxonName;
+               }
+               NonViralName<?> tn = NonViralName.NewInstance(null);
+               return tn;
+           }
+
+           /**
+            * Get a formated string from a hashmap
+            * @param atomisedMap
+            * @param key
+            * @return
+            */
+           private String getFromMap(HashMap<String, String> atomisedMap, String key) {
+               String value = null;
+               if (atomisedMap.containsKey(key)) {
+                   value = atomisedMap.get(key);
+               }
+
+               try {
+                   if (value != null && key.matches(".*Year.*")) {
+                       value = value.trim();
+                       if (value.matches("[a-z A-Z ]*[0-9]{4}$")) {
+                           String tmp = value.split("[0-9]{4}$")[0];
+                           int year = Integer.parseInt(value.split(tmp)[1]);
+                           if (year >= 1752) {
+                               value = tmp;
+                           }
+                           else {
+                               value = null;
+                           }
+                       }
+                       else {
+                           value = null;
+                       }
+                   }
+               }
+               catch (Exception e) {
+                   value = null;
+               }
+               return value;
+           }
+
+           /**
+            * Very fast and dirty implementation to allow handling of transient objects as described in
+            * https://dev.e-taxonomy.eu/trac/ticket/3726
+            *
+            * Not yet complete.
+            *
+            * @param cdmBase
+            * @param state
+            */
+           protected void save(CdmBase cdmBase, SpecimenImportStateBase state) {
+               ICdmApplicationConfiguration cdmRepository = state.getConfig().getCdmAppController();
+               if (cdmRepository == null){
+                   cdmRepository = this;
+               }
+
+               if (cdmBase.isInstanceOf(LanguageString.class)){
+                   cdmRepository.getTermService().saveLanguageData(CdmBase.deproxy(cdmBase, LanguageString.class));
+               }else if (cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
+                   cdmRepository.getOccurrenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, SpecimenOrObservationBase.class));
+               }else if (cdmBase.isInstanceOf(Reference.class)){
+                   cdmRepository.getReferenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, Reference.class));
+               }else if (cdmBase.isInstanceOf(Classification.class)){
+                   cdmRepository.getClassificationService().saveOrUpdate(CdmBase.deproxy(cdmBase, Classification.class));
+               }else if (cdmBase.isInstanceOf(AgentBase.class)){
+                   cdmRepository.getAgentService().saveOrUpdate(CdmBase.deproxy(cdmBase, AgentBase.class));
+               }else if (cdmBase.isInstanceOf(Collection.class)){
+                   cdmRepository.getCollectionService().saveOrUpdate(CdmBase.deproxy(cdmBase, Collection.class));
+               }else if (cdmBase.isInstanceOf(DescriptionBase.class)){
+                   cdmRepository.getDescriptionService().saveOrUpdate(CdmBase.deproxy(cdmBase, DescriptionBase.class));
+               }else if (cdmBase.isInstanceOf(TaxonBase.class)){
+                   cdmRepository.getTaxonService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonBase.class));
+               }else if (cdmBase.isInstanceOf(TaxonNameBase.class)){
+                   cdmRepository.getNameService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonNameBase.class));
+               }else{
+                   throw new IllegalArgumentException("Class not supported in save method: " + CdmBase.deproxy(cdmBase, CdmBase.class).getClass().getSimpleName());
+               }
+
+           }
+
+
+           protected SpecimenOrObservationBase findExistingSpecimen(String unitId, SpecimenImportStateBase state){
+               ICdmApplicationConfiguration cdmAppController = state.getConfig().getCdmAppController();
+               if(cdmAppController==null){
+                   cdmAppController = this;
+               }
+               FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
+               config.setSignificantIdentifier(unitId);
+               Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
+               if(!existingSpecimens.getRecords().isEmpty()){
+                   if(existingSpecimens.getRecords().size()==1){
+                       return existingSpecimens.getRecords().iterator().next();
+                   }
+               }
+               return null;
+           }
+
+           protected abstract void importAssociatedUnits(STATE state, Object item, DerivedUnitFacade derivedUnitFacade);
+
 
-       protected abstract void doInvoke(STATE state);
 
 }
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index 6dc0d06..9239537
@@ -1,92 +1,92 @@
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen;
-
-import java.util.Map;
-
-import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
-import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
-import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
-import eu.etaxonomy.cdm.model.agent.Person;
-import eu.etaxonomy.cdm.model.agent.Team;
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public abstract class SpecimenImportConfiguratorBase<STATE extends SpecimenImportStateBase, InputStream>  extends ImportConfiguratorBase<STATE, InputStream> {
-
-    private boolean ignoreImportOfExistingSpecimen;
-    private boolean reuseExistingTaxaWhenPossible;
-    private Map<String, Team> teams;
-    private Map<String, Person> persons;
-    private boolean ignoreAuthorship;
-    private boolean removeCountryFromLocalityText;
-    private OccurenceQuery query ;
-
-    /**
-     * @param transformer
-     */
-    public SpecimenImportConfiguratorBase(IInputTransformer transformer) {
-        super(transformer);
-        // TODO Auto-generated constructor stub
-    }
-
-    /**
-     * @return
-     */
-    public boolean isReuseExistingTaxaWhenPossible() {
-
-        return reuseExistingTaxaWhenPossible;
-    }
-
-    /**
-     * @param titleCacheTeam
-     */
-    public void setTeams(Map<String, Team> titleCacheTeam) {
-       this.teams  = titleCacheTeam;
-
-    }
-
-    /**
-     * @param titleCachePerson
-     */
-    public void setPersons(Map<String, Person> titleCachePerson) {
-        this.persons = titleCachePerson;
-    }
-
-    /**
-     * @return
-     */
-    public boolean isIgnoreAuthorship() {
-        return ignoreAuthorship;
-    }
-
-    /**
-     * @return
-     */
-    public boolean isRemoveCountryFromLocalityText() {
-        return removeCountryFromLocalityText;
-    }
-
-    public boolean isIgnoreImportOfExistingSpecimens(){
-        return ignoreImportOfExistingSpecimen;
-    }
-
-    public OccurenceQuery getOccurenceQuery(){
-        return query;
-    }
-
-    public void setOccurenceQuery(OccurenceQuery query){
-        this.query = query;
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen;\r
+\r
+import java.util.Map;\r
+\r
+import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;\r
+import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;\r
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public abstract class SpecimenImportConfiguratorBase<STATE extends SpecimenImportStateBase, InputStream>  extends ImportConfiguratorBase<STATE, InputStream> {\r
+\r
+    private boolean ignoreImportOfExistingSpecimen;\r
+    private boolean reuseExistingTaxaWhenPossible;\r
+    private Map<String, Team> teams;\r
+    private Map<String, Person> persons;\r
+    private boolean ignoreAuthorship;\r
+    private boolean removeCountryFromLocalityText;\r
+    private OccurenceQuery query ;\r
+\r
+    /**\r
+     * @param transformer\r
+     */\r
+    public SpecimenImportConfiguratorBase(IInputTransformer transformer) {\r
+        super(transformer);\r
+        // TODO Auto-generated constructor stub\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    public boolean isReuseExistingTaxaWhenPossible() {\r
+\r
+        return reuseExistingTaxaWhenPossible;\r
+    }\r
+\r
+    /**\r
+     * @param titleCacheTeam\r
+     */\r
+    public void setTeams(Map<String, Team> titleCacheTeam) {\r
+       this.teams  = titleCacheTeam;\r
+\r
+    }\r
+\r
+    /**\r
+     * @param titleCachePerson\r
+     */\r
+    public void setPersons(Map<String, Person> titleCachePerson) {\r
+        this.persons = titleCachePerson;\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    public boolean isIgnoreAuthorship() {\r
+        return ignoreAuthorship;\r
+    }\r
+\r
+    /**\r
+     * @return\r
+     */\r
+    public boolean isRemoveCountryFromLocalityText() {\r
+        return removeCountryFromLocalityText;\r
+    }\r
+\r
+    public boolean isIgnoreImportOfExistingSpecimens(){\r
+        return ignoreImportOfExistingSpecimen;\r
+    }\r
+\r
+    public OccurenceQuery getOccurenceQuery(){\r
+        return query;\r
+    }\r
+\r
+    public void setOccurenceQuery(OccurenceQuery query){\r
+        this.query = query;\r
+    }\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index eeaa833..d890b4b
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen;
-
-import org.springframework.transaction.TransactionStatus;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.io.common.CdmImportBase;
-import eu.etaxonomy.cdm.io.common.ImportStateBase;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.model.taxon.Classification;
-
-/**
- * @author k.luther
- * @param <CONFIG>
- * @date 15.07.2016
- *
- */
-public abstract class SpecimenImportStateBase<CONFIG extends SpecimenImportConfiguratorBase, STATE extends SpecimenImportStateBase> extends ImportStateBase<CONFIG , CdmImportBase<CONFIG , STATE >>{
-
-
-    private TransactionStatus tx;
-
-    private ICdmApplicationConfiguration cdmRepository;
-    private Classification classification = null;
-    private Classification defaultClassification = null;
-    private Reference ref = null;
-
-    private TaxonDescription descriptionGroup = null;
-    private DerivedUnit derivedUnitBase;
-
-    private SpecimenImportReport report;
-
-    private SpecimenDataHolder dataHolder;
-
-
-    /**
-     * @param config
-     */
-    protected SpecimenImportStateBase(CONFIG config) {
-        super(config);
-        // TODO Auto-generated constructor stub
-    }
-
-    /* -----Getter/Setter ---*/
-
-    public TransactionStatus getTx() {
-        return tx;
-    }
-
-    public void setTx(TransactionStatus tx) {
-        this.tx = tx;
-    }
-
-    public ICdmApplicationConfiguration getCdmRepository() {
-        return cdmRepository;
-    }
-
-    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {
-        this.cdmRepository = cdmRepository;
-    }
-
-    public Classification getClassification() {
-        return classification;
-    }
-
-    public void setClassification(Classification classification) {
-        this.classification = classification;
-    }
-
-    public Classification getDefaultClassification() {
-        if(defaultClassification==null){
-            final String defaultClassificationAbcd = "Default Classification ABCD";
-            for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){
-                if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)
-                        && classif.getCitation()!=null && classif.getCitation().equals(getRef())) {
-                    defaultClassification = classif;
-                    break;
-                }
-            }
-            if(defaultClassification==null){
-                defaultClassification = Classification.NewInstance(defaultClassificationAbcd);
-                cdmRepository.getClassificationService().save(defaultClassification);
-            }
-        }
-        return defaultClassification;
-    }
-
-    public void setDefaultClassification(Classification defaultClassification) {
-        this.defaultClassification = defaultClassification;
-    }
-
-    public Reference getRef() {
-        return ref;
-    }
-
-    public void setRef(Reference ref) {
-        this.ref = ref;
-    }
-
-    public TaxonDescription getDescriptionGroup() {
-        return descriptionGroup;
-    }
-
-    public void setDescriptionGroup(TaxonDescription descriptionGroup) {
-        this.descriptionGroup = descriptionGroup;
-    }
-
-    public DerivedUnit getDerivedUnitBase() {
-        return derivedUnitBase;
-    }
-
-    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
-        this.derivedUnitBase = derivedUnitBase;
-    }
-
-    /**
-     * @return the report
-     */
-    public SpecimenImportReport getReport() {
-        return report;
-    }
-
-    /**
-     * @param report the report to set
-     */
-    public void setReport(SpecimenImportReport report) {
-        this.report = report;
-    }
-
-    /**
-     *
-     */
-    public abstract void reset() ;
-
-    /**
-     * @return the dataHolder
-     */
-    public SpecimenDataHolder getDataHolder() {
-        return dataHolder;
-    }
-
-    /**
-     * @param dataHolder the dataHolder to set
-     */
-    public void setDataHolder(SpecimenDataHolder dataHolder) {
-        this.dataHolder = dataHolder;
-    }
-
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen;\r
+\r
+import org.springframework.transaction.TransactionStatus;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.io.common.CdmImportBase;\r
+import eu.etaxonomy.cdm.io.common.ImportStateBase;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;\r
+import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.taxon.Classification;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @param <CONFIG>\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public abstract class SpecimenImportStateBase<CONFIG extends SpecimenImportConfiguratorBase, STATE extends SpecimenImportStateBase> extends ImportStateBase<CONFIG , CdmImportBase<CONFIG , STATE >>{\r
+\r
+\r
+    private TransactionStatus tx;\r
+\r
+    private ICdmApplicationConfiguration cdmRepository;\r
+    private Classification classification = null;\r
+    private Classification defaultClassification = null;\r
+    private Reference ref = null;\r
+\r
+    private TaxonDescription descriptionGroup = null;\r
+    private DerivedUnit derivedUnitBase;\r
+\r
+    private SpecimenImportReport report;\r
+\r
+    private SpecimenDataHolder dataHolder;\r
+\r
+\r
+    /**\r
+     * @param config\r
+     */\r
+    protected SpecimenImportStateBase(CONFIG config) {\r
+        super(config);\r
+        // TODO Auto-generated constructor stub\r
+    }\r
+\r
+    /* -----Getter/Setter ---*/\r
+\r
+    public TransactionStatus getTx() {\r
+        return tx;\r
+    }\r
+\r
+    public void setTx(TransactionStatus tx) {\r
+        this.tx = tx;\r
+    }\r
+\r
+    public ICdmApplicationConfiguration getCdmRepository() {\r
+        return cdmRepository;\r
+    }\r
+\r
+    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {\r
+        this.cdmRepository = cdmRepository;\r
+    }\r
+\r
+    public Classification getClassification() {\r
+        return classification;\r
+    }\r
+\r
+    public void setClassification(Classification classification) {\r
+        this.classification = classification;\r
+    }\r
+\r
+    public Classification getDefaultClassification() {\r
+        if(defaultClassification==null){\r
+            final String defaultClassificationAbcd = "Default Classification ABCD";\r
+            for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){\r
+                if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)\r
+                        && classif.getCitation()!=null && classif.getCitation().equals(getRef())) {\r
+                    defaultClassification = classif;\r
+                    break;\r
+                }\r
+            }\r
+            if(defaultClassification==null){\r
+                defaultClassification = Classification.NewInstance(defaultClassificationAbcd);\r
+                cdmRepository.getClassificationService().save(defaultClassification);\r
+            }\r
+        }\r
+        return defaultClassification;\r
+    }\r
+\r
+    public void setDefaultClassification(Classification defaultClassification) {\r
+        this.defaultClassification = defaultClassification;\r
+    }\r
+\r
+    public Reference getRef() {\r
+        return ref;\r
+    }\r
+\r
+    public void setRef(Reference ref) {\r
+        this.ref = ref;\r
+    }\r
+\r
+    public TaxonDescription getDescriptionGroup() {\r
+        return descriptionGroup;\r
+    }\r
+\r
+    public void setDescriptionGroup(TaxonDescription descriptionGroup) {\r
+        this.descriptionGroup = descriptionGroup;\r
+    }\r
+\r
+    public DerivedUnit getDerivedUnitBase() {\r
+        return derivedUnitBase;\r
+    }\r
+\r
+    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {\r
+        this.derivedUnitBase = derivedUnitBase;\r
+    }\r
+\r
+    /**\r
+     * @return the report\r
+     */\r
+    public SpecimenImportReport getReport() {\r
+        return report;\r
+    }\r
+\r
+    /**\r
+     * @param report the report to set\r
+     */\r
+    public void setReport(SpecimenImportReport report) {\r
+        this.report = report;\r
+    }\r
+\r
+    /**\r
+     *\r
+     */\r
+    public abstract void reset() ;\r
+\r
+    /**\r
+     * @return the dataHolder\r
+     */\r
+    public SpecimenDataHolder getDataHolder() {\r
+        return dataHolder;\r
+    }\r
+\r
+    /**\r
+     * @param dataHolder the dataHolder to set\r
+     */\r
+    public void setDataHolder(SpecimenDataHolder dataHolder) {\r
+        this.dataHolder = dataHolder;\r
+    }\r
+\r
+\r
+}\r
index 6fba3e2cd964d7b2a5675bd779857c042c64c968..173500090a6f8b6644464f9a53e105adb9369877 100644 (file)
@@ -293,7 +293,7 @@ public class UnitsGatheringEvent {
         if (DEBUG) {
             System.out.println("getcoll:"+config.getPersons().get(collector.getTitleCache()));
         }
-        this.gatheringEvent.setCollector(config.getPersons().get(collector.getTitleCache()));
+       // this.gatheringEvent.setCollector(config.getPersons().get(collector.getTitleCache()));
     }
 
     /**
@@ -356,7 +356,7 @@ public class UnitsGatheringEvent {
         if (DEBUG) {
             System.out.println("getteam:"+config.getTeams().get(t.getTitleCache()));
         }
-        this.gatheringEvent.setCollector(config.getTeams().get(t.getTitleCache()));
+        //this.gatheringEvent.setCollector(config.getTeams().get(t.getTitleCache()));
     }
 
 
index 7c7d27bf6223f7b789ae1ef84e46848532fc8ea6..a3e64607638b3e119a49866fecb10829520a2034 100644 (file)
@@ -16,6 +16,7 @@ import java.util.Map;
 \r
 import org.apache.log4j.Logger;\r
 \r
+import eu.etaxonomy.cdm.io.specimen.SpecimenDataHolder;\r
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;\r
 \r
 /**\r
@@ -23,7 +24,7 @@ import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
  * @date 16.06.2010\r
  *\r
  */\r
-public class Abcd206DataHolder {\r
+public class Abcd206DataHolder extends SpecimenDataHolder{\r
     @SuppressWarnings("unused")\r
     private static final Logger logger = Logger.getLogger(Abcd206DataHolder.class);\r
 \r
@@ -36,14 +37,14 @@ public class Abcd206DataHolder {
 \r
     //per unit\r
     protected List<Identification> identificationList;\r
-    protected List<HashMap<String, String>> atomisedIdentificationList;\r
+    private List<HashMap<String, String>> atomisedIdentificationList;\r
     protected Map<String, String> namedAreaList;\r
     protected List<String[]> referenceList;\r
     protected List<String> multimediaObjects;\r
     protected List<String> docSources;\r
     protected List<String> associatedUnitIds;\r
 \r
-    protected String nomenclatureCode;\r
+    private String nomenclatureCode;\r
     protected String institutionCode;\r
     protected String collectionCode;\r
     protected String unitID;\r
@@ -74,7 +75,7 @@ public class Abcd206DataHolder {
 \r
     public void reset() {\r
 \r
-        nomenclatureCode = null;\r
+        setNomenclatureCode(null);\r
         institutionCode = null;\r
         collectionCode = null;\r
         unitID = null;\r
@@ -103,7 +104,7 @@ public class Abcd206DataHolder {
         gatheringCoordinateErrorMethod = null;\r
 \r
         identificationList = new ArrayList<Identification>();\r
-        atomisedIdentificationList = new ArrayList<HashMap<String, String>>();\r
+        setAtomisedIdentificationList(new ArrayList<HashMap<String, String>>());\r
         namedAreaList = new HashMap<String, String>();\r
         referenceList = new ArrayList<String[]>();\r
         multimediaObjects = new ArrayList<String>();\r
@@ -111,4 +112,7 @@ public class Abcd206DataHolder {
         associatedUnitIds = new ArrayList<String>();\r
     }\r
 \r
+\r
+\r
+\r
 }\r
index eb892c8ab3e97fb94b0afb939c0f0257cf95cf2e..a85957975a47445b2024de8978980b46fecff087 100644 (file)
@@ -9,6 +9,7 @@
 
 package eu.etaxonomy.cdm.io.specimen.abcd206.in;
 
+import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -26,8 +27,7 @@ import org.w3c.dom.NodeList;
 
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
-import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
-import eu.etaxonomy.cdm.api.service.pager.Pager;
+import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
 import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;
@@ -44,10 +44,8 @@ import eu.etaxonomy.cdm.model.common.DefinedTerm;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
 import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.LanguageString;
 import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
 import eu.etaxonomy.cdm.model.common.OriginalSourceType;
-import eu.etaxonomy.cdm.model.description.DescriptionBase;
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.description.Feature;
 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
@@ -55,16 +53,11 @@ import eu.etaxonomy.cdm.model.description.TaxonDescription;
 import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.molecular.DnaSample;
-import eu.etaxonomy.cdm.model.name.BacterialName;
-import eu.etaxonomy.cdm.model.name.BotanicalName;
-import eu.etaxonomy.cdm.model.name.CultivarPlantName;
-import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.name.Rank;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.name.ZoologicalName;
 import eu.etaxonomy.cdm.model.occurrence.Collection;
 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
@@ -84,8 +77,6 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
 import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
 import eu.etaxonomy.cdm.persistence.query.MatchMode;
-import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
-import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
 
 /**
  * @author p.kelbert
@@ -99,7 +90,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
     private static final Logger logger = Logger.getLogger(Abcd206Import.class);
 
-    private final boolean DEBUG = true;
+
 
     private static final String COLON = ":";
 
@@ -117,44 +108,55 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
     @Override
     @SuppressWarnings("rawtypes")
     public void doInvoke(Abcd206ImportState state) {
+        Abcd206ImportConfigurator config = state.getConfig();
         try{
             state.setTx(startTransaction());
             logger.info("INVOKE Specimen Import from ABCD2.06 XML ");
-
+            InputStream response = null;
             //init cd repository
             if(state.getCdmRepository()==null){
                 state.setCdmRepository(this);
             }
+            if (config.getOccurenceQuery() != null){
+                BioCaseQueryServiceWrapper queryService = new BioCaseQueryServiceWrapper();
+                try {
 
-            SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
+                   response = queryService.query(config.getOccurenceQuery(), config.getSourceUri());
 
-            //init import reference
-            List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
-
-            if (state.getConfig().isInteractWithUser()){
-                Map<String,Reference> refMap = new HashMap<String, Reference>();
-                for (Reference reference : references) {
-                    if (! StringUtils.isBlank(reference.getTitleCache())) {
-                        refMap.put(reference.getTitleCache(),reference);
-                    }
+                }catch(Exception e){
+                    logger.error("An error during ABCD import");
                 }
-                state.setRef(sui.askForReference(refMap));
+            }
+            SpecimenUserInteraction sui = ((Abcd206ImportConfigurator)state.getConfig()).getSpecimenUserInteraction();
 
-                if (state.getRef() == null){
-                    String cla = sui.createNewReference();
-                    if (refMap.get(cla)!= null) {
-                        state.setRef(refMap.get(cla));
-                    } else {
-                        state.setRef(ReferenceFactory.newGeneric());
-                        state.getRef().setTitle(cla);
-                    }
-                }
-                else{
-                    state.setRef(getReferenceService().find(state.getRef().getUuid()));
-                }
-            }else{
+            //init import reference
+        //  List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
+            List<Reference> references = new ArrayList<Reference>();
+
+//            if (state.getConfig().isInteractWithUser()){
+//                Map<String,Reference> refMap = new HashMap<String, Reference>();
+//                for (Reference reference : references) {
+//                    if (! StringUtils.isBlank(reference.getTitleCache())) {
+//                        refMap.put(reference.getTitleCache(),reference);
+//                    }
+//                }
+//                state.setRef(sui.askForReference(refMap));
+//
+//                if (state.getRef() == null){
+//                    String cla = sui.createNewReference();
+//                    if (refMap.get(cla)!= null) {
+//                        state.setRef(refMap.get(cla));
+//                    } else {
+//                        state.setRef(ReferenceFactory.newGeneric());
+//                        state.getRef().setTitle(cla);
+//                    }
+//                }
+//                else{
+//                    state.setRef(getReferenceService().find(state.getRef().getUuid()));
+//                }
+//            }else{
                 if (state.getRef()==null){
-                    String name = NB(state.getConfig().getSourceReferenceTitle());
+                    String name = NB(((Abcd206ImportConfigurator) state.getConfig()).getSourceReferenceTitle());
                     for (Reference reference : references) {
                         if (! StringUtils.isBlank(reference.getTitleCache())) {
                             if (reference.getTitleCache().equalsIgnoreCase(name)) {
@@ -167,18 +169,18 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                         state.getRef().setTitle("ABCD classic");
                     }
                 }
-            }
+            //}
             save(state.getRef(), state);
-            state.getConfig().setSourceReference(state.getRef());
+            ((Abcd206ImportConfigurator) state.getConfig()).setSourceReference(state.getRef());
 
-            if(state.getConfig().getClassificationUuid()!=null){
+            if(((Abcd206ImportConfigurator) state.getConfig()).getClassificationUuid()!=null){
                 //load classification from config if it exists
-                state.setClassification(getClassificationService().load(state.getConfig().getClassificationUuid()));
+                state.setClassification(getClassificationService().load(((Abcd206ImportConfigurator) state.getConfig()).getClassificationUuid()));
             }
             if(state.getClassification()==null){//no existing classification was set in config
                 List<Classification> classificationList = getClassificationService().list(Classification.class, null, null, null, null);
                 //get classification via user interaction
-                if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()){
+                if (((Abcd206ImportConfigurator) state.getConfig()).isUseClassification() && ((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
                     Map<String,Classification> classMap = new HashMap<String, Classification>();
                     for (Classification tree : classificationList) {
                         if (! StringUtils.isBlank(tree.getTitleCache())) {
@@ -198,7 +200,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                 }
                 // use default classification as the classification to import into
                 if (state.getClassification() == null) {
-                    String name = NB(state.getConfig().getClassificationName());
+                    String name = NB(((Abcd206ImportConfigurator) state.getConfig()).getClassificationName());
                     for (Classification classif : classificationList){
                         if (classif.getTitleCache() != null && classif.getTitleCache().equalsIgnoreCase(name)) {
                             state.setClassification(classif);
@@ -214,7 +216,10 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                 }
             }
 
-            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(state.getConfig().getSource(), state.getReport());
+            if (response == null){
+                response =(InputStream) ((Abcd206ImportConfigurator) state.getConfig()).getSource();
+            }
+            UnitAssociationWrapper unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(response, state.getReport());
             NodeList unitsList = unitAssociationWrapper.getAssociatedUnits();
             state.setPrefix(unitAssociationWrapper.getPrefix());
 
@@ -250,10 +255,10 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                     this.handleSingleUnit(state, item);
 
                 }
-                if(state.getConfig().isDeduplicateReferences()){
+                if(((Abcd206ImportConfigurator)state.getConfig()).isDeduplicateReferences()){
                     getReferenceService().deduplicate(Reference.class, null, null);
                 }
-                if(state.getConfig().isDeduplicateClassifications()){
+                if(((Abcd206ImportConfigurator)state.getConfig()).isDeduplicateClassifications()){
                     getClassificationService().deduplicate(Classification.class, null, null);
                 }
             }
@@ -265,7 +270,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             state.getReport().addException(errorDuringImport, e);
         }
         finally{
-            state.getReport().printReport(state.getConfig().getReportUri());
+            state.getReport().printReport(((Abcd206ImportConfigurator)state.getConfig()).getReportUri());
         }
         return;
     }
@@ -277,6 +282,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      */
     @SuppressWarnings("rawtypes")
     private void handleSingleUnit(Abcd206ImportState state, Element item) {
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
         if (DEBUG) {
             logger.info("handleSingleUnit "+state.getRef());
         }
@@ -287,14 +293,14 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             }
             //check if unit already exists
             DerivedUnitFacade derivedUnitFacade = null;
-            if(state.getConfig().isIgnoreImportOfExistingSpecimens()){
+            if(((Abcd206ImportConfigurator)state.getConfig()).isIgnoreImportOfExistingSpecimens()){
                 SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(state.getDataHolder().unitID, state);
                 if(existingSpecimen!=null && existingSpecimen.isInstanceOf(DerivedUnit.class)){
                     DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(existingSpecimen, DerivedUnit.class);
                     state.setDerivedUnitBase(derivedUnit);
                     derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
                     importAssociatedUnits(state, item, derivedUnitFacade);
-                    state.getReport().addAlreadyExistingSpecimen(AbcdImportUtility.getUnitID(derivedUnit, state.getConfig()), derivedUnit);
+                    state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, config), derivedUnit);
                     return;
                 }
             }
@@ -335,19 +341,19 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                     state.getDataHolder().gatheringElevationUnit, state.getDataHolder().gatheringDateText,
                     state.getDataHolder().gatheringNotes, state.getTransformer().getReferenceSystemByKey(
                             state.getDataHolder().gatheringSpatialDatum), state.getDataHolder().gatheringAgentList,
-                    state.getDataHolder().gatheringTeamList, state.getConfig());
+                    state.getDataHolder().gatheringTeamList, (Abcd206ImportConfigurator)state.getConfig());
 
             // country
             UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
             //  unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());
-            unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, state.getConfig(), cdmAppController.getTermService(), cdmAppController.getOccurrenceService());
+            unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, ((Abcd206ImportConfigurator) state.getConfig()), cdmAppController.getTermService(), cdmAppController.getOccurrenceService());
 
             DefinedTermBase<?> areaCountry =  unitsGatheringArea.getCountry();
 
             // other areas
             unitsGatheringArea = new UnitsGatheringArea();
             //            unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
-            unitsGatheringArea.setAreas(state.getDataHolder().namedAreaList,state.getConfig(), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
+            unitsGatheringArea.setAreas(state.getDataHolder().namedAreaList,((Abcd206ImportConfigurator) state.getConfig()), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
             ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();
             for (DefinedTermBase namedArea : nas) {
                 unitsGatheringEvent.addArea(namedArea);
@@ -383,7 +389,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                     try {
                         media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
                         derivedUnitFacade.addDerivedUnitMedia(media);
-                        if(state.getConfig().isAddMediaAsMediaSpecimen()){
+                        if(((Abcd206ImportConfigurator)state.getConfig()).isAddMediaAsMediaSpecimen()){
                             //add media also as specimen scan
                             MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
                             mediaSpecimen.setMediaSpecimen(media);
@@ -419,7 +425,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             setCollectionData(state, derivedUnitFacade);
 
             //Reference stuff
-            SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
+            SpecimenUserInteraction sui = config.getSpecimenUserInteraction();
             Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<String, OriginalSourceBase<?>>();
 
             state.getDataHolder().docSources = new ArrayList<String>();
@@ -457,9 +463,8 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                 reference.addSource(sour);
                 save(reference, state);
             }
-
-            List<IdentifiableSource> issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
-            List<DescriptionElementSource> issTmp2 = getCommonService().list(DescriptionElementSource.class, null, null, null, null);
+            List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
+            List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
 
             Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
             if(issTmp2!=null) {
@@ -471,7 +476,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
             addToSourceMap(sourceMap, osbSet);
 
-            if( state.getConfig().isInteractWithUser()){
+            if( ((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
                 List<OriginalSourceBase<?>>sources=null;
                 if(!state.isDerivedUnitSourcesSet()){
                     sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().docSources);
@@ -537,93 +542,103 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         return;
     }
 
-    private void importAssociatedUnits(Abcd206ImportState state, Element item, DerivedUnitFacade derivedUnitFacade) {
+    @Override
+    protected void importAssociatedUnits(Abcd206ImportState state, Object itemObject, DerivedUnitFacade derivedUnitFacade) {
+
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator) state.getConfig();
         //import associated units
         FieldUnit currentFieldUnit = derivedUnitFacade.innerFieldUnit();
         //TODO: push state (think of implementing stack architecture for state
         DerivedUnit currentUnit = state.getDerivedUnitBase();
         DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
         String currentPrefix = state.getPrefix();
-        NodeList unitAssociationList = item.getElementsByTagName(currentPrefix+"UnitAssociation");
-        for(int k=0;k<unitAssociationList.getLength();k++){
-            if(unitAssociationList.item(k) instanceof Element){
-                Element unitAssociation = (Element)unitAssociationList.item(k);
-                UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
-                UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
-                if(associationWrapper!=null){
-                    NodeList associatedUnits = associationWrapper.getAssociatedUnits();
-                    if(associatedUnits!=null){
-                        for(int m=0;m<associatedUnits.getLength();m++){
-                            if(associatedUnits.item(m) instanceof Element){
-                                state.reset();
-                                state.setPrefix(associationWrapper.getPrefix());
-                                this.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);
-                                handleSingleUnit(state, (Element) associatedUnits.item(m));
-
-                                DerivedUnit associatedUnit = state.getDerivedUnitBase();
-                                FieldUnit associatedFieldUnit = null;
-                                java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
-                                //ignore field unit if associated unit has more than one
-                                if(associatedFieldUnits.size()>1){
-                                    state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
-                                }
-                                else if(associatedFieldUnits.size()==1){
-                                    associatedFieldUnit = associatedFieldUnits.iterator().next();
-                                }
-
-                                //attach current unit and associated unit depending on association type
-
-                                //parent-child relation:
-                                //copy derivation event and connect parent and sub derivative
-                                if(associationWrapper.getAssociationType().contains("individual")){
-                                    if(currentDerivedFrom==null){
-                                        state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",AbcdImportUtility.getUnitID(currentUnit, state.getConfig())));
-                                        DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());
-                                    }
-                                    else{
-                                        DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, currentDerivedFrom.getType());
-                                        updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
-                                        updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
-                                        updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
-                                        updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
+        Element item = null;
+        if (item instanceof Element){
+            item = (Element)itemObject;
+        }
+        NodeList unitAssociationList = null;
+        if (item != null){
+            unitAssociationList = item.getElementsByTagName(currentPrefix+"UnitAssociation");
+            for(int k=0;k<unitAssociationList.getLength();k++){
+                if(unitAssociationList.item(k) instanceof Element){
+                    Element unitAssociation = (Element)unitAssociationList.item(k);
+                    UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
+                    UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
+                    if(associationWrapper!=null){
+                        NodeList associatedUnits = associationWrapper.getAssociatedUnits();
+                        if(associatedUnits!=null){
+                            for(int m=0;m<associatedUnits.getLength();m++){
+                                if(associatedUnits.item(m) instanceof Element){
+                                    state.reset();
+                                    state.setPrefix(associationWrapper.getPrefix());
+                                    this.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);
+                                    handleSingleUnit(state, (Element) associatedUnits.item(m));
+
+                                    DerivedUnit associatedUnit = state.getDerivedUnitBase();
+                                    FieldUnit associatedFieldUnit = null;
+                                    java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
+                                    //ignore field unit if associated unit has more than one
+                                    if(associatedFieldUnits.size()>1){
+                                        state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
                                     }
-                                    state.getReport().addDerivate(associatedUnit, currentUnit, state.getConfig());
-                                }
-                                //siblings relation
-                                //connect current unit to field unit of associated unit
-                                else if(associationWrapper.getAssociationType().contains("population")){
-                                    //no associated field unit -> using current one
-                                    if(associatedFieldUnit==null){
-                                        if(currentFieldUnit!=null){
-                                            DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());
-                                        }
+                                    else if(associatedFieldUnits.size()==1){
+                                        associatedFieldUnit = associatedFieldUnits.iterator().next();
                                     }
-                                    else{
+
+                                    //attach current unit and associated unit depending on association type
+
+                                    //parent-child relation:
+                                    //copy derivation event and connect parent and sub derivative
+                                    if(associationWrapper.getAssociationType().contains("individual")){
                                         if(currentDerivedFrom==null){
-                                            state.getReport().addInfoMessage("No derivation event found for unit "+AbcdImportUtility.getUnitID(currentUnit, state.getConfig())+". Defaulting to ACCESIONING event.");
-                                            DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
+                                            state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",SpecimenImportUtility.getUnitID(currentUnit, config)));
+                                            DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());
                                         }
-                                        if(currentDerivedFrom!=null && associatedFieldUnit!=currentFieldUnit){
-                                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());
+                                        else{
+                                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, currentDerivedFrom.getType());
                                             updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
                                             updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
                                             updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
                                             updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
                                         }
+                                        state.getReport().addDerivate(associatedUnit, currentUnit, config);
+                                    }
+                                    //siblings relation
+                                    //connect current unit to field unit of associated unit
+                                    else if(associationWrapper.getAssociationType().contains("population")){
+                                        //no associated field unit -> using current one
+                                        if(associatedFieldUnit==null){
+                                            if(currentFieldUnit!=null){
+                                                DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());
+                                            }
+                                        }
+                                        else{
+                                            if(currentDerivedFrom==null){
+                                                state.getReport().addInfoMessage("No derivation event found for unit "+SpecimenImportUtility.getUnitID(currentUnit, config)+". Defaulting to ACCESIONING event.");
+                                                DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
+                                            }
+                                            if(currentDerivedFrom!=null && associatedFieldUnit!=currentFieldUnit){
+                                                DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());
+                                                updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
+                                                updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
+                                                updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
+                                                updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
+                                            }
+                                        }
                                     }
-                                }
 
-                                //delete current field unit if replaced
-                                if(currentFieldUnit!=null && currentDerivedFrom!=null
-                                        && currentFieldUnit.getDerivationEvents().size()==1  && currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) //making sure that the field unit
-                                        && currentDerivedFrom.getDerivatives().size()==1 && currentDerivedFrom.getDerivatives().contains(currentUnit) //is not attached to other derived units
-                                        && currentDerivedFrom!=currentUnit.getDerivedFrom() // <- derivation has been replaced and can be deleted
-                                        ){
-                                    currentFieldUnit.removeDerivationEvent(currentDerivedFrom);
-                                    state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);
-                                }
+                                    //delete current field unit if replaced
+                                    if(currentFieldUnit!=null && currentDerivedFrom!=null
+                                            && currentFieldUnit.getDerivationEvents().size()==1  && currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) //making sure that the field unit
+                                            && currentDerivedFrom.getDerivatives().size()==1 && currentDerivedFrom.getDerivatives().contains(currentUnit) //is not attached to other derived units
+                                            && currentDerivedFrom!=currentUnit.getDerivedFrom() // <- derivation has been replaced and can be deleted
+                                            ){
+                                        currentFieldUnit.removeDerivationEvent(currentDerivedFrom);
+                                        state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);
+                                    }
 
-                                save(associatedUnit, state);
+                                    save(associatedUnit, state);
+                                }
                             }
                         }
                     }
@@ -636,21 +651,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         state.setPrefix(currentPrefix);
     }
 
-    private SpecimenOrObservationBase findExistingSpecimen(String unitId, Abcd206ImportState state){
-        ICdmApplicationConfiguration cdmAppController = state.getConfig().getCdmAppController();
-        if(cdmAppController==null){
-            cdmAppController = this;
-        }
-        FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
-        config.setSignificantIdentifier(unitId);
-        Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
-        if(!existingSpecimens.getRecords().isEmpty()){
-            if(existingSpecimens.getRecords().size()==1){
-                return existingSpecimens.getRecords().iterator().next();
-            }
-        }
-        return null;
-    }
+
 
     /**
      * @param sourceMap
@@ -703,7 +704,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
     //    for our new source.
     private IdentifiableSource getIdentifiableSource(Reference reference, String citationDetail) {
 
-        List<IdentifiableSource> issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
+      /*  List<IdentifiableSource> issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
 
 
         if (reference != null){
@@ -724,7 +725,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
                 e1.printStackTrace();
             }
         }
-
+*/
         IdentifiableSource sour = IdentifiableSource.NewInstance(OriginalSourceType.Import,null,null, reference,citationDetail);
         return sour;
     }
@@ -754,44 +755,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
     //    }
 
 
-    /**
-     * Very fast and dirty implementation to allow handling of transient objects as described in
-     * https://dev.e-taxonomy.eu/trac/ticket/3726
-     *
-     * Not yet complete.
-     *
-     * @param cdmBase
-     * @param state
-     */
-    private void save(CdmBase cdmBase, Abcd206ImportState state) {
-        ICdmApplicationConfiguration cdmRepository = state.getConfig().getCdmAppController();
-        if (cdmRepository == null){
-            cdmRepository = this;
-        }
-
-        if (cdmBase.isInstanceOf(LanguageString.class)){
-            cdmRepository.getTermService().saveLanguageData(CdmBase.deproxy(cdmBase, LanguageString.class));
-        }else if (cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
-            cdmRepository.getOccurrenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, SpecimenOrObservationBase.class));
-        }else if (cdmBase.isInstanceOf(Reference.class)){
-            cdmRepository.getReferenceService().saveOrUpdate(CdmBase.deproxy(cdmBase, Reference.class));
-        }else if (cdmBase.isInstanceOf(Classification.class)){
-            cdmRepository.getClassificationService().saveOrUpdate(CdmBase.deproxy(cdmBase, Classification.class));
-        }else if (cdmBase.isInstanceOf(AgentBase.class)){
-            cdmRepository.getAgentService().saveOrUpdate(CdmBase.deproxy(cdmBase, AgentBase.class));
-        }else if (cdmBase.isInstanceOf(Collection.class)){
-            cdmRepository.getCollectionService().saveOrUpdate(CdmBase.deproxy(cdmBase, Collection.class));
-        }else if (cdmBase.isInstanceOf(DescriptionBase.class)){
-            cdmRepository.getDescriptionService().saveOrUpdate(CdmBase.deproxy(cdmBase, DescriptionBase.class));
-        }else if (cdmBase.isInstanceOf(TaxonBase.class)){
-            cdmRepository.getTaxonService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonBase.class));
-        }else if (cdmBase.isInstanceOf(TaxonNameBase.class)){
-            cdmRepository.getNameService().saveOrUpdate(CdmBase.deproxy(cdmBase, TaxonNameBase.class));
-        }else{
-            throw new IllegalArgumentException("Class not supported in save method: " + CdmBase.deproxy(cdmBase, CdmBase.class).getClass().getSimpleName());
-        }
 
-    }
 
     /**
      * setCollectionData : store the collection object into the
@@ -800,8 +764,8 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @param state
      */
     private void setCollectionData(Abcd206ImportState state, DerivedUnitFacade derivedUnitFacade) {
-        Abcd206ImportConfigurator config = state.getConfig();
-        AbcdImportUtility.setUnitID(derivedUnitFacade.innerDerivedUnit(), state.getDataHolder().unitID, config);
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
+        SpecimenImportUtility.setUnitID(derivedUnitFacade.innerDerivedUnit(), state.getDataHolder().unitID, config);
         if(!config.isMapUnitIdToAccessionNumber()){
             derivedUnitFacade.setAccessionNumber(NB(state.getDataHolder().accessionNumber));
         }
@@ -894,7 +858,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             }
             state.getDataHolder().identificationList = new ArrayList<Identification>();
             state.getDataHolder().statusList = new ArrayList<SpecimenTypeDesignationStatus>();
-            state.getDataHolder().atomisedIdentificationList = new ArrayList<HashMap<String, String>>();
+            state.getDataHolder().setAtomisedIdentificationList(new ArrayList<HashMap<String, String>>());
             state.getDataHolder().referenceList = new ArrayList<String[]>();
             state.getDataHolder().multimediaObjects = new ArrayList<String>();
 
@@ -934,6 +898,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @return the Institution (existing or new)
      */
     private Institution getInstitution(String institutionCode, Abcd206ImportState state) {
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
         Institution institution=null;
         List<Institution> institutions;
         try {
@@ -942,7 +907,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             institutions = new ArrayList<Institution>();
             logger.warn(e);
         }
-        if (institutions.size() > 0 && state.getConfig().isReUseExistingMetadata()) {
+        if (institutions.size() > 0 && config.isReUseExistingMetadata()) {
             for (Institution institut:institutions){
                 try{
                     if (institut.getCode().equalsIgnoreCase(institutionCode)) {
@@ -974,6 +939,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @return the Collection (existing or new)
      */
     private Collection getCollection(Institution institution, String collectionCode, Abcd206ImportState state) {
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
         Collection collection = null;
         List<Collection> collections;
         try {
@@ -981,7 +947,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         } catch (Exception e) {
             collections = new ArrayList<Collection>();
         }
-        if (collections.size() > 0 && state.getConfig().isReUseExistingMetadata()) {
+        if (collections.size() > 0 && config.isReUseExistingMetadata()) {
             for (Collection coll:collections){
                 if (coll.getCode() != null && coll.getInstitute() != null
                         && coll.getCode().equalsIgnoreCase(collectionCode) && coll.getInstitute().equals(institution)) {
@@ -1011,7 +977,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      */
     @SuppressWarnings("rawtypes")
     private void linkDeterminationEvent(Abcd206ImportState state, Taxon taxon, boolean preferredFlag,  DerivedUnitFacade derivedFacade) {
-        Abcd206ImportConfigurator config = state.getConfig();
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
         if(DEBUG){
             logger.info("start linkdetermination with taxon:" + taxon.getUuid()+", "+taxon);
         }
@@ -1048,13 +1014,14 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         }
 
         for (String[] fullReference : state.getDataHolder().referenceList) {
-            List<Reference> references = getReferenceService().list(Reference.class, null, null, null, null);
+
 
             String strReference=fullReference[0];
             String citationDetail = fullReference[1];
             String citationURL = fullReference[2];
+            List<Reference> references = getReferenceService().listByTitle(Reference.class, "strReference", MatchMode.EXACT, null, null, null, null, null);
 
-            if (isNotBlank(strReference)){
+            if (!references.isEmpty()){
                 Reference reference = null;
                 for (Reference refe: references) {
                     if (refe.getTitleCache().equalsIgnoreCase(strReference)) {
@@ -1091,7 +1058,8 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @param determinationEvent:the determinationevent
      */
     private void makeIndividualsAssociation(Abcd206ImportState state, Taxon taxon, DeterminationEvent determinationEvent) {
-        SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
+        SpecimenUserInteraction sui = config.getSpecimenUserInteraction();
 
         if (DEBUG) {
             logger.info("MAKE INDIVIDUALS ASSOCIATION");
@@ -1099,7 +1067,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
         TaxonDescription taxonDescription = null;
         Set<TaxonDescription> descriptions= taxon.getDescriptions();
-        if (state.getConfig().isInteractWithUser()){
+        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
             if(!state.isDescriptionGroupSet()){
                 taxonDescription = sui.askForDescriptionGroup(descriptions);
                 state.setDescriptionGroup(taxonDescription);
@@ -1145,7 +1113,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
         addToSourceMap(sourceMap, osbSet);
 
-        if (state.getConfig().isInteractWithUser()){
+        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
             List<OriginalSourceBase<?>> res = null;
             if(!state.isDescriptionSourcesSet()){
                 res = sui.askForSource(sourceMap, "the description group ("+taxon+")",
@@ -1186,7 +1154,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         indAssociation.setAssociatedSpecimenOrObservation(state.getDerivedUnitBase());
         indAssociation.setFeature(feature);
 
-        if (state.getConfig().isInteractWithUser()){
+        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
             sourceMap = new HashMap<String, OriginalSourceBase<?>>();
 
             issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
@@ -1263,7 +1231,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
         save(taxonDescription, state);
         save(taxon, state);
-        state.getReport().addDerivate(state.getDerivedUnitBase(), state.getConfig());
+        state.getReport().addDerivate(state.getDerivedUnitBase(), config);
         state.getReport().addIndividualAssociation(taxon, state.getDataHolder().unitID, state.getDerivedUnitBase());
     }
 
@@ -1585,14 +1553,14 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @param derivedUnitFacade : the current derivedunitfacade
      */
     private void handleIdentifications(Abcd206ImportState state, DerivedUnitFacade derivedUnitFacade) {
-        Abcd206ImportConfigurator config = state.getConfig();
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
 
 
         String scientificName = "";
         boolean preferredFlag = false;
 
-        if (state.getDataHolder().nomenclatureCode == ""){
-            state.getDataHolder().nomenclatureCode = config.getNomenclaturalCode().toString();
+        if (state.getDataHolder().getNomenclatureCode() == ""){
+            state.getDataHolder().setNomenclatureCode(config.getNomenclaturalCode().toString());
         }
 
         for (int i = 0; i < state.getDataHolder().identificationList.size(); i++) {
@@ -1608,10 +1576,10 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             }
 
             if (identification.getCode().indexOf(':') != -1) {
-                state.getDataHolder().nomenclatureCode = identification.getCode().split(COLON)[1];
+                state.getDataHolder().setNomenclatureCode(identification.getCode().split(COLON)[1]);
             }
             else{
-                state.getDataHolder().nomenclatureCode = identification.getCode();
+                state.getDataHolder().setNomenclatureCode(identification.getCode());
             }
             TaxonNameBase<?,?> taxonName = getOrCreateTaxonName(scientificName, null, preferredFlag, state, i);
             Taxon taxon = getOrCreateTaxonForName(taxonName, state);
@@ -1621,109 +1589,9 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
     }
 
 
-    private TaxonNameBase<?, ?> getOrCreateTaxonName(String scientificName, Rank rank, boolean preferredFlag, Abcd206ImportState state, int unitIndexInAbcdFile){
-        TaxonNameBase<?, ?> taxonName = null;
-        Abcd206ImportConfigurator config = state.getConfig();
 
-        //check atomised name data for rank
-        //new name will be created
-        NonViralName<?> atomisedTaxonName = null;
-        if (rank==null && unitIndexInAbcdFile>=0 && (state.getDataHolder().atomisedIdentificationList != null || state.getDataHolder().atomisedIdentificationList.size() > 0)) {
-            atomisedTaxonName = setTaxonNameByType(state.getDataHolder().atomisedIdentificationList.get(unitIndexInAbcdFile), scientificName, state);
-            if(atomisedTaxonName!=null){
-                rank = atomisedTaxonName.getRank();
-            }
-        }
-        if(config.isReuseExistingTaxaWhenPossible()){
-            NonViralName<?> parsedName = atomisedTaxonName;
-            if(parsedName==null){
-                parsedName = parseScientificName(scientificName, state, state.getReport());
-            }
-            if(config.isIgnoreAuthorship() && parsedName!=null && preferredFlag){
-                // do not ignore authorship for non-preferred names because they need
-                // to be created for the determination history
-                String nameCache = parsedName.getNameCache();
-                List<NonViralName> names = getNameService().findNamesByNameCache(nameCache, MatchMode.EXACT, null);
-                taxonName = getBestMatchingName(scientificName, new ArrayList<TaxonNameBase>(names), state);
-            }
-            else {
-                //search for existing names
-                List<TaxonNameBase> names = getNameService().listByTitle(TaxonNameBase.class, scientificName, MatchMode.EXACT, null, null, null, null, null);
-                taxonName = getBestMatchingName(scientificName, names, state);
-                //still nothing found -> try with the atomised name full title cache
-                if(taxonName==null && atomisedTaxonName!=null){
-                    names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getFullTitleCache(), MatchMode.EXACT, null, null, null, null, null);
-                    taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
-                    //still nothing found -> try with the atomised name title cache
-                    if(taxonName==null){
-                        names = getNameService().listByTitle(TaxonNameBase.class, atomisedTaxonName.getTitleCache(), MatchMode.EXACT, null, null, null, null, null);
-                        taxonName = getBestMatchingName(atomisedTaxonName.getTitleCache(), names, state);
-                    }
-                }
-            }
-        }
 
-        if(taxonName==null && atomisedTaxonName!=null){
-            taxonName = atomisedTaxonName;
-            state.getReport().addName(taxonName);
-            logger.info("Created new taxon name "+taxonName);
-            if(taxonName.hasProblem()){
-                state.getReport().addInfoMessage(String.format("Created %s with parsing problems", taxonName));
-            }
-            if(!atomisedTaxonName.getTitleCache().equals(scientificName)){
-                state.getReport().addInfoMessage(String.format("Taxon %s was parsed as %s", scientificName, atomisedTaxonName.getTitleCache()));
-            }
-        }
-        else if(taxonName==null){
-            //create new taxon name
-            taxonName = NonViralName.NewInstance(rank);
-            taxonName.setFullTitleCache(scientificName,true);
-            taxonName.setTitleCache(scientificName, true);
-            state.getReport().addName(taxonName);
-            logger.info("Created new taxon name "+taxonName);
-        }
-        save(taxonName, state);
-        return taxonName;
-    }
 
-    private TaxonNameBase<?, ?> getBestMatchingName(String scientificName, java.util.Collection<TaxonNameBase> names, Abcd206ImportState state){
-        List<TaxonNameBase> namesWithAcceptedTaxa = new ArrayList<TaxonNameBase>();
-        for (TaxonNameBase name : names) {
-            if(!name.getTaxa().isEmpty()){
-                namesWithAcceptedTaxa.add(name);
-            }
-        }
-        String message = "More than one taxon name was found for "+scientificName+"!";
-        //check for names with accepted taxa
-        if(namesWithAcceptedTaxa.size()>0){
-            if(namesWithAcceptedTaxa.size()>1){
-                state.getReport().addInfoMessage(message);
-                logger.warn(message);
-                return null;
-            }
-            return namesWithAcceptedTaxa.iterator().next();
-        }
-        //no names with accepted taxa found -> check accepted taxa of synonyms
-        List<Taxon> taxaFromSynonyms = new ArrayList<Taxon>();
-        for (TaxonNameBase name : names) {
-            Set<TaxonBase> taxonBases = name.getTaxonBases();
-            for (TaxonBase taxonBase : taxonBases) {
-                if(taxonBase.isInstanceOf(Synonym.class)){
-                    Synonym synonym = HibernateProxyHelper.deproxy(taxonBase, Synonym.class);
-                    taxaFromSynonyms.addAll(synonym.getAcceptedTaxa());
-                }
-            }
-        }
-        if(taxaFromSynonyms.size()>0){
-            if(taxaFromSynonyms.size()>1){
-                state.getReport().addInfoMessage(message);
-                logger.warn(message);
-                return null;
-            }
-            return taxaFromSynonyms.iterator().next().getName();
-        }
-        return null;
-    }
 
     private Taxon getOrCreateTaxonForName(TaxonNameBase<?, ?> taxonNameBase, Abcd206ImportState state){
         Set<Taxon> acceptedTaxa = taxonNameBase.getTaxa();
@@ -1770,13 +1638,14 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
      * @param state : the ABCD import state
      */
     private void addTaxonNode(Taxon taxon, Abcd206ImportState state, boolean preferredFlag) {
+        Abcd206ImportConfigurator config = (Abcd206ImportConfigurator)state.getConfig();
         logger.info("link taxon to a taxonNode "+taxon.getTitleCache());
         //only add nodes if not already existing in current classification or default classification
 
         //check if node exists in current classification
         //NOTE: we cannot use hasTaxonNodeInClassification() here because we are first creating it here
         if (!existsInClassification(taxon, state.getClassification())){
-            if(state.getConfig().isMoveNewTaxaToDefaultClassification()){
+            if(config.isMoveNewTaxaToDefaultClassification()){
                 //check if node exists in default classification
                 if(!existsInClassification(taxon, state.getDefaultClassification())){
                     addParentTaxon(taxon, state, preferredFlag, state.getDefaultClassification());
@@ -1933,292 +1802,12 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         return null;
     }
 
-    /**
-     * Parse automatically the scientific name
-     * @param scientificName the scientific name to parse
-     * @param state the current import state
-     * @param report the import report
-     * @return a parsed name
-     */
-    private NonViralName<?> parseScientificName(String scientificName, Abcd206ImportState state, Abcd206ImportReport report) {
-        NonViralNameParserImpl nvnpi = NonViralNameParserImpl.NewInstance();
-        NonViralName<?> taxonName = null;
-        boolean problem = false;
-
-        if(DEBUG){
-            logger.info("parseScientificName " + state.getDataHolder().nomenclatureCode.toString());
-        }
-
-        if (state.getDataHolder().nomenclatureCode.toString().equals("Zoological") || state.getDataHolder().nomenclatureCode.toString().contains("ICZN")) {
-            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICZN, null);
-            if (taxonName.hasProblem()) {
-                problem = true;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.toString().equals("Botanical") || state.getDataHolder().nomenclatureCode.toString().contains("ICBN")) {
-            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNAFP, null);
-            if (taxonName.hasProblem()) {
-                problem = true;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.toString().equals("Bacterial") || state.getDataHolder().nomenclatureCode.toString().contains("ICBN")) {
-            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNB, null);
-            if (taxonName.hasProblem()) {
-                problem = true;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.toString().equals("Cultivar") || state.getDataHolder().nomenclatureCode.toString().contains("ICNCP")) {
-            taxonName = nvnpi.parseFullName(scientificName, NomenclaturalCode.ICNCP, null);
-            if (taxonName.hasProblem()) {
-                problem = true;
-            }
-        }
-        if (problem) {
-            String message = String.format("Parsing problems for %s", scientificName);
-            if(taxonName!=null){
-                for (ParserProblem parserProblem : taxonName.getParsingProblems()) {
-                    message += "\n\t- "+parserProblem;
-                }
-            }
-            report.addInfoMessage(message);
-            logger.info(message);
-        }
-        return taxonName;
-
-    }
-
-    /**
-     * Create the name without automatic parsing, either because it failed, or because the user deactivated it.
-     * The name is built upon the ABCD fields
-     * @param atomisedMap : the ABCD atomised fields
-     * @param fullName : the full scientific name
-     * @param state
-     * @return the corresponding Botanical or Zoological or... name
-     */
-    private NonViralName<?> setTaxonNameByType(
-            HashMap<String, String> atomisedMap, String fullName, Abcd206ImportState state) {
-        boolean problem = false;
-        if(DEBUG) {
-            logger.info("settaxonnamebytype " + state.getDataHolder().nomenclatureCode.toString());
-        }
 
-        if (state.getDataHolder().nomenclatureCode.equals("Zoological")) {
-            NonViralName<ZoologicalName> taxonName = ZoologicalName.NewInstance(null);
-            taxonName.setFullTitleCache(fullName, true);
-            taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
-            taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
-            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap,"SpeciesEpithet")));
-            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap,"SubspeciesEpithet")));
 
-            if (taxonName.getGenusOrUninomial() != null){
-                taxonName.setRank(Rank.GENUS());
-            }
 
-            if (taxonName.getInfraGenericEpithet() != null){
-                taxonName.setRank(Rank.SUBGENUS());
-            }
 
-            if (taxonName.getSpecificEpithet() != null){
-                taxonName.setRank(Rank.SPECIES());
-            }
 
-            if (taxonName.getInfraSpecificEpithet() != null){
-                taxonName.setRank(Rank.SUBSPECIES());
-            }
 
-            Team team = null;
-            if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
-                team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
-            }
-            else {
-                if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
-                    team = Team.NewInstance();
-                    team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
-                }
-            }
-            if (team != null) {
-                taxonName.setBasionymAuthorship(team);
-            }
-            else {
-                if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
-                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
-                }
-                else if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
-                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamAndYear"));
-                }
-            }
-            if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
-                team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
-                taxonName.setCombinationAuthorship(team);
-            }
-            if (taxonName.hasProblem()) {
-                logger.info("pb ICZN");
-                problem = true;
-            }
-            else {
-                return taxonName;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.equals("Botanical")) {
-            BotanicalName taxonName = (BotanicalName) parseScientificName(fullName, state, state.getReport());
-            if (taxonName != null){
-                return taxonName;
-            }
-            else{
-                taxonName = BotanicalName.NewInstance(null);
-            }
-            taxonName.setFullTitleCache(fullName, true);
-            taxonName.setGenusOrUninomial(NB(getFromMap(atomisedMap, "Genus")));
-            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "FirstEpithet")));
-            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "InfraSpeEpithet")));
-            try {
-                taxonName.setRank(Rank.getRankByName(getFromMap(atomisedMap, "Rank")));
-            } catch (Exception e) {
-                if (taxonName.getInfraSpecificEpithet() != null){
-                    taxonName.setRank(Rank.SUBSPECIES());
-                }
-                else if (taxonName.getSpecificEpithet() != null){
-                    taxonName.setRank(Rank.SPECIES());
-                }
-                else if (taxonName.getInfraGenericEpithet() != null){
-                    taxonName.setRank(Rank.SUBGENUS());
-                }
-                else if (taxonName.getGenusOrUninomial() != null){
-                    taxonName.setRank(Rank.GENUS());
-                }
-            }
-            Team team = null;
-            if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
-                team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"), true);
-                taxonName.setBasionymAuthorship(team);
-            }
-            if (getFromMap(atomisedMap, "AuthorTeam") != null) {
-                team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeam"), true);
-                taxonName.setCombinationAuthorship(team);
-            }
-            if (team == null) {
-                if (getFromMap(atomisedMap, "AuthorTeamParenthesis") != null) {
-                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeamParenthesis"));
-                }
-                else if (getFromMap(atomisedMap, "AuthorTeam") != null) {
-                    taxonName.setAuthorshipCache(getFromMap(atomisedMap, "AuthorTeam"));
-                }
-            }
-            if (getFromMap(atomisedMap, "CombinationAuthorTeamAndYear") != null) {
-                team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "CombinationAuthorTeamAndYear"), true);
-                taxonName.setCombinationAuthorship(team);
-            }
-            if (taxonName.hasProblem()) {
-                logger.info("pb ICBN");
-                problem = true;
-            }
-            else {
-                return taxonName;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.equals("Bacterial")) {
-            NonViralName<BacterialName> taxonName = BacterialName.NewInstance(null);
-            taxonName.setFullTitleCache(fullName, true);
-            taxonName.setGenusOrUninomial(getFromMap(atomisedMap, "Genus"));
-            taxonName.setInfraGenericEpithet(NB(getFromMap(atomisedMap, "SubGenus")));
-            taxonName.setSpecificEpithet(NB(getFromMap(atomisedMap, "Species")));
-            taxonName.setInfraSpecificEpithet(NB(getFromMap(atomisedMap, "SubspeciesEpithet")));
-
-            if (taxonName.getGenusOrUninomial() != null){
-                taxonName.setRank(Rank.GENUS());
-            }
-            else if (taxonName.getInfraGenericEpithet() != null){
-                taxonName.setRank(Rank.SUBGENUS());
-            }
-            else if (taxonName.getSpecificEpithet() != null){
-                taxonName.setRank(Rank.SPECIES());
-            }
-            else if (taxonName.getInfraSpecificEpithet() != null){
-                taxonName.setRank(Rank.SUBSPECIES());
-            }
-
-            if (getFromMap(atomisedMap, "AuthorTeamAndYear") != null) {
-                Team team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "AuthorTeamAndYear"), true);
-                taxonName.setCombinationAuthorship(team);
-            }
-            if (getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear") != null) {
-                Team team = Team.NewInstance();
-                team.setTitleCache(getFromMap(atomisedMap, "ParentheticalAuthorTeamAndYear"), true);
-                taxonName.setBasionymAuthorship(team);
-            }
-            if (taxonName.hasProblem()) {
-                logger.info("pb ICNB");
-                problem = true;
-            }
-            else {
-                return taxonName;
-            }
-        }
-        else if (state.getDataHolder().nomenclatureCode.equals("Cultivar")) {
-            CultivarPlantName taxonName = CultivarPlantName.NewInstance(null);
-
-            if (taxonName.hasProblem()) {
-                logger.info("pb ICNCP");
-                problem = true;
-            }
-            else {
-                return taxonName;
-            }
-            return taxonName;
-        }
-
-        if (problem) {
-            logger.info("Problem im setTaxonNameByType ");
-            NonViralName<?> taxonName = NonViralName.NewInstance(null);
-            taxonName.setFullTitleCache(fullName, true);
-            return taxonName;
-        }
-        NonViralName<?> tn = NonViralName.NewInstance(null);
-        return tn;
-    }
-
-
-    /**
-     * Get a formated string from a hashmap
-     * @param atomisedMap
-     * @param key
-     * @return
-     */
-    private String getFromMap(HashMap<String, String> atomisedMap, String key) {
-        String value = null;
-        if (atomisedMap.containsKey(key)) {
-            value = atomisedMap.get(key);
-        }
-
-        try {
-            if (value != null && key.matches(".*Year.*")) {
-                value = value.trim();
-                if (value.matches("[a-z A-Z ]*[0-9]{4}$")) {
-                    String tmp = value.split("[0-9]{4}$")[0];
-                    int year = Integer.parseInt(value.split(tmp)[1]);
-                    if (year >= 1752) {
-                        value = tmp;
-                    }
-                    else {
-                        value = null;
-                    }
-                }
-                else {
-                    value = null;
-                }
-            }
-        }
-        catch (Exception e) {
-            value = null;
-        }
-        return value;
-    }
 
     //    private void compareABCDtoCDM(URI urlFileName, List<String> knownElts, Abcd206XMLFieldGetter abcdFieldGetter) {
     //        try {
@@ -2284,7 +1873,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
 
         //existing teams in DB
         Map<String,Team> titleCacheTeam = new HashMap<String, Team>();
-        List<UuidAndTitleCache<Team>> hiberTeam = getAgentService().getTeamUuidAndTitleCache();
+        List<UuidAndTitleCache<Team>> hiberTeam = new ArrayList<UuidAndTitleCache<Team>>();//getAgentService().getTeamUuidAndTitleCache();
 
         Set<UUID> uuids = new HashSet<UUID>();
         for (UuidAndTitleCache<Team> hibernateT:hiberTeam){
@@ -2304,7 +1893,7 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         }
 
         //existing persons in DB
-        List<UuidAndTitleCache<Person>> hiberPersons = getAgentService().getPersonUuidAndTitleCache();
+        List<UuidAndTitleCache<Person>> hiberPersons = new ArrayList<UuidAndTitleCache<Person>>();//getAgentService().getPersonUuidAndTitleCache();
         Map<String,Person> titleCachePerson = new HashMap<String, Person>();
         uuids = new HashSet<UUID>();
         for (UuidAndTitleCache<Person> hibernateP:hiberPersons){
@@ -2375,8 +1964,8 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
             }
         }
 
-        state.getConfig().setTeams(titleCacheTeam);
-        state.getConfig().setPersons(titleCachePerson);
+        ((Abcd206ImportConfigurator) state.getConfig()).setTeams(titleCacheTeam);
+        ((Abcd206ImportConfigurator) state.getConfig()).setPersons(titleCachePerson);
     }
 
     @Override
@@ -2384,4 +1973,13 @@ public class Abcd206Import extends SpecimenImportBase<Abcd206ImportConfigurator,
         return false;
     }
 
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.cdm.io.specimen.SpecimenImportBase#handleSingleUnit(eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase, java.lang.Object)
+     */
+    @Override
+    protected void handleSingleUnit(Abcd206ImportState state, Object item) {
+        // TODO Auto-generated method stub
+
+    }
+
 }
\ No newline at end of file
index 0f571675ce1f8c6e488cb3c8a364466bfb6207e0..bad532c305860473195228827893bb92f4490f91 100644 (file)
@@ -10,7 +10,6 @@
 package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
 \r
 \r
-import java.io.InputStream;\r
 import java.net.URI;\r
 import java.util.HashMap;\r
 import java.util.Map;\r
@@ -23,8 +22,8 @@ import eu.etaxonomy.cdm.database.ICdmDataSource;
 import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;\r
 import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
 import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;\r
-import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;\r
 import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;\r
 import eu.etaxonomy.cdm.io.specimen.SpecimenUserInteraction;\r
 import eu.etaxonomy.cdm.model.agent.Person;\r
 import eu.etaxonomy.cdm.model.agent.Team;\r
@@ -34,8 +33,9 @@ import eu.etaxonomy.cdm.model.reference.Reference;
  * @author p.kelbert\r
  * @created 20.10.2008\r
  * @version 1.0\r
+ * @param <SOURCE>\r
  */\r
-public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206ImportState, InputStream> implements IImportConfigurator, IMatchingImportConfigurator {\r
+public class Abcd206ImportConfigurator<AbcdImportState, InputStream> extends SpecimenImportConfiguratorBase implements IImportConfigurator, IMatchingImportConfigurator {\r
     private static final Logger logger = Logger.getLogger(Abcd206ImportConfigurator.class);\r
 \r
     private static String sourceReferenceTitle = null;\r
@@ -104,11 +104,11 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
      * @param object\r
      * @param b\r
      * @return\r
-     */\r
+     *//*\r
     public static Abcd206ImportConfigurator NewInstance(InputStream stream, ICdmDataSource destination, boolean interact) {\r
         return new Abcd206ImportConfigurator(stream, null, destination, interact);\r
     }\r
-\r
+*/\r
 \r
 \r
     /**\r
@@ -141,10 +141,10 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
     @Override\r
     public InputStream getSource(){\r
         if (super.getSource() != null){\r
-               return super.getSource();\r
+               return (InputStream)super.getSource();\r
         }else if (this.sourceUri != null){\r
                try {\r
-                               InputStream is = UriUtils.getInputStream(sourceUri);\r
+                               InputStream is = (InputStream) UriUtils.getInputStream(sourceUri);\r
                                setSource(is);\r
                                return is;\r
                        } catch (Exception e) {\r
@@ -155,11 +155,7 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         }\r
     }\r
 \r
-    @Override\r
-    public void setSource(InputStream is) {\r
-       //this.sourceUri = null;\r
-       super.setSource(is);\r
-    }\r
+\r
 \r
     public URI getSourceUri(){\r
        return this.sourceUri;\r
@@ -255,17 +251,13 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         return titleCacheTeam;\r
     }\r
 \r
-    public void setTeams(Map<String, Team> titleCacheTeam) {\r
-        this.titleCacheTeam = titleCacheTeam;\r
-    }\r
+\r
 \r
     public Map<String, Person> getPersons() {\r
         return titleCachePerson;\r
     }\r
 \r
-    public void setPersons(Map<String, Person> titleCachePerson) {\r
-        this.titleCachePerson = titleCachePerson;\r
-    }\r
+\r
 \r
     public void setDefaultAuthor(String string) {\r
         defaultAuthor=string;\r
@@ -339,6 +331,7 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         this.ignoreAuthorship = ignoreAuthorship;\r
     }\r
 \r
+    @Override\r
     public boolean isIgnoreAuthorship() {\r
         return ignoreAuthorship;\r
     }\r
@@ -371,6 +364,7 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         this.removeCountryFromLocalityText = removeCountryFromLocalityText;\r
     }\r
 \r
+    @Override\r
     public boolean isRemoveCountryFromLocalityText() {\r
         return removeCountryFromLocalityText;\r
     }\r
@@ -391,6 +385,7 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         this.overwriteExistingSpecimens = overwriteExistingSpecimens;\r
     }\r
 \r
+    @Override\r
     public boolean isIgnoreImportOfExistingSpecimens() {\r
         return ignoreImportOfExistingSpecimens;\r
     }\r
@@ -399,11 +394,16 @@ public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206Imp
         this.ignoreImportOfExistingSpecimens = ignoreImportOfExistingSpecimens;\r
     }\r
 \r
+    @Override\r
     public OccurenceQuery getOccurenceQuery(){\r
         return query;\r
     }\r
 \r
+    @Override\r
     public void setOccurenceQuery(OccurenceQuery query){\r
         this.query = query;\r
     }\r
+\r
+\r
+\r
 }\r
index 073e1ffcd76675f76df9349942b917b9ae0229b6..4e76c998dcdcc4a5f57160c1a2088b9fd84702c7 100644 (file)
@@ -38,7 +38,7 @@ import eu.etaxonomy.cdm.model.taxon.TaxonNode;
  * @date Jan 23, 2015
  *
  */
-public class Abcd206ImportReport {
+public class Abcd206ImportReport extends SpecimenImportReport{
 
     static private final Logger logger = Logger.getLogger(Abcd206ImportReport.class);
 
@@ -51,34 +51,40 @@ public class Abcd206ImportReport {
     private final List<TaxonNode> createdTaxonNodes = new ArrayList<TaxonNode>();
     private final List<String> infoMessages = new ArrayList<String>();
 
+    @Override
     public void addTaxon(Taxon taxon){
         createdTaxa.add(taxon);
     }
 
+    @Override
     public void addName(TaxonNameBase<?, ?> taxonName){
         createdNames.add(taxonName);
     }
 
+    @Override
     public void addTaxonNode(TaxonNode taxonNode){
         createdTaxonNodes.add(taxonNode);
     }
 
+    @Override
     public void addDerivate(DerivedUnit parent, Abcd206ImportConfigurator config){
         addDerivate(parent, null, config);
     }
 
+    @Override
     public void addDerivate(DerivedUnit parent, DerivedUnit child, Abcd206ImportConfigurator config){
-        UnitIdSpecimen parentUnitIdSpecimen = new UnitIdSpecimen(AbcdImportUtility.getUnitID(parent, config), parent);
+        UnitIdSpecimen parentUnitIdSpecimen = new UnitIdSpecimen(SpecimenImportUtility.getUnitID(parent, config), parent);
         List<UnitIdSpecimen> children = derivateMap.get(parentUnitIdSpecimen);
         if(children==null){
             children = new ArrayList<UnitIdSpecimen>();
         }
         if(child!=null){
-            children.add(new UnitIdSpecimen(AbcdImportUtility.getUnitID(child, config), child));
+            children.add(new UnitIdSpecimen(SpecimenImportUtility.getUnitID(child, config), child));
         }
         derivateMap.put(parentUnitIdSpecimen, children);
     }
 
+    @Override
     public void addIndividualAssociation(Taxon taxon, String derivedUnitId, DerivedUnit derivedUnitBase) {
         UnitIdSpecimen derivedUnitIdSpecimen = new UnitIdSpecimen(derivedUnitId, derivedUnitBase);
         List<UnitIdSpecimen> associatedSpecimens = taxonToAssociatedSpecimens.get(taxon);
@@ -89,20 +95,24 @@ public class Abcd206ImportReport {
         taxonToAssociatedSpecimens.put(taxon, associatedSpecimens);
     }
 
+    @Override
     public void addAlreadyExistingSpecimen(String unitId, DerivedUnit derivedUnit){
         alreadyExistingSpecimens.add(new UnitIdSpecimen(unitId, derivedUnit));
     }
 
+    @Override
     public void addException(String message, Exception e) {
         StringWriter errors = new StringWriter();
         e.printStackTrace(new PrintWriter(errors));
         infoMessages.add(message+"\n"+e.getMessage()+"\n"+errors.toString());
     }
 
+    @Override
     public void addInfoMessage(String message) {
         infoMessages.add(message);
     }
 
+    @Override
     public void printReport(URI reportUri) {
         PrintStream out;
         if(reportUri != null){
@@ -120,6 +130,7 @@ public class Abcd206ImportReport {
     }
 
 
+    @Override
     public void printReport(PrintStream out) {
 
         out.println("++++++++Import Report+++++++++");
index 96a87458a81044c68ad5ade10f9e33dfc2a6d162..359c95bbdf46be12d40f808f0ad0efba3929661c 100644 (file)
 package eu.etaxonomy.cdm.io.specimen.abcd206.in;
 
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
 import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.List;
 
 import org.apache.log4j.Logger;
-import org.springframework.transaction.TransactionStatus;
 
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.io.common.CdmImportBase;
-import eu.etaxonomy.cdm.io.common.ImportStateBase;
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase;
 import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.model.taxon.Classification;
 
 /**
  * @author a.mueller
  * @created 11.05.2009
  * @version 1.0
  */
-public class Abcd206ImportState extends ImportStateBase<Abcd206ImportConfigurator, CdmImportBase<Abcd206ImportConfigurator,Abcd206ImportState>>{
+public class Abcd206ImportState extends SpecimenImportStateBase<Abcd206ImportConfigurator<Abcd206ImportState, InputStream>, Abcd206ImportState>{
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(Abcd206ImportState.class);
 
-       private TransactionStatus tx;
-
-       private ICdmApplicationConfiguration cdmRepository;
 
        private String prefix;
 
-    private Abcd206ImportReport report;
 
-       private Classification classification = null;
-       private Classification defaultClassification = null;
-       private Reference ref = null;
+
+
 
        private Abcd206DataHolder dataHolder;
-       private DerivedUnit derivedUnitBase;
+
 
        private List<OriginalSourceBase<?>> associationRefs = new ArrayList<OriginalSourceBase<?>>();
        private boolean associationSourcesSet=false;
@@ -58,72 +47,21 @@ public class Abcd206ImportState extends ImportStateBase<Abcd206ImportConfigurato
        private List<OriginalSourceBase<?>> derivedUnitSources = new ArrayList<OriginalSourceBase<?>>();
        private boolean derivedUnitSourcesSet=false;
        private boolean descriptionGroupSet = false;
-       private TaxonDescription descriptionGroup = null;
+
 
 //****************** CONSTRUCTOR ***************************************************/
 
        public Abcd206ImportState(Abcd206ImportConfigurator config) {
                super(config);
-        report = new Abcd206ImportReport();
+        setReport(new SpecimenImportReport());
         setTransformer(new AbcdTransformer());
        }
 
 //************************ GETTER / SETTER *****************************************/
 
-       public TransactionStatus getTx() {
-               return tx;
-       }
-
-       public void setTx(TransactionStatus tx) {
-               this.tx = tx;
-       }
-
-       public ICdmApplicationConfiguration getCdmRepository() {
-               return cdmRepository;
-       }
-
-       public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {
-               this.cdmRepository = cdmRepository;
-       }
-
-    public Classification getClassification() {
-        return classification;
-    }
-
-    public void setClassification(Classification classification) {
-        this.classification = classification;
-    }
-
-    public Classification getDefaultClassification() {
-        if(defaultClassification==null){
-            final String defaultClassificationAbcd = "Default Classification ABCD";
-            for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){
-                if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)
-                        && classif.getCitation()!=null && classif.getCitation().equals(getRef())) {
-                    defaultClassification = classif;
-                    break;
-                }
-            }
-            if(defaultClassification==null){
-                defaultClassification = Classification.NewInstance(defaultClassificationAbcd);
-                cdmRepository.getClassificationService().save(defaultClassification);
-            }
-        }
-        return defaultClassification;
-    }
-
-    public void setDefaultClassification(Classification defaultClassification) {
-        this.defaultClassification = defaultClassification;
-    }
-
-    public Reference getRef() {
-        return ref;
-    }
 
-    public void setRef(Reference ref) {
-        this.ref = ref;
-    }
 
+    @Override
     public Abcd206DataHolder getDataHolder() {
         return dataHolder;
     }
@@ -132,13 +70,7 @@ public class Abcd206ImportState extends ImportStateBase<Abcd206ImportConfigurato
         this.dataHolder = dataHolder;
     }
 
-    public DerivedUnit getDerivedUnitBase() {
-        return derivedUnitBase;
-    }
 
-    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
-        this.derivedUnitBase = derivedUnitBase;
-    }
 
     public List<OriginalSourceBase<?>> getAssociationRefs() {
         return associationRefs;
@@ -196,13 +128,7 @@ public class Abcd206ImportState extends ImportStateBase<Abcd206ImportConfigurato
         this.descriptionGroupSet = descriptionGroupSet;
     }
 
-    public TaxonDescription getDescriptionGroup() {
-        return descriptionGroup;
-    }
 
-    public void setDescriptionGroup(TaxonDescription descriptionGroup) {
-        this.descriptionGroup = descriptionGroup;
-    }
 
     public void setPrefix(String prefix) {
         this.prefix = prefix;
@@ -212,19 +138,17 @@ public class Abcd206ImportState extends ImportStateBase<Abcd206ImportConfigurato
         return prefix;
     }
 
-    public Abcd206ImportReport getReport(){
-        return report;
-    }
 
     @Override
     public byte[] getReportAsByteArray() {
         ByteArrayOutputStream importStream = new ByteArrayOutputStream();
-        report.printReport(new PrintStream(importStream));
+        getReport().printReport(new PrintStream(importStream));
         return importStream.toByteArray();
     }
 
+    @Override
     public void reset() {
         getDataHolder().reset();
-        derivedUnitBase = null;
+        setDerivedUnitBase(null);
     }
 }
index fdb32b1b9a4525c57295bf0c7691ce8d52adac90..b1210af593e6a519e7ca7711a33c424667e4f263 100644 (file)
@@ -99,10 +99,10 @@ public class Abcd206XMLFieldGetter {
                             }
                         }
                     } else if (identifications.item(m).getNodeName().equals(prefix + "PreferredFlag")) {
-                        if (dataHolder.nomenclatureCode != null&& dataHolder.nomenclatureCode != "") {
+                        if (dataHolder.getNomenclatureCode() != null&& dataHolder.getNomenclatureCode() != "") {
                             // logger.info("TMP NAME P" + tmpName);
 
-                            dataHolder.identificationList.add(new Identification(tmpName, identifications.item(m).getTextContent(), dataHolder.nomenclatureCode));
+                            dataHolder.identificationList.add(new Identification(tmpName, identifications.item(m).getTextContent(), dataHolder.getNomenclatureCode()));
                         } else {
                             dataHolder.identificationList.add(new Identification(tmpName, identifications.item(m).getTextContent()));
                         }
@@ -119,7 +119,7 @@ public class Abcd206XMLFieldGetter {
         boolean hasPref = false;
         for (int j = 0; j < group.getLength(); j++) {
             if (group.item(j).getNodeName().equals(prefix + "Identification")) {
-                dataHolder.nomenclatureCode = "";
+                dataHolder.setNomenclatureCode("");
                 identifications = group.item(j).getChildNodes();
                 for (int m = 0; m < identifications.getLength(); m++) {
                     if (identifications.item(m).getNodeName().equals(prefix + "Result")) {
@@ -136,9 +136,9 @@ public class Abcd206XMLFieldGetter {
                     }
                 }
                 if (!hasPref && tmpName != null) {
-                    if (dataHolder.nomenclatureCode != null
-                            && dataHolder.nomenclatureCode != "") {
-                        dataHolder.identificationList.add(new Identification(tmpName, "0", dataHolder.nomenclatureCode));
+                    if (dataHolder.getNomenclatureCode() != null
+                            && dataHolder.getNomenclatureCode() != "") {
+                        dataHolder.identificationList.add(new Identification(tmpName, "0", dataHolder.getNomenclatureCode()));
                     } else {
                         dataHolder.identificationList.add(new Identification(tmpName, "0"));
                     }
@@ -175,20 +175,20 @@ public class Abcd206XMLFieldGetter {
                             if (scnames.item(n).hasChildNodes()) {
                                 String tmp = scnames.item(n).getChildNodes().item(1).getNodeName();
                                 if (tmp.indexOf(prefix) != -1&& prefix.length() > 0) {
-                                    dataHolder.nomenclatureCode = tmp.split(prefix)[1];
+                                    dataHolder.setNomenclatureCode(tmp.split(prefix)[1]);
                                 }
                                 else {
-                                    dataHolder.nomenclatureCode = scnames.item(n).getChildNodes().item(1).getNodeName();
+                                    dataHolder.setNomenclatureCode(scnames.item(n).getChildNodes().item(1).getNodeName());
                                 }
                             }
                         } catch (Exception e) {
                             if(DEBUG) {
                                 logger.warn("PB nomenclaturecode");
                             }
-                            dataHolder.nomenclatureCode = "";
+                            dataHolder.setNomenclatureCode("");
                         }
                         atomised = scnames.item(n).getChildNodes().item(1).getChildNodes();
-                        dataHolder.atomisedIdentificationList.add(this.getAtomisedNames(dataHolder.nomenclatureCode,atomised));
+                        dataHolder.getAtomisedIdentificationList().add(this.getAtomisedNames(dataHolder.getNomenclatureCode(),atomised));
                     }
                 }
             }
index 4826b43ff2f63699fe25d6629d7b1e6adfda9a62..8df89315a68b13a5138283ada0d4aa8b62340306 100644 (file)
@@ -1,45 +1,45 @@
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in;
-
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-
-/**
- * @author pplitzner
- * @date 16.06.2015
- *
- */
-public class AbcdImportUtility {
-
-    public static String getUnitID(DerivedUnit derivedUnit, Abcd206ImportConfigurator config){
-        if(config.isMapUnitIdToAccessionNumber()){
-            return derivedUnit.getAccessionNumber();
-        }
-        if(config.isMapUnitIdToBarcode()){
-            return derivedUnit.getBarcode();
-        }
-        return derivedUnit.getCatalogNumber();
-    }
-
-    public static void setUnitID(DerivedUnit derivedUnit, String unitId, Abcd206ImportConfigurator config){
-        if(config.isMapUnitIdToCatalogNumber()
-                || !(config.isMapUnitIdToAccessionNumber() || config.isMapUnitIdToBarcode() || config.isMapUnitIdToCatalogNumber())){
-            // set catalog number (default if nothing is set)
-            derivedUnit.setCatalogNumber(unitId);
-        }
-        if(config.isMapUnitIdToAccessionNumber()){
-            derivedUnit.setAccessionNumber(unitId);
-        }
-        if(config.isMapUnitIdToBarcode()){
-            derivedUnit.setBarcode(unitId);
-        }
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
+\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+\r
+/**\r
+ * @author pplitzner\r
+ * @date 16.06.2015\r
+ *\r
+ */\r
+public class AbcdImportUtility {\r
+\r
+    public static String getUnitID(DerivedUnit derivedUnit, Abcd206ImportConfigurator config){\r
+        if(config.isMapUnitIdToAccessionNumber()){\r
+            return derivedUnit.getAccessionNumber();\r
+        }\r
+        if(config.isMapUnitIdToBarcode()){\r
+            return derivedUnit.getBarcode();\r
+        }\r
+        return derivedUnit.getCatalogNumber();\r
+    }\r
+\r
+    public static void setUnitID(DerivedUnit derivedUnit, String unitId, Abcd206ImportConfigurator config){\r
+        if(config.isMapUnitIdToCatalogNumber()\r
+                || !(config.isMapUnitIdToAccessionNumber() || config.isMapUnitIdToBarcode() || config.isMapUnitIdToCatalogNumber())){\r
+            // set catalog number (default if nothing is set)\r
+            derivedUnit.setCatalogNumber(unitId);\r
+        }\r
+        if(config.isMapUnitIdToAccessionNumber()){\r
+            derivedUnit.setAccessionNumber(unitId);\r
+        }\r
+        if(config.isMapUnitIdToBarcode()){\r
+            derivedUnit.setBarcode(unitId);\r
+        }\r
+    }\r
+\r
+}\r
index 0237fc05a7c2619b0ad3a54cbfd3aef591899bd3..c63688680d4b38247e952b04e320f6365499ce5f 100644 (file)
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.Date;
-import java.util.List;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.log4j.Logger;
-import org.joda.time.DateTime;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
-import eu.etaxonomy.cdm.persistence.query.MatchMode;
-
-/**
- * @author pplitzner
- * @date 16.06.2015
- *
- */
-public class AbcdParseUtility {
-
-    private static final Logger logger = Logger.getLogger(AbcdParseUtility.class);
-
-
-    public static URI parseFirstUri(NodeList nodeList, Abcd206ImportReport report){
-        URI uri = null;
-        String textContent = parseFirstTextContent(nodeList);
-        if(textContent!=null){
-            try {
-                uri = URI.create(textContent);
-            } catch (IllegalArgumentException e) {
-                if(report!=null){
-                    report.addException("Exception during URI parsing!", e);
-                }
-            }
-        }
-        return uri;
-    }
-
-    public static String parseFirstTextContent(NodeList nodeList){
-        return parseFirstTextContent(nodeList, true);
-    }
-
-    public static String parseFirstTextContent(NodeList nodeList, boolean cleanUpWhiteSpaces){
-        String string = null;
-        if(nodeList.getLength()>0){
-            string = nodeList.item(0).getTextContent();
-            if(cleanUpWhiteSpaces){
-                string = string.replace("\n", "").replaceAll("( )+", " ").trim();
-            }
-        }
-        return string;
-    }
-
-    public static Double parseFirstDouble(NodeList nodeList, Abcd206ImportReport report){
-        if(nodeList.getLength()>0){
-            return parseDouble(nodeList.item(0), report);
-        }
-        return null;
-    }
-
-    public static Double parseDouble(Node node, Abcd206ImportReport report){
-        String message = "Could not parse double value for node " + node.getNodeName();
-        Double doubleValue = null;
-        try{
-            String textContent = node.getTextContent();
-            //remove 1000 dots
-            textContent = textContent.replace(".","");
-            //convert commmas
-            textContent = textContent.replace(",",".");
-            doubleValue = Double.parseDouble(textContent);
-        } catch (NullPointerException npe){
-            logger.error(message, npe);
-            if(report!=null){
-                report.addException(message, npe);
-            }
-        } catch (NumberFormatException nfe){
-            logger.error(message, nfe);
-            if(report!=null){
-                report.addException(message, nfe);
-            }
-        }
-        return doubleValue;
-    }
-
-    public static DateTime parseFirstDateTime(NodeList nodeList) {
-        DateTime dateTime = null;
-        String textContent = parseFirstTextContent(nodeList);
-        if(textContent!=null){
-            dateTime = DateTime.parse(textContent);
-        }
-        return dateTime;
-    }
-
-    public static Date parseFirstDate(NodeList nodeList) {
-        Date date = null;
-        DateTime dateTime = parseFirstDateTime(nodeList);
-        if(dateTime!=null){
-            date = dateTime.toDate();
-        }
-        return date;
-    }
-
-    public static Reference parseFirstReference(NodeList referenceNodeList, ICdmApplicationConfiguration cdmAppController){
-        String referenceCitation = AbcdParseUtility.parseFirstTextContent(referenceNodeList);
-        //check if reference already exists
-        List<Reference> matchingReferences = cdmAppController.getReferenceService().findByTitle(Reference.class, referenceCitation, MatchMode.EXACT, null, null, null, null, null).getRecords();
-        Reference reference;
-        if(matchingReferences.size()==1){
-            reference = matchingReferences.iterator().next();
-        }
-        else{
-            reference = ReferenceFactory.newGeneric();
-            reference.setTitle(referenceCitation);
-            cdmAppController.getReferenceService().saveOrUpdate(reference);
-        }
-        return reference;
-    }
-
-    /**
-     * Return the wrapper with the list of root nodes for an ABCD XML file
-     * @param fileName: the file's location
-     * @return a wrapper with a list of root nodes ("Unit")
-     */
-    public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, Abcd206ImportReport report) {
-        UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();
-        NodeList unitList = null;
-        try {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder = factory.newDocumentBuilder();
-
-            Document document = builder.parse(inputStream);
-            Element root = document.getDocumentElement();
-            unitList = root.getElementsByTagName("Unit");
-            if (unitList.getLength()>0) {
-                unitAssociationWrapper.setPrefix("");
-                unitAssociationWrapper.setAssociatedUnits(unitList);
-                return unitAssociationWrapper;
-            }
-            unitList = root.getElementsByTagName("abcd:Unit");
-            if (unitList.getLength()>0) {
-                unitAssociationWrapper.setPrefix("abcd:");
-                unitAssociationWrapper.setAssociatedUnits(unitList);
-                return unitAssociationWrapper;
-            }
-            unitList = root.getElementsByTagName("abcd21:Unit");
-            if (unitList.getLength()>0) {
-                unitAssociationWrapper.setPrefix("abcd21:");
-                unitAssociationWrapper.setAssociatedUnits(unitList);
-            }
-        } catch (Exception e) {
-            logger.warn(e);
-            if(report!=null){
-                report.addException("Exception during parsing of nodeList!", e);
-            }
-        }
-        return unitAssociationWrapper;
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
+\r
+import java.io.InputStream;\r
+import java.net.URI;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import javax.xml.parsers.DocumentBuilder;\r
+import javax.xml.parsers.DocumentBuilderFactory;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.joda.time.DateTime;\r
+import org.w3c.dom.Document;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
+\r
+/**\r
+ * @author pplitzner\r
+ * @date 16.06.2015\r
+ *\r
+ */\r
+public class AbcdParseUtility {\r
+\r
+    private static final Logger logger = Logger.getLogger(AbcdParseUtility.class);\r
+\r
+\r
+    public static URI parseFirstUri(NodeList nodeList, SpecimenImportReport report){\r
+        URI uri = null;\r
+        String textContent = parseFirstTextContent(nodeList);\r
+        if(textContent!=null){\r
+            try {\r
+                uri = URI.create(textContent);\r
+            } catch (IllegalArgumentException e) {\r
+                if(report!=null){\r
+                    report.addException("Exception during URI parsing!", e);\r
+                }\r
+            }\r
+        }\r
+        return uri;\r
+    }\r
+\r
+    public static String parseFirstTextContent(NodeList nodeList){\r
+        return parseFirstTextContent(nodeList, true);\r
+    }\r
+\r
+    public static String parseFirstTextContent(NodeList nodeList, boolean cleanUpWhiteSpaces){\r
+        String string = null;\r
+        if(nodeList.getLength()>0){\r
+            string = nodeList.item(0).getTextContent();\r
+            if(cleanUpWhiteSpaces){\r
+                string = string.replace("\n", "").replaceAll("( )+", " ").trim();\r
+            }\r
+        }\r
+        return string;\r
+    }\r
+\r
+    public static Double parseFirstDouble(NodeList nodeList, SpecimenImportReport report){\r
+        if(nodeList.getLength()>0){\r
+            return parseDouble(nodeList.item(0), report);\r
+        }\r
+        return null;\r
+    }\r
+\r
+    public static Double parseDouble(Node node, SpecimenImportReport report){\r
+        String message = "Could not parse double value for node " + node.getNodeName();\r
+        Double doubleValue = null;\r
+        try{\r
+            String textContent = node.getTextContent();\r
+            //remove 1000 dots\r
+            textContent = textContent.replace(".","");\r
+            //convert commmas\r
+            textContent = textContent.replace(",",".");\r
+            doubleValue = Double.parseDouble(textContent);\r
+        } catch (NullPointerException npe){\r
+            logger.error(message, npe);\r
+            if(report!=null){\r
+                report.addException(message, npe);\r
+            }\r
+        } catch (NumberFormatException nfe){\r
+            logger.error(message, nfe);\r
+            if(report!=null){\r
+                report.addException(message, nfe);\r
+            }\r
+        }\r
+        return doubleValue;\r
+    }\r
+\r
+    public static DateTime parseFirstDateTime(NodeList nodeList) {\r
+        DateTime dateTime = null;\r
+        String textContent = parseFirstTextContent(nodeList);\r
+        if(textContent!=null){\r
+            dateTime = DateTime.parse(textContent);\r
+        }\r
+        return dateTime;\r
+    }\r
+\r
+    public static Date parseFirstDate(NodeList nodeList) {\r
+        Date date = null;\r
+        DateTime dateTime = parseFirstDateTime(nodeList);\r
+        if(dateTime!=null){\r
+            date = dateTime.toDate();\r
+        }\r
+        return date;\r
+    }\r
+\r
+    public static Reference parseFirstReference(NodeList referenceNodeList, ICdmApplicationConfiguration cdmAppController){\r
+        String referenceCitation = AbcdParseUtility.parseFirstTextContent(referenceNodeList);\r
+        //check if reference already exists\r
+        List<Reference> matchingReferences = cdmAppController.getReferenceService().findByTitle(Reference.class, referenceCitation, MatchMode.EXACT, null, null, null, null, null).getRecords();\r
+        Reference reference;\r
+        if(matchingReferences.size()==1){\r
+            reference = matchingReferences.iterator().next();\r
+        }\r
+        else{\r
+            reference = ReferenceFactory.newGeneric();\r
+            reference.setTitle(referenceCitation);\r
+            cdmAppController.getReferenceService().saveOrUpdate(reference);\r
+        }\r
+        return reference;\r
+    }\r
+\r
+    /**\r
+     * Return the wrapper with the list of root nodes for an ABCD XML file\r
+     * @param fileName: the file's location\r
+     * @return a wrapper with a list of root nodes ("Unit")\r
+     */\r
+    public static UnitAssociationWrapper parseUnitsNodeList(InputStream inputStream, SpecimenImportReport report) {\r
+        UnitAssociationWrapper unitAssociationWrapper = new UnitAssociationWrapper();\r
+        NodeList unitList = null;\r
+        try {\r
+            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r
+            DocumentBuilder builder = factory.newDocumentBuilder();\r
+\r
+            Document document = builder.parse(inputStream);\r
+            Element root = document.getDocumentElement();\r
+            unitList = root.getElementsByTagName("Unit");\r
+            if (unitList.getLength()>0) {\r
+                unitAssociationWrapper.setPrefix("");\r
+                unitAssociationWrapper.setAssociatedUnits(unitList);\r
+                return unitAssociationWrapper;\r
+            }\r
+            unitList = root.getElementsByTagName("abcd:Unit");\r
+            if (unitList.getLength()>0) {\r
+                unitAssociationWrapper.setPrefix("abcd:");\r
+                unitAssociationWrapper.setAssociatedUnits(unitList);\r
+                return unitAssociationWrapper;\r
+            }\r
+            unitList = root.getElementsByTagName("abcd21:Unit");\r
+            if (unitList.getLength()>0) {\r
+                unitAssociationWrapper.setPrefix("abcd21:");\r
+                unitAssociationWrapper.setAssociatedUnits(unitList);\r
+            }\r
+        } catch (Exception e) {\r
+            logger.warn(e);\r
+            if(report!=null){\r
+                report.addException("Exception during parsing of nodeList!", e);\r
+            }\r
+        }\r
+        return unitAssociationWrapper;\r
+    }\r
+\r
+}\r
index cd02ac4671eb9d7881af961179bd989b8decc09a..67e40b18e67ab4081765c8017614d50815e54b66 100644 (file)
@@ -1,60 +1,60 @@
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in;
-
-import java.util.List;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.model.agent.AgentBase;
-import eu.etaxonomy.cdm.model.agent.Person;
-import eu.etaxonomy.cdm.persistence.query.MatchMode;
-
-/**
- * @author pplitzner
- * @date 16.06.2015
- *
- */
-public class AbcdPersonParser {
-
-    private final String prefix;
-
-    private final Abcd206ImportReport report;
-
-    private final ICdmApplicationConfiguration cdmAppController;
-
-
-    public AbcdPersonParser(String prefix, Abcd206ImportReport report, ICdmApplicationConfiguration cdmAppController) {
-        this.prefix = prefix;
-        this.report = report;
-        this.cdmAppController = cdmAppController;
-    }
-
-
-    public AgentBase<?> parse(Element item) {
-        AgentBase<?> agentBase = null;
-        NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");
-        String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);
-        if(fullName!=null){
-            List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();
-            if(matchingAgents.size()==1){
-                agentBase = matchingAgents.iterator().next();
-            }
-            else{
-                agentBase = Person.NewTitledInstance(fullName);
-            }
-        }
-        return agentBase;
-    }
-
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
+\r
+import java.util.List;\r
+\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.NodeList;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.model.agent.AgentBase;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
+\r
+/**\r
+ * @author pplitzner\r
+ * @date 16.06.2015\r
+ *\r
+ */\r
+public class AbcdPersonParser {\r
+\r
+    private final String prefix;\r
+\r
+    private final SpecimenImportReport report;\r
+\r
+    private final ICdmApplicationConfiguration cdmAppController;\r
+\r
+\r
+    public AbcdPersonParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {\r
+        this.prefix = prefix;\r
+        this.report = report;\r
+        this.cdmAppController = cdmAppController;\r
+    }\r
+\r
+\r
+    public AgentBase<?> parse(Element item) {\r
+        AgentBase<?> agentBase = null;\r
+        NodeList fullNameList = item.getElementsByTagName(prefix+"FullName");\r
+        String fullName = AbcdParseUtility.parseFirstTextContent(fullNameList);\r
+        if(fullName!=null){\r
+            List<AgentBase> matchingAgents = cdmAppController.getAgentService().findByTitle(AgentBase.class, fullName, MatchMode.EXACT, null, null, null, null, null).getRecords();\r
+            if(matchingAgents.size()==1){\r
+                agentBase = matchingAgents.iterator().next();\r
+            }\r
+            else{\r
+                agentBase = Person.NewTitledInstance(fullName);\r
+            }\r
+        }\r
+        return agentBase;\r
+    }\r
+\r
+\r
+}\r
index e934017c11c1d889e382128430e07bd6917136a4..0557a83c7c5f604f1fcc383c866a97064cf2281e 100644 (file)
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in.molecular;
-
-import java.util.Date;
-import java.util.UUID;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportReport;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdPersonParser;
-import eu.etaxonomy.cdm.model.agent.AgentBase;
-import eu.etaxonomy.cdm.model.common.DefinedTerm;
-import eu.etaxonomy.cdm.model.common.TimePeriod;
-import eu.etaxonomy.cdm.model.molecular.DnaSample;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
-import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
-
-/**
- * @author pplitzner
- * @date 15.06.2015
- *
- */
-public class AbcdDnaParser {
-
-    private final String prefix;
-
-    private final Abcd206ImportReport report;
-
-    private final ICdmApplicationConfiguration cdmAppController;
-
-    public AbcdDnaParser(String prefix, Abcd206ImportReport report, ICdmApplicationConfiguration cdmAppController) {
-        this.prefix = prefix;
-        this.report = report;
-        this.cdmAppController = cdmAppController;
-    }
-
-    public DnaSample parse(Element item, Abcd206ImportState state) {
-        FieldUnit fieldUnit = FieldUnit.NewInstance();
-        DnaSample dnaSample = DnaSample.NewInstance();
-        DerivationEvent.NewSimpleInstance(fieldUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
-
-        //specimen unit
-        NodeList specimenUnitList = item.getElementsByTagName(prefix+"SpecimenUnit");
-        if(specimenUnitList.item(0)!=null && specimenUnitList.item(0) instanceof Element){
-            parseSpecimenUnit((Element)specimenUnitList.item(0), dnaSample);
-        }
-        NodeList unitExtensions = item.getElementsByTagName(prefix+"UnitExtension");
-        for(int i=0;i<unitExtensions.getLength();i++){
-            if(unitExtensions.item(i) instanceof Element){
-                Element unitExtension = (Element) unitExtensions.item(i);
-                NodeList ggbn = unitExtension.getElementsByTagName("ggbn:GGBN");
-                if(ggbn.getLength()>0){
-                    AbcdGgbnParser ggbnParser = new AbcdGgbnParser(report, cdmAppController);
-                    ggbnParser.parse(ggbn, dnaSample, state);
-                }
-            }
-        }
-        return dnaSample;
-    }
-
-    private void parseSpecimenUnit(Element item, DnaSample dnaSample) {
-        NodeList preparationsList = item.getElementsByTagName(prefix+"Preparations");
-        if(preparationsList.item(0)!=null && preparationsList.item(0) instanceof Element){
-            parsePreparations((Element) preparationsList.item(0), dnaSample);
-        }
-        NodeList preservationsList = item.getElementsByTagName(prefix+"Preservations");
-        if(preservationsList.item(0)!=null && preservationsList.item(0) instanceof Element){
-            parsePreservations((Element) preservationsList.item(0), dnaSample);
-        }
-    }
-
-    private void parsePreparations(Element item, DnaSample dnaSample) {
-        NodeList preparationList = item.getElementsByTagName(prefix+"preparation");
-        for(int i=0;i<preparationList.getLength();i++){
-            Node node = preparationList.item(i);
-            if(node instanceof Element){
-                DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
-
-                String preparationType = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preparationType"));
-                //preparation materials
-                String preparationMaterials = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preparationMaterials"));
-                derivedFrom.setDescription(preparationMaterials);
-                //preparation actor
-                NodeList preparationAgentList = ((Element) node).getElementsByTagName(prefix+"preparationAgent");
-                if(preparationAgentList.item(0)!=null && preparationAgentList.item(0) instanceof Element){
-                    AgentBase<?> preparationAgent = parsePreparationAgent((Element)preparationAgentList.item(0));
-                    derivedFrom.setActor(preparationAgent);
-                }
-                //preparation date
-                Date preparationDate = AbcdParseUtility.parseFirstDate(((Element) node).getElementsByTagName(prefix+"preparationDate"));
-                derivedFrom.setTimeperiod(TimePeriod.NewInstance(preparationDate, null));
-                //sample designation
-                NodeList sampleDesignationsList = ((Element) node).getElementsByTagName(prefix+"sampleDesignations");
-                if(sampleDesignationsList.item(0)!=null && sampleDesignationsList.item(0) instanceof Element){
-                    parseSampleDesignations((Element)sampleDesignationsList.item(0), dnaSample);
-                }
-            }
-        }
-    }
-
-    /**
-     * @param item
-     * @param dnaSample
-     */
-    private void parseSampleDesignations(Element item, DnaSample dnaSample) {
-        NodeList sampleDesignationList = item.getElementsByTagName(prefix+"sampleDesignation");
-        for(int i=0;i<sampleDesignationList.getLength();i++){
-            dnaSample.addIdentifier(sampleDesignationList.item(i).getTextContent(), (DefinedTerm)cdmAppController.getTermService().find(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc")));
-        }
-
-    }
-
-    private AgentBase<?> parsePreparationAgent(Element item) {
-        AgentBase<?> agentBase = null;
-        NodeList personList = item.getElementsByTagName(prefix+"Person");
-        if(personList.item(0)!=null && personList.item(0) instanceof Element){
-            agentBase = new AbcdPersonParser(prefix,report, cdmAppController).parse((Element)personList.item(0));
-        }
-        return agentBase;
-    }
-
-    private void parsePreservations(Element item, DnaSample dnaSample) {
-        NodeList preservationList = item.getElementsByTagName(prefix+"preservation");
-        for(int i=0;i<preservationList.getLength();i++){
-            Node node = preservationList.item(i);
-            if(node instanceof Element){
-                PreservationMethod preservation = PreservationMethod.NewInstance();
-                dnaSample.setPreservation(preservation);
-
-                String preservationType = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preservationType"));
-
-                Double preservationTemperature = AbcdParseUtility.parseFirstDouble(((Element) node).getElementsByTagName(prefix+"preservationTemperature"), report);
-                preservation.setTemperature(preservationTemperature);
-            }
-        }
-    }
-
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in.molecular;\r
+\r
+import java.util.Date;\r
+import java.util.UUID;\r
+\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdPersonParser;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;\r
+import eu.etaxonomy.cdm.model.agent.AgentBase;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
+import eu.etaxonomy.cdm.model.common.TimePeriod;\r
+import eu.etaxonomy.cdm.model.molecular.DnaSample;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;\r
+\r
+/**\r
+ * @author pplitzner\r
+ * @date 15.06.2015\r
+ *\r
+ */\r
+public class AbcdDnaParser {\r
+\r
+    private final String prefix;\r
+\r
+    private final SpecimenImportReport report;\r
+\r
+    private final ICdmApplicationConfiguration cdmAppController;\r
+\r
+    public AbcdDnaParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {\r
+        this.prefix = prefix;\r
+        this.report = report;\r
+        this.cdmAppController = cdmAppController;\r
+    }\r
+\r
+    public DnaSample parse(Element item, Abcd206ImportState state) {\r
+        FieldUnit fieldUnit = FieldUnit.NewInstance();\r
+        DnaSample dnaSample = DnaSample.NewInstance();\r
+        DerivationEvent.NewSimpleInstance(fieldUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());\r
+\r
+        //specimen unit\r
+        NodeList specimenUnitList = item.getElementsByTagName(prefix+"SpecimenUnit");\r
+        if(specimenUnitList.item(0)!=null && specimenUnitList.item(0) instanceof Element){\r
+            parseSpecimenUnit((Element)specimenUnitList.item(0), dnaSample);\r
+        }\r
+        NodeList unitExtensions = item.getElementsByTagName(prefix+"UnitExtension");\r
+        for(int i=0;i<unitExtensions.getLength();i++){\r
+            if(unitExtensions.item(i) instanceof Element){\r
+                Element unitExtension = (Element) unitExtensions.item(i);\r
+                NodeList ggbn = unitExtension.getElementsByTagName("ggbn:GGBN");\r
+                if(ggbn.getLength()>0){\r
+                    AbcdGgbnParser ggbnParser = new AbcdGgbnParser(report, cdmAppController);\r
+                    ggbnParser.parse(ggbn, dnaSample, state);\r
+                }\r
+            }\r
+        }\r
+        return dnaSample;\r
+    }\r
+\r
+    private void parseSpecimenUnit(Element item, DnaSample dnaSample) {\r
+        NodeList preparationsList = item.getElementsByTagName(prefix+"Preparations");\r
+        if(preparationsList.item(0)!=null && preparationsList.item(0) instanceof Element){\r
+            parsePreparations((Element) preparationsList.item(0), dnaSample);\r
+        }\r
+        NodeList preservationsList = item.getElementsByTagName(prefix+"Preservations");\r
+        if(preservationsList.item(0)!=null && preservationsList.item(0) instanceof Element){\r
+            parsePreservations((Element) preservationsList.item(0), dnaSample);\r
+        }\r
+    }\r
+\r
+    private void parsePreparations(Element item, DnaSample dnaSample) {\r
+        NodeList preparationList = item.getElementsByTagName(prefix+"preparation");\r
+        for(int i=0;i<preparationList.getLength();i++){\r
+            Node node = preparationList.item(i);\r
+            if(node instanceof Element){\r
+                DerivationEvent derivedFrom = dnaSample.getDerivedFrom();\r
+\r
+                String preparationType = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preparationType"));\r
+                //preparation materials\r
+                String preparationMaterials = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preparationMaterials"));\r
+                derivedFrom.setDescription(preparationMaterials);\r
+                //preparation actor\r
+                NodeList preparationAgentList = ((Element) node).getElementsByTagName(prefix+"preparationAgent");\r
+                if(preparationAgentList.item(0)!=null && preparationAgentList.item(0) instanceof Element){\r
+                    AgentBase<?> preparationAgent = parsePreparationAgent((Element)preparationAgentList.item(0));\r
+                    derivedFrom.setActor(preparationAgent);\r
+                }\r
+                //preparation date\r
+                Date preparationDate = AbcdParseUtility.parseFirstDate(((Element) node).getElementsByTagName(prefix+"preparationDate"));\r
+                derivedFrom.setTimeperiod(TimePeriod.NewInstance(preparationDate, null));\r
+                //sample designation\r
+                NodeList sampleDesignationsList = ((Element) node).getElementsByTagName(prefix+"sampleDesignations");\r
+                if(sampleDesignationsList.item(0)!=null && sampleDesignationsList.item(0) instanceof Element){\r
+                    parseSampleDesignations((Element)sampleDesignationsList.item(0), dnaSample);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * @param item\r
+     * @param dnaSample\r
+     */\r
+    private void parseSampleDesignations(Element item, DnaSample dnaSample) {\r
+        NodeList sampleDesignationList = item.getElementsByTagName(prefix+"sampleDesignation");\r
+        for(int i=0;i<sampleDesignationList.getLength();i++){\r
+            dnaSample.addIdentifier(sampleDesignationList.item(i).getTextContent(), (DefinedTerm)cdmAppController.getTermService().find(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc")));\r
+        }\r
+\r
+    }\r
+\r
+    private AgentBase<?> parsePreparationAgent(Element item) {\r
+        AgentBase<?> agentBase = null;\r
+        NodeList personList = item.getElementsByTagName(prefix+"Person");\r
+        if(personList.item(0)!=null && personList.item(0) instanceof Element){\r
+            agentBase = new AbcdPersonParser(prefix,report, cdmAppController).parse((Element)personList.item(0));\r
+        }\r
+        return agentBase;\r
+    }\r
+\r
+    private void parsePreservations(Element item, DnaSample dnaSample) {\r
+        NodeList preservationList = item.getElementsByTagName(prefix+"preservation");\r
+        for(int i=0;i<preservationList.getLength();i++){\r
+            Node node = preservationList.item(i);\r
+            if(node instanceof Element){\r
+                PreservationMethod preservation = PreservationMethod.NewInstance();\r
+                dnaSample.setPreservation(preservation);\r
+\r
+                String preservationType = AbcdParseUtility.parseFirstTextContent(((Element) node).getElementsByTagName(prefix+"preservationType"));\r
+\r
+                Double preservationTemperature = AbcdParseUtility.parseFirstDouble(((Element) node).getElementsByTagName(prefix+"preservationTemperature"), report);\r
+                preservation.setTemperature(preservationTemperature);\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+}\r
index 4d77b08c87b8ee8d56f17e1c7fe524ed30b632df..a695929cc76665f117fa17375c4f186b24fddcd5 100644 (file)
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in.molecular;
-
-import java.net.URI;
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.log4j.Logger;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportReport;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
-import eu.etaxonomy.cdm.model.common.DefinedTerm;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
-import eu.etaxonomy.cdm.model.common.OrderedTerm;
-import eu.etaxonomy.cdm.model.media.Media;
-import eu.etaxonomy.cdm.model.molecular.Amplification;
-import eu.etaxonomy.cdm.model.molecular.AmplificationResult;
-import eu.etaxonomy.cdm.model.molecular.DnaQuality;
-import eu.etaxonomy.cdm.model.molecular.DnaSample;
-import eu.etaxonomy.cdm.model.molecular.Primer;
-import eu.etaxonomy.cdm.model.molecular.Sequence;
-import eu.etaxonomy.cdm.model.molecular.SequenceDirection;
-import eu.etaxonomy.cdm.model.molecular.SequenceString;
-import eu.etaxonomy.cdm.model.molecular.SingleRead;
-import eu.etaxonomy.cdm.model.molecular.SingleReadAlignment;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.persistence.query.MatchMode;
-
-/**
- * @author pplitzner
- * @date Mar 4, 2015
- *
- */
-public class AbcdGgbnParser {
-
-    //DNA Quality term
-    private static final String HIGH = "high";
-    private static final String MEDIUM = "medium";
-    private static final String LOW = "low";
-    private static final UUID HIGH_QUALITY_TERM = UUID.fromString("ec443c76-5987-4ec5-a66b-da207f70b47f");
-    private static final UUID MEDIUM_QUALITY_TERM = UUID.fromString("2a174892-1246-4807-9022-71ce8639346b");
-    private static final UUID LOW_QUALITY_TERM = UUID.fromString("a3bf12ff-b041-425f-bdaa-aa51da65eebc");
-
-    private static final String FORWARD = "forward";
-
-    private static final String REVERSE = "reverse";
-
-    private static final Logger logger = Logger.getLogger(AbcdGgbnParser.class);
-
-    private final String prefix = "ggbn:";
-
-    private final Abcd206ImportReport report;
-
-    private final ICdmApplicationConfiguration cdmAppController;
-
-    public AbcdGgbnParser(Abcd206ImportReport report, ICdmApplicationConfiguration cdmAppController) {
-        this.report = report;
-        this.cdmAppController = cdmAppController;
-    }
-
-    public DnaSample parse(NodeList ggbn, DnaSample dnaSample, Abcd206ImportState state) {
-
-        for(int i=0;i<ggbn.getLength();i++){
-            Node item = ggbn.item(i);
-            if(item instanceof Element){
-                Element element = (Element) item;
-                NodeList methodDeterminationConcentrationAndRatiosList = element.getElementsByTagName(prefix+"methodDeterminationConcentrationAndRatios");
-                NodeList volumeList = element.getElementsByTagName(prefix+"volume");
-                NodeList weightList = element.getElementsByTagName(prefix+"weight");
-                NodeList methodDeterminationWeightList = element.getElementsByTagName(prefix+"methodDeterminationWeight");
-                NodeList DNADNAHybridizationList = element.getElementsByTagName(prefix+"DNADNAHybridization");
-                NodeList DNAMeltingPointList = element.getElementsByTagName(prefix+"DNAMeltingPoint");
-                NodeList estimatedSizeList = element.getElementsByTagName(prefix+"estimated_size");
-                NodeList poolDnaExtractsList = element.getElementsByTagName(prefix+"pool_dna_extracts");
-                NodeList gelImageList = element.getElementsByTagName(prefix+"gelImage");
-                NodeList amplificationsList = element.getElementsByTagName(prefix+"Amplifications");
-
-                dnaSample.setDnaQuality(parseDnaQuality(element, state));
-
-                parseGelImage(gelImageList, state);
-                parseAmplifications(amplificationsList, dnaSample, state);
-            }
-        }
-        return dnaSample;
-    }
-
-    private DnaQuality parseDnaQuality(Element element, Abcd206ImportState state) {
-        DnaQuality dnaQuality = DnaQuality.NewInstance();
-
-        NodeList purificationMethodList = element.getElementsByTagName(prefix+"purificationMethod");
-        String purificationMethod = AbcdParseUtility.parseFirstTextContent(purificationMethodList);
-        dnaQuality.setPurificationMethod(purificationMethod);
-
-        NodeList concentrationList = element.getElementsByTagName(prefix+"concentration");
-        if(concentrationList.getLength()==1){
-            Node concentration = concentrationList.item(0);
-            dnaQuality.setConcentration(AbcdParseUtility.parseDouble(concentration, report));
-            if(concentration instanceof Element){
-                String unit = ((Element) concentration).getAttribute("Unit");
-                //TODO
-//                dnaQuality.setConcentrationUnit(concentrationUnit)
-            }
-        }
-
-        NodeList ratioOfAbsorbance260_280List = element.getElementsByTagName(prefix+"ratioOfAbsorbance260_280");
-        dnaQuality.setRatioOfAbsorbance260_280(AbcdParseUtility.parseFirstDouble(ratioOfAbsorbance260_280List, report));
-
-        NodeList ratioOfAbsorbance260_230List = element.getElementsByTagName(prefix+"ratioOfAbsorbance260_230");
-        dnaQuality.setRatioOfAbsorbance260_230(AbcdParseUtility.parseFirstDouble(ratioOfAbsorbance260_230List, report));
-
-        NodeList qualityCheckDateList = element.getElementsByTagName(prefix+"qualityCheckDate");
-        if(qualityCheckDateList.item(0)!=null){
-            dnaQuality.setQualityCheckDate(AbcdParseUtility.parseFirstDateTime(qualityCheckDateList));
-        }
-
-        NodeList qualityList = element.getElementsByTagName(prefix+"quality");
-        String quality = AbcdParseUtility.parseFirstTextContent(qualityList);
-        if(LOW.equals(quality)){
-            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(LOW_QUALITY_TERM));
-        }
-        else if(MEDIUM.equals(quality)){
-            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(MEDIUM_QUALITY_TERM));
-        }
-        else if(HIGH.equals(quality)){
-            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(HIGH_QUALITY_TERM));
-        }
-
-        NodeList qualityRemarksList = element.getElementsByTagName(prefix+"qualityRemarks");
-
-
-        return dnaQuality;
-    }
-
-    private void parseGelImage(NodeList gelImageList, Abcd206ImportState state) {
-        if(gelImageList.item(0)!=null && gelImageList.item(0) instanceof Element){
-            Element gelImage = (Element)gelImageList.item(0);
-            NodeList fileURIList = gelImage.getElementsByTagName("fileURI");
-            NodeList gelVoltageList = gelImage.getElementsByTagName("gelVoltage");
-            NodeList gelConcentrationList = gelImage.getElementsByTagName("gelConcentration");
-            NodeList gelDurationList = gelImage.getElementsByTagName("gelDuration");
-            NodeList gelLadderList = gelImage.getElementsByTagName("gelLadder");
-            NodeList gelStainList = gelImage.getElementsByTagName("gelStain");
-            NodeList gelRemarksList = gelImage.getElementsByTagName("gelRemarks");
-
-        }
-
-    }
-
-    private void parseAmplifications(NodeList amplificationsList, DnaSample dnaSample, Abcd206ImportState state) {
-        if(amplificationsList.item(0)!=null && amplificationsList.item(0) instanceof Element){
-            AmplificationResult amplificationResult = AmplificationResult.NewInstance();
-            Amplification amplification = Amplification.NewInstance();
-            NodeList amplificationList = ((Element) amplificationsList.item(0)).getElementsByTagName(prefix+"amplification");
-            for(int i=0;i<amplificationList.getLength();i++){
-                if(amplificationList.item(i) instanceof Element){
-                    Element amplificationElement = (Element)amplificationList.item(i);
-                    NodeList amplificationDateList = amplificationElement.getElementsByTagName(prefix+"amplificationDate");
-                    NodeList amplificationStaffList = amplificationElement.getElementsByTagName(prefix+"amplificationStaff");
-
-                    //amplification dna marker
-                    NodeList markerList = amplificationElement.getElementsByTagName(prefix+"marker");
-                    if(markerList.item(0)!=null){
-                        String amplificationMarker = markerList.item(0).getTextContent();
-                        DefinedTerm dnaMarker = null;
-                        List<DefinedTermBase> markersFound = cdmAppController.getTermService().findByTitle(DefinedTerm.class, amplificationMarker, MatchMode.EXACT, null, null, null, null, null).getRecords();
-                        if(markersFound.size()==1){
-                            dnaMarker = (DefinedTerm) markersFound.get(0);
-                        }
-                        else{
-                            dnaMarker = DefinedTerm.NewDnaMarkerInstance(amplificationMarker, amplificationMarker, amplificationMarker);
-                            cdmAppController.getTermService().saveOrUpdate(dnaMarker);
-                        }
-                        amplification.setDnaMarker(dnaMarker);
-                    }
-
-                    NodeList markerSubfragmentList = amplificationElement.getElementsByTagName(prefix+"markerSubfragment");
-                    NodeList amplificationSuccessList = amplificationElement.getElementsByTagName(prefix+"amplificationSuccess");
-                    NodeList amplificationSuccessDetailsList = amplificationElement.getElementsByTagName(prefix+"amplificationSuccessDetails");
-                    NodeList amplificationMethodList = amplificationElement.getElementsByTagName(prefix+"amplificationMethod");
-                    NodeList purificationMethodList = amplificationElement.getElementsByTagName(prefix+"purificationMethod");
-                    NodeList libReadsSeqdList = amplificationElement.getElementsByTagName(prefix+"lib_reads_seqd");
-                    NodeList libScreenList = amplificationElement.getElementsByTagName(prefix+"lib_screen");
-                    NodeList libVectorList = amplificationElement.getElementsByTagName(prefix+"lib_vector");
-                    NodeList libConstMethList = amplificationElement.getElementsByTagName(prefix+"lib_const_meth");
-                    NodeList plasmidList = amplificationElement.getElementsByTagName(prefix+"plasmid");
-
-                    //consensus sequence
-                    NodeList sequencingsList = amplificationElement.getElementsByTagName(prefix+"Sequencings");
-                    if(sequencingsList.item(0)!=null && sequencingsList.item(0) instanceof Element){
-                        parseAmplificationSequencings((Element)sequencingsList.item(0), amplification, amplificationResult, dnaSample, state);
-                    }
-                    parseAmplificationPrimers(amplificationElement.getElementsByTagName(prefix+"AmplificationPrimers"));
-                }
-            }
-            //check if amplification already exists (can only be checked after all fields are initialized because comparison is done on the label cache))
-            List<Amplification> matchingAmplifications = cdmAppController.getAmplificationService().findByLabelCache(amplification.getLabelCache(), MatchMode.EXACT, null, null, null, null, null).getRecords();
-            if(matchingAmplifications.size()==1){
-                amplification = matchingAmplifications.iterator().next();
-            }
-            cdmAppController.getAmplificationService().save(amplification);
-            amplificationResult.setAmplification(amplification);
-            dnaSample.addAmplificationResult(amplificationResult);
-        }
-    }
-
-    private void parseAmplificationPrimers(NodeList elementsByTagName) {
-        // TODO Auto-generated method stub
-
-    }
-
-    private void parseAmplificationSequencings(Element sequencings, Amplification amplification, AmplificationResult amplificationResult, DnaSample dnaSample, Abcd206ImportState state) {
-        NodeList sequencingList = sequencings.getElementsByTagName(prefix+"sequencing");
-        for(int i=0;i<sequencingList.getLength();i++){
-            Sequence sequence = Sequence.NewInstance("");
-            dnaSample.addSequence(sequence);
-            sequence.setDnaMarker(amplification.getDnaMarker());
-
-            if(sequencingList.item(i) instanceof Element){
-                Element sequencing = (Element)sequencingList.item(i);
-
-                //singleSequencings
-                NodeList singleSequencingsList = sequencing.getElementsByTagName(prefix+"SingleSequencings");
-                parseSingleSequencings(singleSequencingsList, amplification, amplificationResult, sequence);
-                //Consensus sequence
-                NodeList consensusSequencesList = sequencing.getElementsByTagName(prefix+"consensusSequence");
-                sequence.setConsensusSequence(SequenceString.NewInstance(AbcdParseUtility.parseFirstTextContent(consensusSequencesList)));
-                //sequence length
-                Double consensusSequenceLength = AbcdParseUtility.parseFirstDouble(sequencing.getElementsByTagName(prefix+"consensusSequenceLength"), report);
-                if(sequence.getConsensusSequence()!=null && consensusSequenceLength!=null){
-                    //TODO: this can be different from the actual length in ABCD but not in CDM!
-                    sequence.getConsensusSequence().setLength(consensusSequenceLength.intValue());
-                }
-                //contig file URL
-                NodeList consensusSequenceChromatogramFileURIList = sequencing.getElementsByTagName(prefix+"consensusSequenceChromatogramFileURI");
-                URI uri = AbcdParseUtility.parseFirstUri(consensusSequenceChromatogramFileURIList, report);
-                Media contigFile = Media.NewInstance(uri, null, null, null);
-                sequence.setContigFile(contigFile);
-
-                //genetic Accession
-                NodeList geneticAccessionList = sequencing.getElementsByTagName(prefix+"geneticAccession");
-                parseGeneticAccession(geneticAccessionList, sequence);
-
-                //references
-                NodeList referencesList = sequencing.getElementsByTagName(prefix+"References");
-                if(referencesList.item(0)!=null && referencesList.item(0) instanceof Element){
-                    parseSequencingReferences((Element) referencesList.item(0), sequence);
-                }
-            }
-        }
-//        if(nodeList.item(0)!=null && nodeList.item(0) instanceof Element){
-//        NodeList plasmidList = amplificationElement.getElementsByTagName(prefix+"plasmid");
-
-    }
-
-    private void parseSequencingReferences(Element references, Sequence sequence) {
-        NodeList referenceList = references.getElementsByTagName(prefix+"Reference");
-        for(int i=0;i<referenceList.getLength();i++){
-            if(referenceList.item(i) instanceof Element){
-                Element element = (Element)referenceList.item(i);
-                NodeList referenceCitationList = element.getElementsByTagName(prefix+"ReferenceCitation");
-                Reference reference = AbcdParseUtility.parseFirstReference(referenceCitationList, cdmAppController);
-                sequence.addCitation(reference);
-            }
-        }
-    }
-
-    private void parseSingleSequencings(NodeList singleSequencingsList, Amplification amplification, AmplificationResult amplificationResult, Sequence sequence) {
-        if(singleSequencingsList.item(0)!=null && singleSequencingsList.item(0) instanceof Element){
-            Element singleSequencings = (Element)singleSequencingsList.item(0);
-            NodeList singleSequencingList = singleSequencings.getElementsByTagName(prefix+"singleSequencing");
-            for(int i=0;i<singleSequencingList.getLength();i++){
-                //single read
-                SingleRead singleRead = SingleRead.NewInstance();
-                SingleReadAlignment.NewInstance(sequence, singleRead);
-                amplificationResult.addSingleRead(singleRead);
-                if(singleSequencingList.item(i) instanceof Element){
-                    Element singleSequencing = (Element)singleSequencingList.item(i);
-                    NodeList sequencingDirectionList = singleSequencing.getElementsByTagName(prefix+"sequencingDirection");
-                    //read direction
-                    String singleReadDirection = AbcdParseUtility.parseFirstTextContent(sequencingDirectionList);
-                    if(singleReadDirection.equals(FORWARD)){
-                        singleRead.setDirection(SequenceDirection.Forward);
-                    }
-                    else if(singleReadDirection.equals(REVERSE)){
-                        singleRead.setDirection(SequenceDirection.Reverse);
-                    }
-                    //read pherogram URI
-                    NodeList chromatogramFileURIList = singleSequencing.getElementsByTagName(prefix+"chromatogramFileURI");
-                    singleRead.setPherogram(Media.NewInstance(AbcdParseUtility.parseFirstUri(chromatogramFileURIList, report), null, null, null));
-                    NodeList sequencingPrimersList = singleSequencing.getElementsByTagName(prefix+"SequencingPrimers");
-                    parseSequencingPrimers(sequencingPrimersList, singleRead, amplification);
-                }
-            }
-        }
-    }
-
-    private void parseSequencingPrimers(NodeList sequencingPrimersList, SingleRead singleRead, Amplification amplification) {
-        if(sequencingPrimersList.item(0)!=null && sequencingPrimersList.item(0) instanceof Element){
-            Element sequencingPrimers = (Element)sequencingPrimersList.item(0);
-            NodeList sequencingPrimerList = sequencingPrimers.getElementsByTagName(prefix+"sequencingPrimer");
-            for(int i=0;i<sequencingPrimerList.getLength();i++){
-                if(sequencingPrimerList.item(i) instanceof Element){
-                    Element sequencingPrimer = (Element)sequencingPrimerList.item(i);
-                    //primer name
-                    String primerName = AbcdParseUtility.parseFirstTextContent(sequencingPrimer.getElementsByTagName(prefix+"primerName"));
-                    //check if primer already exists
-                    List<Primer> matchingPrimers = cdmAppController.getPrimerService().findByLabel(primerName, MatchMode.EXACT, null, null, null, null, null).getRecords();
-                    Primer primer = null;
-                    if(matchingPrimers.size()==1){
-                        primer = matchingPrimers.iterator().next();
-                        return;
-                    }
-                    else{
-                        primer = Primer.NewInstance(null);
-                        primer.setLabel(primerName);
-                    }
-                    singleRead.setPrimer(primer);
-                    //primer sequence
-                    NodeList primerSequenceList = sequencingPrimer.getElementsByTagName(prefix+"primerSequence");
-                    primer.setSequence(SequenceString.NewInstance(AbcdParseUtility.parseFirstTextContent(primerSequenceList)));
-                    //primer direction
-                    String direction = parseFirstAttribute("Direction", primerSequenceList);
-                    if(direction!=null){
-                        if(direction.equals(FORWARD)){
-                            amplification.setForwardPrimer(primer);
-                        }
-                        else if(direction.equals(REVERSE)){
-                            amplification.setReversePrimer(primer);
-                        }
-                    }
-                    //reference citation
-                    NodeList primerReferenceCitationList = sequencingPrimer.getElementsByTagName(prefix+"primerReferenceCitation");
-                    String primerReferenceCitation = AbcdParseUtility.parseFirstTextContent(primerReferenceCitationList);
-                    Reference reference = AbcdParseUtility.parseFirstReference(primerReferenceCitationList, cdmAppController);
-                    primer.setPublishedIn(reference);
-
-                    cdmAppController.getPrimerService().save(primer);
-                }
-            }
-        }
-    }
-
-    private String parseFirstAttribute(String attributeName, NodeList nodeList) {
-        String attribute = null;
-        if(nodeList.item(0)!=null && nodeList.item(0) instanceof Element){
-            Element element = (Element)nodeList.item(0);
-            attribute = element.getAttribute(attributeName);
-        }
-        return attribute;
-    }
-
-    private void parseGeneticAccession(NodeList geneticAccessionList, Sequence sequence) {
-        for(int i=0;i<geneticAccessionList.getLength();i++){
-            if(geneticAccessionList.item(i) instanceof Element){
-                //genetic accession number
-                NodeList geneticAccessionNumberList = ((Element)geneticAccessionList.item(i)).getElementsByTagName(prefix+"geneticAccessionNumber");
-                sequence.setGeneticAccessionNumber(AbcdParseUtility.parseFirstTextContent(geneticAccessionNumberList));
-
-                //genetic accession number uri
-                NodeList geneticAccessionNumberUriList = ((Element)geneticAccessionList.item(i)).getElementsByTagName(prefix+"geneticAccessionNumberURI");
-                //TODO: this is different from the geneticAccessionNumber
-
-            }
-        }
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in.molecular;\r
+\r
+import java.net.URI;\r
+import java.util.List;\r
+import java.util.UUID;\r
+\r
+import org.apache.log4j.Logger;\r
+import org.w3c.dom.Element;\r
+import org.w3c.dom.Node;\r
+import org.w3c.dom.NodeList;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportState;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;\r
+import eu.etaxonomy.cdm.model.common.DefinedTerm;\r
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;\r
+import eu.etaxonomy.cdm.model.common.OrderedTerm;\r
+import eu.etaxonomy.cdm.model.media.Media;\r
+import eu.etaxonomy.cdm.model.molecular.Amplification;\r
+import eu.etaxonomy.cdm.model.molecular.AmplificationResult;\r
+import eu.etaxonomy.cdm.model.molecular.DnaQuality;\r
+import eu.etaxonomy.cdm.model.molecular.DnaSample;\r
+import eu.etaxonomy.cdm.model.molecular.Primer;\r
+import eu.etaxonomy.cdm.model.molecular.Sequence;\r
+import eu.etaxonomy.cdm.model.molecular.SequenceDirection;\r
+import eu.etaxonomy.cdm.model.molecular.SequenceString;\r
+import eu.etaxonomy.cdm.model.molecular.SingleRead;\r
+import eu.etaxonomy.cdm.model.molecular.SingleReadAlignment;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.persistence.query.MatchMode;\r
+\r
+/**\r
+ * @author pplitzner\r
+ * @date Mar 4, 2015\r
+ *\r
+ */\r
+public class AbcdGgbnParser {\r
+\r
+    //DNA Quality term\r
+    private static final String HIGH = "high";\r
+    private static final String MEDIUM = "medium";\r
+    private static final String LOW = "low";\r
+    private static final UUID HIGH_QUALITY_TERM = UUID.fromString("ec443c76-5987-4ec5-a66b-da207f70b47f");\r
+    private static final UUID MEDIUM_QUALITY_TERM = UUID.fromString("2a174892-1246-4807-9022-71ce8639346b");\r
+    private static final UUID LOW_QUALITY_TERM = UUID.fromString("a3bf12ff-b041-425f-bdaa-aa51da65eebc");\r
+\r
+    private static final String FORWARD = "forward";\r
+\r
+    private static final String REVERSE = "reverse";\r
+\r
+    private static final Logger logger = Logger.getLogger(AbcdGgbnParser.class);\r
+\r
+    private final String prefix = "ggbn:";\r
+\r
+    private final SpecimenImportReport report;\r
+\r
+    private final ICdmApplicationConfiguration cdmAppController;\r
+\r
+    public AbcdGgbnParser(SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {\r
+        this.report = report;\r
+        this.cdmAppController = cdmAppController;\r
+    }\r
+\r
+    public DnaSample parse(NodeList ggbn, DnaSample dnaSample, Abcd206ImportState state) {\r
+\r
+        for(int i=0;i<ggbn.getLength();i++){\r
+            Node item = ggbn.item(i);\r
+            if(item instanceof Element){\r
+                Element element = (Element) item;\r
+                NodeList methodDeterminationConcentrationAndRatiosList = element.getElementsByTagName(prefix+"methodDeterminationConcentrationAndRatios");\r
+                NodeList volumeList = element.getElementsByTagName(prefix+"volume");\r
+                NodeList weightList = element.getElementsByTagName(prefix+"weight");\r
+                NodeList methodDeterminationWeightList = element.getElementsByTagName(prefix+"methodDeterminationWeight");\r
+                NodeList DNADNAHybridizationList = element.getElementsByTagName(prefix+"DNADNAHybridization");\r
+                NodeList DNAMeltingPointList = element.getElementsByTagName(prefix+"DNAMeltingPoint");\r
+                NodeList estimatedSizeList = element.getElementsByTagName(prefix+"estimated_size");\r
+                NodeList poolDnaExtractsList = element.getElementsByTagName(prefix+"pool_dna_extracts");\r
+                NodeList gelImageList = element.getElementsByTagName(prefix+"gelImage");\r
+                NodeList amplificationsList = element.getElementsByTagName(prefix+"Amplifications");\r
+\r
+                dnaSample.setDnaQuality(parseDnaQuality(element, state));\r
+\r
+                parseGelImage(gelImageList, state);\r
+                parseAmplifications(amplificationsList, dnaSample, state);\r
+            }\r
+        }\r
+        return dnaSample;\r
+    }\r
+\r
+    private DnaQuality parseDnaQuality(Element element, Abcd206ImportState state) {\r
+        DnaQuality dnaQuality = DnaQuality.NewInstance();\r
+\r
+        NodeList purificationMethodList = element.getElementsByTagName(prefix+"purificationMethod");\r
+        String purificationMethod = AbcdParseUtility.parseFirstTextContent(purificationMethodList);\r
+        dnaQuality.setPurificationMethod(purificationMethod);\r
+\r
+        NodeList concentrationList = element.getElementsByTagName(prefix+"concentration");\r
+        if(concentrationList.getLength()==1){\r
+            Node concentration = concentrationList.item(0);\r
+            dnaQuality.setConcentration(AbcdParseUtility.parseDouble(concentration, report));\r
+            if(concentration instanceof Element){\r
+                String unit = ((Element) concentration).getAttribute("Unit");\r
+                //TODO\r
+//                dnaQuality.setConcentrationUnit(concentrationUnit)\r
+            }\r
+        }\r
+\r
+        NodeList ratioOfAbsorbance260_280List = element.getElementsByTagName(prefix+"ratioOfAbsorbance260_280");\r
+        dnaQuality.setRatioOfAbsorbance260_280(AbcdParseUtility.parseFirstDouble(ratioOfAbsorbance260_280List, report));\r
+\r
+        NodeList ratioOfAbsorbance260_230List = element.getElementsByTagName(prefix+"ratioOfAbsorbance260_230");\r
+        dnaQuality.setRatioOfAbsorbance260_230(AbcdParseUtility.parseFirstDouble(ratioOfAbsorbance260_230List, report));\r
+\r
+        NodeList qualityCheckDateList = element.getElementsByTagName(prefix+"qualityCheckDate");\r
+        if(qualityCheckDateList.item(0)!=null){\r
+            dnaQuality.setQualityCheckDate(AbcdParseUtility.parseFirstDateTime(qualityCheckDateList));\r
+        }\r
+\r
+        NodeList qualityList = element.getElementsByTagName(prefix+"quality");\r
+        String quality = AbcdParseUtility.parseFirstTextContent(qualityList);\r
+        if(LOW.equals(quality)){\r
+            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(LOW_QUALITY_TERM));\r
+        }\r
+        else if(MEDIUM.equals(quality)){\r
+            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(MEDIUM_QUALITY_TERM));\r
+        }\r
+        else if(HIGH.equals(quality)){\r
+            dnaQuality.setQualityTerm((OrderedTerm) state.getCdmRepository().getTermService().load(HIGH_QUALITY_TERM));\r
+        }\r
+\r
+        NodeList qualityRemarksList = element.getElementsByTagName(prefix+"qualityRemarks");\r
+\r
+\r
+        return dnaQuality;\r
+    }\r
+\r
+    private void parseGelImage(NodeList gelImageList, Abcd206ImportState state) {\r
+        if(gelImageList.item(0)!=null && gelImageList.item(0) instanceof Element){\r
+            Element gelImage = (Element)gelImageList.item(0);\r
+            NodeList fileURIList = gelImage.getElementsByTagName("fileURI");\r
+            NodeList gelVoltageList = gelImage.getElementsByTagName("gelVoltage");\r
+            NodeList gelConcentrationList = gelImage.getElementsByTagName("gelConcentration");\r
+            NodeList gelDurationList = gelImage.getElementsByTagName("gelDuration");\r
+            NodeList gelLadderList = gelImage.getElementsByTagName("gelLadder");\r
+            NodeList gelStainList = gelImage.getElementsByTagName("gelStain");\r
+            NodeList gelRemarksList = gelImage.getElementsByTagName("gelRemarks");\r
+\r
+        }\r
+\r
+    }\r
+\r
+    private void parseAmplifications(NodeList amplificationsList, DnaSample dnaSample, Abcd206ImportState state) {\r
+        if(amplificationsList.item(0)!=null && amplificationsList.item(0) instanceof Element){\r
+            AmplificationResult amplificationResult = AmplificationResult.NewInstance();\r
+            Amplification amplification = Amplification.NewInstance();\r
+            NodeList amplificationList = ((Element) amplificationsList.item(0)).getElementsByTagName(prefix+"amplification");\r
+            for(int i=0;i<amplificationList.getLength();i++){\r
+                if(amplificationList.item(i) instanceof Element){\r
+                    Element amplificationElement = (Element)amplificationList.item(i);\r
+                    NodeList amplificationDateList = amplificationElement.getElementsByTagName(prefix+"amplificationDate");\r
+                    NodeList amplificationStaffList = amplificationElement.getElementsByTagName(prefix+"amplificationStaff");\r
+\r
+                    //amplification dna marker\r
+                    NodeList markerList = amplificationElement.getElementsByTagName(prefix+"marker");\r
+                    if(markerList.item(0)!=null){\r
+                        String amplificationMarker = markerList.item(0).getTextContent();\r
+                        DefinedTerm dnaMarker = null;\r
+                        List<DefinedTermBase> markersFound = cdmAppController.getTermService().findByTitle(DefinedTerm.class, amplificationMarker, MatchMode.EXACT, null, null, null, null, null).getRecords();\r
+                        if(markersFound.size()==1){\r
+                            dnaMarker = (DefinedTerm) markersFound.get(0);\r
+                        }\r
+                        else{\r
+                            dnaMarker = DefinedTerm.NewDnaMarkerInstance(amplificationMarker, amplificationMarker, amplificationMarker);\r
+                            cdmAppController.getTermService().saveOrUpdate(dnaMarker);\r
+                        }\r
+                        amplification.setDnaMarker(dnaMarker);\r
+                    }\r
+\r
+                    NodeList markerSubfragmentList = amplificationElement.getElementsByTagName(prefix+"markerSubfragment");\r
+                    NodeList amplificationSuccessList = amplificationElement.getElementsByTagName(prefix+"amplificationSuccess");\r
+                    NodeList amplificationSuccessDetailsList = amplificationElement.getElementsByTagName(prefix+"amplificationSuccessDetails");\r
+                    NodeList amplificationMethodList = amplificationElement.getElementsByTagName(prefix+"amplificationMethod");\r
+                    NodeList purificationMethodList = amplificationElement.getElementsByTagName(prefix+"purificationMethod");\r
+                    NodeList libReadsSeqdList = amplificationElement.getElementsByTagName(prefix+"lib_reads_seqd");\r
+                    NodeList libScreenList = amplificationElement.getElementsByTagName(prefix+"lib_screen");\r
+                    NodeList libVectorList = amplificationElement.getElementsByTagName(prefix+"lib_vector");\r
+                    NodeList libConstMethList = amplificationElement.getElementsByTagName(prefix+"lib_const_meth");\r
+                    NodeList plasmidList = amplificationElement.getElementsByTagName(prefix+"plasmid");\r
+\r
+                    //consensus sequence\r
+                    NodeList sequencingsList = amplificationElement.getElementsByTagName(prefix+"Sequencings");\r
+                    if(sequencingsList.item(0)!=null && sequencingsList.item(0) instanceof Element){\r
+                        parseAmplificationSequencings((Element)sequencingsList.item(0), amplification, amplificationResult, dnaSample, state);\r
+                    }\r
+                    parseAmplificationPrimers(amplificationElement.getElementsByTagName(prefix+"AmplificationPrimers"));\r
+                }\r
+            }\r
+            //check if amplification already exists (can only be checked after all fields are initialized because comparison is done on the label cache))\r
+            List<Amplification> matchingAmplifications = cdmAppController.getAmplificationService().findByLabelCache(amplification.getLabelCache(), MatchMode.EXACT, null, null, null, null, null).getRecords();\r
+            if(matchingAmplifications.size()==1){\r
+                amplification = matchingAmplifications.iterator().next();\r
+            }\r
+            cdmAppController.getAmplificationService().save(amplification);\r
+            amplificationResult.setAmplification(amplification);\r
+            dnaSample.addAmplificationResult(amplificationResult);\r
+        }\r
+    }\r
+\r
+    private void parseAmplificationPrimers(NodeList elementsByTagName) {\r
+        // TODO Auto-generated method stub\r
+\r
+    }\r
+\r
+    private void parseAmplificationSequencings(Element sequencings, Amplification amplification, AmplificationResult amplificationResult, DnaSample dnaSample, Abcd206ImportState state) {\r
+        NodeList sequencingList = sequencings.getElementsByTagName(prefix+"sequencing");\r
+        for(int i=0;i<sequencingList.getLength();i++){\r
+            Sequence sequence = Sequence.NewInstance("");\r
+            dnaSample.addSequence(sequence);\r
+            sequence.setDnaMarker(amplification.getDnaMarker());\r
+\r
+            if(sequencingList.item(i) instanceof Element){\r
+                Element sequencing = (Element)sequencingList.item(i);\r
+\r
+                //singleSequencings\r
+                NodeList singleSequencingsList = sequencing.getElementsByTagName(prefix+"SingleSequencings");\r
+                parseSingleSequencings(singleSequencingsList, amplification, amplificationResult, sequence);\r
+                //Consensus sequence\r
+                NodeList consensusSequencesList = sequencing.getElementsByTagName(prefix+"consensusSequence");\r
+                sequence.setConsensusSequence(SequenceString.NewInstance(AbcdParseUtility.parseFirstTextContent(consensusSequencesList)));\r
+                //sequence length\r
+                Double consensusSequenceLength = AbcdParseUtility.parseFirstDouble(sequencing.getElementsByTagName(prefix+"consensusSequenceLength"), report);\r
+                if(sequence.getConsensusSequence()!=null && consensusSequenceLength!=null){\r
+                    //TODO: this can be different from the actual length in ABCD but not in CDM!\r
+                    sequence.getConsensusSequence().setLength(consensusSequenceLength.intValue());\r
+                }\r
+                //contig file URL\r
+                NodeList consensusSequenceChromatogramFileURIList = sequencing.getElementsByTagName(prefix+"consensusSequenceChromatogramFileURI");\r
+                URI uri = AbcdParseUtility.parseFirstUri(consensusSequenceChromatogramFileURIList, report);\r
+                Media contigFile = Media.NewInstance(uri, null, null, null);\r
+                sequence.setContigFile(contigFile);\r
+\r
+                //genetic Accession\r
+                NodeList geneticAccessionList = sequencing.getElementsByTagName(prefix+"geneticAccession");\r
+                parseGeneticAccession(geneticAccessionList, sequence);\r
+\r
+                //references\r
+                NodeList referencesList = sequencing.getElementsByTagName(prefix+"References");\r
+                if(referencesList.item(0)!=null && referencesList.item(0) instanceof Element){\r
+                    parseSequencingReferences((Element) referencesList.item(0), sequence);\r
+                }\r
+            }\r
+        }\r
+//        if(nodeList.item(0)!=null && nodeList.item(0) instanceof Element){\r
+//        NodeList plasmidList = amplificationElement.getElementsByTagName(prefix+"plasmid");\r
+\r
+    }\r
+\r
+    private void parseSequencingReferences(Element references, Sequence sequence) {\r
+        NodeList referenceList = references.getElementsByTagName(prefix+"Reference");\r
+        for(int i=0;i<referenceList.getLength();i++){\r
+            if(referenceList.item(i) instanceof Element){\r
+                Element element = (Element)referenceList.item(i);\r
+                NodeList referenceCitationList = element.getElementsByTagName(prefix+"ReferenceCitation");\r
+                Reference reference = AbcdParseUtility.parseFirstReference(referenceCitationList, cdmAppController);\r
+                sequence.addCitation(reference);\r
+            }\r
+        }\r
+    }\r
+\r
+    private void parseSingleSequencings(NodeList singleSequencingsList, Amplification amplification, AmplificationResult amplificationResult, Sequence sequence) {\r
+        if(singleSequencingsList.item(0)!=null && singleSequencingsList.item(0) instanceof Element){\r
+            Element singleSequencings = (Element)singleSequencingsList.item(0);\r
+            NodeList singleSequencingList = singleSequencings.getElementsByTagName(prefix+"singleSequencing");\r
+            for(int i=0;i<singleSequencingList.getLength();i++){\r
+                //single read\r
+                SingleRead singleRead = SingleRead.NewInstance();\r
+                SingleReadAlignment.NewInstance(sequence, singleRead);\r
+                amplificationResult.addSingleRead(singleRead);\r
+                if(singleSequencingList.item(i) instanceof Element){\r
+                    Element singleSequencing = (Element)singleSequencingList.item(i);\r
+                    NodeList sequencingDirectionList = singleSequencing.getElementsByTagName(prefix+"sequencingDirection");\r
+                    //read direction\r
+                    String singleReadDirection = AbcdParseUtility.parseFirstTextContent(sequencingDirectionList);\r
+                    if(singleReadDirection.equals(FORWARD)){\r
+                        singleRead.setDirection(SequenceDirection.Forward);\r
+                    }\r
+                    else if(singleReadDirection.equals(REVERSE)){\r
+                        singleRead.setDirection(SequenceDirection.Reverse);\r
+                    }\r
+                    //read pherogram URI\r
+                    NodeList chromatogramFileURIList = singleSequencing.getElementsByTagName(prefix+"chromatogramFileURI");\r
+                    singleRead.setPherogram(Media.NewInstance(AbcdParseUtility.parseFirstUri(chromatogramFileURIList, report), null, null, null));\r
+                    NodeList sequencingPrimersList = singleSequencing.getElementsByTagName(prefix+"SequencingPrimers");\r
+                    parseSequencingPrimers(sequencingPrimersList, singleRead, amplification);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    private void parseSequencingPrimers(NodeList sequencingPrimersList, SingleRead singleRead, Amplification amplification) {\r
+        if(sequencingPrimersList.item(0)!=null && sequencingPrimersList.item(0) instanceof Element){\r
+            Element sequencingPrimers = (Element)sequencingPrimersList.item(0);\r
+            NodeList sequencingPrimerList = sequencingPrimers.getElementsByTagName(prefix+"sequencingPrimer");\r
+            for(int i=0;i<sequencingPrimerList.getLength();i++){\r
+                if(sequencingPrimerList.item(i) instanceof Element){\r
+                    Element sequencingPrimer = (Element)sequencingPrimerList.item(i);\r
+                    //primer name\r
+                    String primerName = AbcdParseUtility.parseFirstTextContent(sequencingPrimer.getElementsByTagName(prefix+"primerName"));\r
+                    //check if primer already exists\r
+                    List<Primer> matchingPrimers = cdmAppController.getPrimerService().findByLabel(primerName, MatchMode.EXACT, null, null, null, null, null).getRecords();\r
+                    Primer primer = null;\r
+                    if(matchingPrimers.size()==1){\r
+                        primer = matchingPrimers.iterator().next();\r
+                        return;\r
+                    }\r
+                    else{\r
+                        primer = Primer.NewInstance(null);\r
+                        primer.setLabel(primerName);\r
+                    }\r
+                    singleRead.setPrimer(primer);\r
+                    //primer sequence\r
+                    NodeList primerSequenceList = sequencingPrimer.getElementsByTagName(prefix+"primerSequence");\r
+                    primer.setSequence(SequenceString.NewInstance(AbcdParseUtility.parseFirstTextContent(primerSequenceList)));\r
+                    //primer direction\r
+                    String direction = parseFirstAttribute("Direction", primerSequenceList);\r
+                    if(direction!=null){\r
+                        if(direction.equals(FORWARD)){\r
+                            amplification.setForwardPrimer(primer);\r
+                        }\r
+                        else if(direction.equals(REVERSE)){\r
+                            amplification.setReversePrimer(primer);\r
+                        }\r
+                    }\r
+                    //reference citation\r
+                    NodeList primerReferenceCitationList = sequencingPrimer.getElementsByTagName(prefix+"primerReferenceCitation");\r
+                    String primerReferenceCitation = AbcdParseUtility.parseFirstTextContent(primerReferenceCitationList);\r
+                    Reference reference = AbcdParseUtility.parseFirstReference(primerReferenceCitationList, cdmAppController);\r
+                    primer.setPublishedIn(reference);\r
+\r
+                    cdmAppController.getPrimerService().save(primer);\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+    private String parseFirstAttribute(String attributeName, NodeList nodeList) {\r
+        String attribute = null;\r
+        if(nodeList.item(0)!=null && nodeList.item(0) instanceof Element){\r
+            Element element = (Element)nodeList.item(0);\r
+            attribute = element.getAttribute(attributeName);\r
+        }\r
+        return attribute;\r
+    }\r
+\r
+    private void parseGeneticAccession(NodeList geneticAccessionList, Sequence sequence) {\r
+        for(int i=0;i<geneticAccessionList.getLength();i++){\r
+            if(geneticAccessionList.item(i) instanceof Element){\r
+                //genetic accession number\r
+                NodeList geneticAccessionNumberList = ((Element)geneticAccessionList.item(i)).getElementsByTagName(prefix+"geneticAccessionNumber");\r
+                sequence.setGeneticAccessionNumber(AbcdParseUtility.parseFirstTextContent(geneticAccessionNumberList));\r
+\r
+                //genetic accession number uri\r
+                NodeList geneticAccessionNumberUriList = ((Element)geneticAccessionList.item(i)).getElementsByTagName(prefix+"geneticAccessionNumberURI");\r
+                //TODO: this is different from the geneticAccessionNumber\r
+\r
+            }\r
+        }\r
+    }\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index 63b64b4..5b896fe
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.gbif.in;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import eu.etaxonomy.cdm.io.specimen.SpecimenDataHolder;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;
-import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public class GbifDataHolder extends SpecimenDataHolder{
-    @SuppressWarnings("unused")
-    private static final Logger logger = Logger.getLogger(Abcd206DataHolder.class);
-
-    //per import
-    protected List<SpecimenTypeDesignationStatus> statusList;
-    protected List<String> knownGbifElements = new ArrayList<String>();
-    protected HashMap<String,String> allGbifElements = new HashMap<String,String>();
-    public List<String> gatheringAgentList;
-    protected List<String> gatheringTeamList;
-
-    /*per unit
-    protected List<Identification> identificationList;
-    private List<HashMap<String, String>> atomisedIdentificationList;
-    protected Map<String, String> namedAreaList;
-    protected List<String[]> referenceList;
-    protected List<String> multimediaObjects;
-    protected List<String> docSources;
-    protected List<String> associatedUnitIds;
-
-    private String nomenclatureCode;
-    protected String institutionCode;
-    protected String collectionCode;
-    protected String unitID;
-    protected String recordBasis;
-    protected String kindOfUnit;
-    protected String accessionNumber;
-    protected String fieldNumber;
-    protected Double longitude;
-    protected Double latitude;
-    protected String locality;
-    protected String languageIso;
-    protected String country;
-    protected String isocountry;
-    protected Integer depth;
-    protected Integer altitude;
-    protected String unitNotes;
-    protected String gatheringNotes;
-    protected String gatheringDateText;
-    protected String gatheringElevationText;
-    protected String gatheringElevation;
-    protected String gatheringElevationMax;
-    protected String gatheringElevationMin;
-    protected String gatheringElevationUnit;
-    protected String gatheringSpatialDatum;
-    protected String gatheringCoordinateErrorMethod;
-    */
-
-
-    protected String key;
-    protected String datasetKey;
-    protected String publishingOrgKey;
-    protected String publishingCountry;
-    protected String protocol;
-    protected String lastCrawled;
-    protected String lastParsed;
-    protected String extensions;
-    protected String basisOfRecord;
-    protected String individualCount;
-    protected String taxonKey;
-    protected String kingdomKey;
-    protected String phylumKey;
-    protected String classKey;
-    protected String orderKey;
-    protected String familyKey;
-    protected String genusKey;
-    protected String speciesKey;
-    protected String scientificName;
-    protected String kingdom;
-    protected String phylum;
-    protected String order;
-    protected String family;
-    protected String genus;
-    protected String species;
-    protected String genericName;
-    protected String specificEpithet;
-    protected String taxonRank;
-    protected String dateIdentified;
-    protected String decimalLongitude;
-    protected String decimalLatitude;
-    protected String elevation;
-    protected String continent;
-    protected String stateProvince;
-    protected String year;
-    protected String month;
-    protected String day;
-    protected String eventDate;
-    protected String[] issues;
-   protected String lastInterpreted;
-   protected String identifiers;
-   protected String[] facts;
-   protected String[] relations;
-   protected String geodeticDatum;
-   protected String className;
-   protected String countryCode;
-   protected String country;
-   protected String nomenclaturalStatus;
-   protected String rightsHolder;
-   protected String identifier;
-   protected String recordNumber;
-   protected String nomenclaturalCode;
-   protected String county;
-   protected String locality;
-   protected String datasetName;
-   protected String gbifID;
-   protected String collectionCode;
-   protected String occurrenceID;
-   protected String type;
-   protected String taxonID;
-   protected String license;
-   protected String catalogNumber;
-   protected String recordedBy;
-    protected String institutionCode;
-    protected String ownerInstitutionCode;
-    protected String bibliographicCitation;
-    protected String identifiedBy;
-    protected String collectionID;
-
-
-    public void reset() {
-
-        key = null;
-        datasetKey = null;
-        publishingOrgKey = null;
-        publishingCountry = null;
-        protocol = null;
-        lastCrawled = null;
-        lastParsed = null;
-        extensions = null;
-        basisOfRecord = null;
-        individualCount = null;
-        taxonKey = null;
-        kingdomKey = null;
-        phylumKey = null;
-        classKey = null;
-        orderKey = null;
-        familyKey = null;
-        genusKey = null;
-        speciesKey = null;
-        scientificName = null;
-        kingdom = null;
-        phylum = null;
-        order = null;
-        family = null;
-        genus = null;
-        species = null;
-        genericName = null;
-        specificEpithet = null;
-        taxonRank = null;
-        dateIdentified = null;
-        decimalLongitude = null;
-        decimalLatitude = null;
-        elevation = null;
-        continent = null;
-        stateProvince = null;
-        year = null;
-        month = null;
-        day = null;
-        eventDate = null;
-        issues = null;
-       lastInterpreted = null;
-       identifiers = null;
-       facts =  null;
-       relations = null;
-       geodeticDatum = null;
-       className = null;
-       countryCode = null;
-       country = null;
-       nomenclaturalStatus = null;
-       rightsHolder = null;
-       identifier = null;
-       recordNumber = null;
-       nomenclaturalCode = null;
-       county = null;
-       locality = null;
-       datasetName = null;
-       gbifID = null;
-       collectionCode = null;
-       occurrenceID = null;
-       type = null;
-       taxonID = null;
-       license = null;
-       catalogNumber = null;
-       recordedBy = null;
-       institutionCode = null;
-       ownerInstitutionCode = null;
-       bibliographicCitation = null;
-       identifiedBy = null;
-       collectionID = null;
-    }
-
-
-
-    /**
-     * @return the nomenclatureCode
-     */
-    public String getNomenclatureCode() {
-        return nomenclaturalCode;
-    }
-
-
-
-    /**
-     * @param nomenclatureCode the nomenclatureCode to set
-     */
-    public void setNomenclatureCode(String nomenclatureCode) {
-        this.nomenclaturalCode = nomenclatureCode;
-    }
-
-
-
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.gbif.in;\r
+\r
+import java.util.ArrayList;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+\r
+import org.apache.log4j.Logger;\r
+\r
+import eu.etaxonomy.cdm.io.specimen.SpecimenDataHolder;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206DataHolder;\r
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public class GbifDataHolder extends SpecimenDataHolder{\r
+    @SuppressWarnings("unused")\r
+    private static final Logger logger = Logger.getLogger(Abcd206DataHolder.class);\r
+\r
+    //per import\r
+    protected List<SpecimenTypeDesignationStatus> statusList;\r
+    protected List<String> knownGbifElements = new ArrayList<String>();\r
+    protected HashMap<String,String> allGbifElements = new HashMap<String,String>();\r
+    public List<String> gatheringAgentList;\r
+    protected List<String> gatheringTeamList;\r
+\r
+    /*per unit\r
+    protected List<Identification> identificationList;\r
+    private List<HashMap<String, String>> atomisedIdentificationList;\r
+    protected Map<String, String> namedAreaList;\r
+    protected List<String[]> referenceList;\r
+    protected List<String> multimediaObjects;\r
+    protected List<String> docSources;\r
+    protected List<String> associatedUnitIds;\r
+\r
+    private String nomenclatureCode;\r
+    protected String institutionCode;\r
+    protected String collectionCode;\r
+    protected String unitID;\r
+    protected String recordBasis;\r
+    protected String kindOfUnit;\r
+    protected String accessionNumber;\r
+    protected String fieldNumber;\r
+    protected Double longitude;\r
+    protected Double latitude;\r
+    protected String locality;\r
+    protected String languageIso;\r
+    protected String country;\r
+    protected String isocountry;\r
+    protected Integer depth;\r
+    protected Integer altitude;\r
+    protected String unitNotes;\r
+    protected String gatheringNotes;\r
+    protected String gatheringDateText;\r
+    protected String gatheringElevationText;\r
+    protected String gatheringElevation;\r
+    protected String gatheringElevationMax;\r
+    protected String gatheringElevationMin;\r
+    protected String gatheringElevationUnit;\r
+    protected String gatheringSpatialDatum;\r
+    protected String gatheringCoordinateErrorMethod;\r
+    */\r
+\r
+\r
+    protected String key;\r
+    protected String datasetKey;\r
+    protected String publishingOrgKey;\r
+    protected String publishingCountry;\r
+    protected String protocol;\r
+    protected String lastCrawled;\r
+    protected String lastParsed;\r
+    protected String extensions;\r
+    protected String basisOfRecord;\r
+    protected String individualCount;\r
+    protected String taxonKey;\r
+    protected String kingdomKey;\r
+    protected String phylumKey;\r
+    protected String classKey;\r
+    protected String orderKey;\r
+    protected String familyKey;\r
+    protected String genusKey;\r
+    protected String speciesKey;\r
+    protected String scientificName;\r
+    protected String kingdom;\r
+    protected String phylum;\r
+    protected String order;\r
+    protected String family;\r
+    protected String genus;\r
+    protected String species;\r
+    protected String genericName;\r
+    protected String specificEpithet;\r
+    protected String taxonRank;\r
+    protected String dateIdentified;\r
+    protected String decimalLongitude;\r
+    protected String decimalLatitude;\r
+    protected String elevation;\r
+    protected String continent;\r
+    protected String stateProvince;\r
+    protected String year;\r
+    protected String month;\r
+    protected String day;\r
+    protected String eventDate;\r
+    protected String[] issues;\r
+   protected String lastInterpreted;\r
+   protected String identifiers;\r
+   protected String[] facts;\r
+   protected String[] relations;\r
+   protected String geodeticDatum;\r
+   protected String className;\r
+   protected String countryCode;\r
+   protected String country;\r
+   protected String nomenclaturalStatus;\r
+   protected String rightsHolder;\r
+   protected String identifier;\r
+   protected String recordNumber;\r
+   protected String nomenclaturalCode;\r
+   protected String county;\r
+   protected String locality;\r
+   protected String datasetName;\r
+   protected String gbifID;\r
+   protected String collectionCode;\r
+   protected String occurrenceID;\r
+   protected String type;\r
+   protected String taxonID;\r
+   protected String license;\r
+   protected String catalogNumber;\r
+   protected String recordedBy;\r
+    protected String institutionCode;\r
+    protected String ownerInstitutionCode;\r
+    protected String bibliographicCitation;\r
+    protected String identifiedBy;\r
+    protected String collectionID;\r
+\r
+\r
+    public void reset() {\r
+\r
+        key = null;\r
+        datasetKey = null;\r
+        publishingOrgKey = null;\r
+        publishingCountry = null;\r
+        protocol = null;\r
+        lastCrawled = null;\r
+        lastParsed = null;\r
+        extensions = null;\r
+        basisOfRecord = null;\r
+        individualCount = null;\r
+        taxonKey = null;\r
+        kingdomKey = null;\r
+        phylumKey = null;\r
+        classKey = null;\r
+        orderKey = null;\r
+        familyKey = null;\r
+        genusKey = null;\r
+        speciesKey = null;\r
+        scientificName = null;\r
+        kingdom = null;\r
+        phylum = null;\r
+        order = null;\r
+        family = null;\r
+        genus = null;\r
+        species = null;\r
+        genericName = null;\r
+        specificEpithet = null;\r
+        taxonRank = null;\r
+        dateIdentified = null;\r
+        decimalLongitude = null;\r
+        decimalLatitude = null;\r
+        elevation = null;\r
+        continent = null;\r
+        stateProvince = null;\r
+        year = null;\r
+        month = null;\r
+        day = null;\r
+        eventDate = null;\r
+        issues = null;\r
+       lastInterpreted = null;\r
+       identifiers = null;\r
+       facts =  null;\r
+       relations = null;\r
+       geodeticDatum = null;\r
+       className = null;\r
+       countryCode = null;\r
+       country = null;\r
+       nomenclaturalStatus = null;\r
+       rightsHolder = null;\r
+       identifier = null;\r
+       recordNumber = null;\r
+       nomenclaturalCode = null;\r
+       county = null;\r
+       locality = null;\r
+       datasetName = null;\r
+       gbifID = null;\r
+       collectionCode = null;\r
+       occurrenceID = null;\r
+       type = null;\r
+       taxonID = null;\r
+       license = null;\r
+       catalogNumber = null;\r
+       recordedBy = null;\r
+       institutionCode = null;\r
+       ownerInstitutionCode = null;\r
+       bibliographicCitation = null;\r
+       identifiedBy = null;\r
+       collectionID = null;\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * @return the nomenclatureCode\r
+     */\r
+    public String getNomenclatureCode() {\r
+        return nomenclaturalCode;\r
+    }\r
+\r
+\r
+\r
+    /**\r
+     * @param nomenclatureCode the nomenclatureCode to set\r
+     */\r
+    public void setNomenclatureCode(String nomenclatureCode) {\r
+        this.nomenclaturalCode = nomenclatureCode;\r
+    }\r
+\r
+\r
+\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index 173285f..8370d5d
-package eu.etaxonomy.cdm.io.specimen.gbif.in;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.log4j.Logger;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
-import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;
-import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
-import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportUtility;
-import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
-import eu.etaxonomy.cdm.model.taxon.Classification;
-
-// $Id$
-/**
- * Copyright (C) 2016 EDIT
- * European Distributed Institute of Taxonomy
- * http://www.e-taxonomy.eu
- *
- * The contents of this file are subject to the Mozilla Public License Version 1.1
- * See LICENSE.TXT at the top of this package for the full license terms.
- */
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public class GbifImport extends SpecimenImportBase<DwcaImportConfigurator, GbifImportState> {
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-    private static final Logger logger = Logger.getLogger(GbifImport.class);
-
-    @Override
-    protected boolean doCheck(GbifImportState state) {
-        logger.warn("Checking not yet implemented for " + this.getClass().getSimpleName());
-        return true;
-    }
-
-
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
-     */
-    @Override
-    protected boolean isIgnore(GbifImportState state) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
-
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.specimen.SpecimenImportBase#doInvoke(eu.etaxonomy.cdm.io.common.ImportStateBase)
-     */
-    @Override
-    protected void doInvoke(GbifImportState state) {
-        GbifImportState gbifImportState = state;
-        GbifImportConfigurator config = state.getConfig();
-
-            state.setTx(startTransaction());
-            logger.info("INVOKE Specimen Import from ABCD2.06 XML ");
-            Collection<GbifResponse> results = null;
-            //init cd repository
-            if(state.getCdmRepository()==null){
-                state.setCdmRepository(this);
-            }
-            if (config.getOccurenceQuery() != null){
-                 try {
-                    results = new GbifQueryServiceWrapper().query(config.getOccurenceQuery());
-                } catch (ClientProtocolException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                } catch (IOException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                } catch (URISyntaxException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-
-
-            }
-
-           if(state.getConfig().getClassificationUuid()!=null){
-                //load classification from config if it exists
-                state.setClassification(getClassificationService().load(state.getConfig().getClassificationUuid()));
-            }
-            if(state.getClassification()==null){//no existing classification was set in config
-                List<Classification> classificationList = getClassificationService().list(Classification.class, null, null, null, null);
-                //get classification via user interaction
-                if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()){
-                    Map<String,Classification> classMap = new HashMap<String, Classification>();
-                    for (Classification tree : classificationList) {
-                        if (! StringUtils.isBlank(tree.getTitleCache())) {
-                            classMap.put(tree.getTitleCache(),tree);
-                        }
-                    }
-
-                }
-                // use default classification as the classification to import into
-                if (state.getClassification() == null) {
-                    String name = NB(state.getConfig().getClassificationName());
-                    for (Classification classif : classificationList){
-                        if (classif.getTitleCache() != null && classif.getTitleCache().equalsIgnoreCase(name)) {
-                            state.setClassification(classif);
-                        }
-                    }
-                    if (state.getClassification() == null){
-                        state.setClassification(Classification.NewInstance(name, state.getRef(), Language.DEFAULT()));
-                        //we do not need a default classification when creating an empty new one
-                        state.setDefaultClassification(state.getClassification());
-
-                    }
-
-                }
-            }
-            String message = "nb units to insert: " + results.size();
-            logger.info(message);
-            state.getConfig().getProgressMonitor().beginTask("Importing ABCD file", results.size());
-            updateProgress(state, message);
-
-            state.setDataHolder(new GbifDataHolder());
-            state.getDataHolder().reset();
-
-            for (GbifResponse response:results) {
-                if(state.getConfig().getProgressMonitor().isCanceled()){
-                    break;
-                }
-
-
-
-
-                //this.setUnitPropertiesXML( item, abcdFieldGetter, state);
-            //   updateProgress(state, "Importing data for unit "+state.getDataHolder().unitID+" ("+i+"/"+unitsList.getLength()+")");
-
-                //import unit + field unit data
-                this.handleSingleUnit(state, response);
-
-            }
-
-
-            commitTransaction(state.getTx());
-
-
-
-    }
-
-    @Override
-    protected void importAssociatedUnits(GbifImportState state, Object item, DerivedUnitFacade derivedUnitFacade) {
-
-        //import associated units
-        FieldUnit currentFieldUnit = derivedUnitFacade.innerFieldUnit();
-        //TODO: push state (think of implementing stack architecture for state
-        DerivedUnit currentUnit = state.getDerivedUnitBase();
-        DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();
-        String currentPrefix = state.getPrefix();
-      /*  NodeList unitAssociationList = item.getElementsByTagName(currentPrefix+"UnitAssociation");
-        for(int k=0;k<unitAssociationList.getLength();k++){
-            if(unitAssociationList.item(k) instanceof Element){
-                Element unitAssociation = (Element)unitAssociationList.item(k);
-                UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());
-                UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);
-                if(associationWrapper!=null){
-                    NodeList associatedUnits = associationWrapper.getAssociatedUnits();
-                    if(associatedUnits!=null){
-                        for(int m=0;m<associatedUnits.getLength();m++){
-                            if(associatedUnits.item(m) instanceof Element){
-                                state.reset();
-                                state.setPrefix(associationWrapper.getPrefix());
-                                this.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);
-                                handleSingleUnit(state, associatedUnits.item(m));
-
-                                DerivedUnit associatedUnit = state.getDerivedUnitBase();
-                                FieldUnit associatedFieldUnit = null;
-                                java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());
-                                //ignore field unit if associated unit has more than one
-                                if(associatedFieldUnits.size()>1){
-                                    state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));
-                                }
-                                else if(associatedFieldUnits.size()==1){
-                                    associatedFieldUnit = associatedFieldUnits.iterator().next();
-                                }
-
-                                //attach current unit and associated unit depending on association type
-
-                                //parent-child relation:
-                                //copy derivation event and connect parent and sub derivative
-                                if(associationWrapper.getAssociationType().contains("individual")){
-                                    if(currentDerivedFrom==null){
-                                        state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",AbcdImportUtility.getUnitID(currentUnit, config)));
-                                        DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());
-                                    }
-                                    else{
-                                        DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, currentDerivedFrom.getType());
-                                        updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
-                                        updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
-                                        updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
-                                        updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
-                                    }
-                                    state.getReport().addDerivate(associatedUnit, currentUnit, config);
-                                }
-                                //siblings relation
-                                //connect current unit to field unit of associated unit
-                                else if(associationWrapper.getAssociationType().contains("population")){
-                                    //no associated field unit -> using current one
-                                    if(associatedFieldUnit==null){
-                                        if(currentFieldUnit!=null){
-                                            DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());
-                                        }
-                                    }
-                                    else{
-                                        if(currentDerivedFrom==null){
-                                            state.getReport().addInfoMessage("No derivation event found for unit "+AbcdImportUtility.getUnitID(currentUnit, config)+". Defaulting to ACCESIONING event.");
-                                            DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());
-                                        }
-                                        if(currentDerivedFrom!=null && associatedFieldUnit!=currentFieldUnit){
-                                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());
-                                            updatedDerivationEvent.setActor(currentDerivedFrom.getActor());
-                                            updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());
-                                            updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());
-                                            updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());
-                                        }
-                                    }
-                                }
-
-                                //delete current field unit if replaced
-                                if(currentFieldUnit!=null && currentDerivedFrom!=null
-                                        && currentFieldUnit.getDerivationEvents().size()==1  && currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) //making sure that the field unit
-                                        && currentDerivedFrom.getDerivatives().size()==1 && currentDerivedFrom.getDerivatives().contains(currentUnit) //is not attached to other derived units
-                                        && currentDerivedFrom!=currentUnit.getDerivedFrom() // <- derivation has been replaced and can be deleted
-                                        ){
-                                    currentFieldUnit.removeDerivationEvent(currentDerivedFrom);
-                                    state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);
-                                }
-
-                                save(associatedUnit, state);
-                            }
-                        }
-                    }
-                }
-            }
-        }*/
-        //TODO: pop state
-        state.reset();
-        state.setDerivedUnitBase(currentUnit);
-        state.setPrefix(currentPrefix);
-    }
-@Override
-protected void handleSingleUnit(GbifImportState state, Object itemObject){
-    GbifResponse item;
-    if (itemObject instanceof GbifResponse){
-        item = (GbifResponse) itemObject;
-    } else{
-        logger.error("For Gbif Import the item has to be of type GbifResponse.");
-        return;
-    }
-    if (DEBUG) {
-        logger.info("handleSingleUnit "+state.getRef());
-    }
-    try {
-        ICdmApplicationConfiguration cdmAppController = state.getConfig().getCdmAppController();
-        if(cdmAppController==null){
-            cdmAppController = this;
-        }
-        //check if unit already exists
-        DerivedUnitFacade derivedUnitFacade = null;
-        if(state.getConfig().isIgnoreImportOfExistingSpecimens()){
-            String[] tripleId = item.getTripleID();
-            SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(tripleId[0], state);
-            if(existingSpecimen!=null && existingSpecimen.isInstanceOf(DerivedUnit.class)){
-                DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(existingSpecimen, DerivedUnit.class);
-                state.setDerivedUnitBase(derivedUnit);
-                derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
-                importAssociatedUnits(state, item, derivedUnitFacade);
-                state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, state.getConfig()), derivedUnit);
-                return;
-            }
-        }
-        // TODO: implement overwrite/merge specimen
-//      else if(state.getConfig().isOverwriteExistingSpecimens()){
-//          Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);
-//          if(!existingSpecimens.getRecords().isEmpty()){
-//              derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit);
-//              derivedUnitBase = derivedUnitFacade.innerDerivedUnit();
-//              fieldUnit = derivedUnitFacade.getFieldUnit(true);
-//          }
-//      }
-        //import new specimen
-
-        // import DNA unit
-        //TODO!!!!
-//        if(state.getDataHolder().catalogNumber!=null && state.getDataHolder()..equalsIgnoreCase("dna")){
-//            AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(), state.getCdmRepository());
-//            DnaSample dnaSample = dnaParser.parse(item, state);
-//            save(dnaSample, state);
-//            //set dna as derived unit to avoid creating an extra specimen for this dna sample (instead just the field unit will be created)
-//            state.setDerivedUnitBase(dnaSample);
-//            derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());
-//        }
-//        else{
-//            // create facade
-//            derivedUnitFacade = getFacade(state);
-//            state.setDerivedUnitBase(derivedUnitFacade.innerDerivedUnit());
-//        }
-
-        /**
-         * GATHERING EVENT
-         */
-        // gathering event
-      /*  UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(cdmAppController.getTermService(),
-                state.getDataHolder().locality, state.getDataHolder().languageIso, state.getDataHolder().longitude,
-                state.getDataHolder().latitude, state.getDataHolder().gatheringElevationText,
-                state.getDataHolder().gatheringElevationMin, state.getDataHolder().gatheringElevationMax,
-                state.getDataHolder().gatheringElevationUnit, state.getDataHolder().gatheringDateText,
-                state.getDataHolder().gatheringNotes, state.getTransformer().getReferenceSystemByKey(
-                        state.getDataHolder().gatheringSpatialDatum), state.getDataHolder().gatheringAgentList,
-                state.getDataHolder().gatheringTeamList, state.getConfig());
-
-        // country
-        UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();
-        //  unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());
-        unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, state.getConfig(), cdmAppController.getTermService(), cdmAppController.getOccurrenceService());
-
-        DefinedTermBase<?> areaCountry =  unitsGatheringArea.getCountry();
-
-        // other areas
-        unitsGatheringArea = new UnitsGatheringArea();
-        //            unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());
-        unitsGatheringArea.setAreas(state.getDataHolder().namedAreaList,state.getConfig(), cdmAppController.getTermService(), cdmAppController.getVocabularyService());
-        ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();
-        for (DefinedTermBase namedArea : nas) {
-            unitsGatheringEvent.addArea(namedArea);
-        }
-
-        // copy gathering event to facade
-        GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();
-        derivedUnitFacade.setLocality(gatheringEvent.getLocality());
-        derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());
-        derivedUnitFacade.setCollector(gatheringEvent.getCollector());
-        derivedUnitFacade.setCountry((NamedArea)areaCountry);
-        derivedUnitFacade.setAbsoluteElevationText(gatheringEvent.getAbsoluteElevationText());
-        derivedUnitFacade.setAbsoluteElevation(gatheringEvent.getAbsoluteElevation());
-        derivedUnitFacade.setAbsoluteElevationMax(gatheringEvent.getAbsoluteElevationMax());
-        derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());
-
-        for(DefinedTermBase<?> area:unitsGatheringArea.getAreas()){
-            derivedUnitFacade.addCollectingArea((NamedArea) area);
-        }
-        //            derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());
-        // TODO exsiccatum
-
-        // add fieldNumber
-        derivedUnitFacade.setFieldNumber(NB(state.getDataHolder().fieldNumber));
-
-        // add unitNotes
-        derivedUnitFacade.addAnnotation(Annotation.NewDefaultLanguageInstance(NB(state.getDataHolder().unitNotes)));
-
-        // //add Multimedia URLs
-        if (state.getDataHolder().multimediaObjects.size() != -1) {
-            for (String multimediaObject : state.getDataHolder().multimediaObjects) {
-                Media media;
-                try {
-                    media = getImageMedia(multimediaObject, READ_MEDIA_DATA);
-                    derivedUnitFacade.addDerivedUnitMedia(media);
-                    if(state.getConfig().isAddMediaAsMediaSpecimen()){
-                        //add media also as specimen scan
-                        MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);
-                        mediaSpecimen.setMediaSpecimen(media);
-                        DefinedTermBase specimenScanTerm = getTermService().load(SPECIMEN_SCAN_TERM);
-                        if(specimenScanTerm instanceof DefinedTerm){
-                            mediaSpecimen.setKindOfUnit((DefinedTerm) specimenScanTerm);
-                        }
-                        DerivationEvent derivationEvent = DerivationEvent.NewInstance(DerivationEventType.PREPARATION());
-                        derivationEvent.addDerivative(mediaSpecimen);
-                        derivedUnitFacade.innerDerivedUnit().addDerivationEvent(derivationEvent);
-                    }
-
-                } catch (MalformedURLException e) {
-                    // TODO Auto-generated catch block
-                    e.printStackTrace();
-                }
-
-            }
-        }
-
-        //          /*
-        //           * merge AND STORE DATA
-        //           */
-        //          getTermService().saveOrUpdate(areaCountry);// TODO save area sooner
-        //
-        //          for (NamedArea area : otherAreas) {
-        //              getTermService().saveOrUpdate(area);// merge it sooner (foreach area)
-        //          }
-/*
-        save(unitsGatheringEvent.getLocality(), state);
-
-        // handle collection data
-        setCollectionData(state, derivedUnitFacade);
-
-        //Reference stuff
-        SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();
-        Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<String, OriginalSourceBase<?>>();
-
-        state.getDataHolder().docSources = new ArrayList<String>();
-        for (String[] fullReference : state.getDataHolder().referenceList) {
-            String strReference=fullReference[0];
-            String citationDetail = fullReference[1];
-            String citationURL = fullReference[2];
-
-            if (!citationURL.isEmpty()) {
-                citationDetail+=", "+citationURL;
-            }
-
-            Reference reference;
-            if(strReference.equals(state.getRef().getTitleCache())){
-                reference = state.getRef();
-            }
-            else{
-                reference = ReferenceFactory.newGeneric();
-                reference.setTitle(strReference);
-            }
-
-            IdentifiableSource sour = getIdentifiableSource(reference,citationDetail);
-
-            try{
-                if (sour.getCitation() != null){
-                    if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {
-                        state.getDataHolder().docSources.add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());
-                    } else {
-                        state.getDataHolder().docSources.add(sour.getCitation().getTitleCache());
-                    }
-                }
-            }catch(Exception e){
-                logger.warn("oups");
-            }
-            reference.addSource(sour);
-            save(reference, state);
-        }
-        List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
-        List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
-
-        Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
-        if(issTmp2!=null) {
-            osbSet.addAll(issTmp2);
-        }
-        if(issTmp!=null) {
-            osbSet.addAll(issTmp);
-        }
-
-        addToSourceMap(sourceMap, osbSet);
-
-        if( state.getConfig().isInteractWithUser()){
-            List<OriginalSourceBase<?>>sources=null;
-            if(!state.isDerivedUnitSourcesSet()){
-                sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().docSources);
-                state.setDerivedUnitSources(sources);
-                state.setDerivedUnitSourcesSet(true);
-            }
-            else{
-                sources=state.getDerivedUnitSources();
-            }
-//          System.out.println("nb sources: "+sources.size());
-//          System.out.println("derivedunitfacade : "+derivedUnitFacade.getTitleCache());
-            for (OriginalSourceBase<?> sour:sources){
-                if(sour.isInstanceOf(IdentifiableSource.class)){
-                    if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
-//                      System.out.println("add source to derivedunitfacade1 "+derivedUnitFacade.getTitleCache());
-                        derivedUnitFacade.addSource((IdentifiableSource)sour.clone());
-                    }
-                }else{
-                    if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {
-//                      System.out.println("add source to derivedunitfacade2 "+derivedUnitFacade.getTitleCache());
-                        derivedUnitFacade.addSource(OriginalSourceType.Import,sour.getCitation(),sour.getCitationMicroReference(), ioName);
-                    }
-                }
-            }
-        }else{
-            for (OriginalSourceBase<?> sr : sourceMap.values()){
-                if(sr.isInstanceOf(IdentifiableSource.class)){
-                    if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
-//                      System.out.println("add source to derivedunitfacade3 "+derivedUnitFacade.getTitleCache());
-                        derivedUnitFacade.addSource((IdentifiableSource)sr.clone());
-                    }
-                }else{
-                    if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {
-//                      System.out.println("add source to derivedunitfacade4 "+derivedUnitFacade.getTitleCache());
-                        derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);
-                    }
-                }
-            }
-        }
-
-        save(state.getDerivedUnitBase(), state);
-
-        if(DEBUG) {
-            logger.info("saved ABCD specimen ...");
-        }
-
-        // handle identifications
-        handleIdentifications(state, derivedUnitFacade);
-
-        //associatedUnits
-        importAssociatedUnits(state, item, derivedUnitFacade);
-
-*/
-
-    } catch (Exception e) {
-        String message = "Error when reading record!";
-        logger.warn(message);
-        state.getReport().addException(message, e);
-        e.printStackTrace();
-        state.setUnsuccessfull();
-    }
-
-    return;
-}
-
-
-
-
-
-
-
-
-
-
-    /*
-     * "key": 1257570425,
-"datasetKey": "7bd65a7a-f762-11e1-a439-00145eb45e9a",
-"publishingOrgKey": "90fd6680-349f-11d8-aa2d-b8a03c50a862",
-"publishingCountry": "US",
-"protocol": "DWC_ARCHIVE",
-"lastCrawled": "2016-06-06T11:11:35.800+0000",
-"lastParsed": "2016-03-21T14:11:42.224+0000",
-"extensions": { },
-"basisOfRecord": "PRESERVED_SPECIMEN",
-"individualCount": 1,
-"taxonKey": 5338762,
-"kingdomKey": 6,
-"phylumKey": 7707728,
-"classKey": 220,
-"orderKey": 412,
-"familyKey": 8798,
-"genusKey": 2907867,
-"speciesKey": 5338762,
-"scientificName": "Mitchella repens L.",
-"kingdom": "Plantae",
-"phylum": "Tracheophyta",
-"order": "Gentianales",
-"family": "Rubiaceae",
-"genus": "Mitchella",
-"species": "Mitchella repens",
-"genericName": "Mitchella",
-"specificEpithet": "repens",
-"taxonRank": "SPECIES",
-"dateIdentified": "2005-12-31T23:00:00.000+0000",
-"decimalLongitude": -98.70693,
-"decimalLatitude": 20.77805,
-"elevation": 1524.0,
-"continent": "NORTH_AMERICA",
-"stateProvince": "Hidalgo",
-"year": 2006,
-"month": 6,
-"day": 11,
-"eventDate": "2006-06-10T22:00:00.000+0000",
-"issues": [
-
-    "COORDINATE_ROUNDED",
-    "GEODETIC_DATUM_ASSUMED_WGS84"
-
-],
-"lastInterpreted": "2016-04-17T13:34:52.325+0000",
-"identifiers": [ ],
-"facts": [ ],
-"relations": [ ],
-"geodeticDatum": "WGS84",
-"class": "Magnoliopsida",
-"countryCode": "MX",
-"country": "Mexico",
-"nomenclaturalStatus": "No opinion",
-"rightsHolder": "Missouri Botanical Garden",
-"identifier": "urn:catalog:MO:Tropicos:100217973",
-"recordNumber": "Oberle 274",
-"nomenclaturalCode": "ICNafp",
-"county": "Metztitlán",
-"locality": "Along trail downslope of road between Molango and Zacualtipan.",
-"datasetName": "Tropicos",
-"gbifID": "1257570425",
-"collectionCode": "MO",
-"occurrenceID": "urn:catalog:MO:Tropicos:100217973",
-"type": "PhysicalObject",
-"taxonID": "27902971",
-"license": "http://creativecommons.org/licenses/by/4.0/legalcode",
-"catalogNumber": "100217973",
-"recordedBy": "Brad Oberle",
-"institutionCode": "MO",
-"ownerInstitutionCode": "MOBOT",
-"bibliographicCitation": "http://www.tropicos.org/Specimen/100217973",
-"identifiedBy": "B. Oberle",
-"collectionID": "http://biocol.org/urn:lsid:biocol.org:col:15859
-     *
-     */
-
-
-
-}
+package eu.etaxonomy.cdm.io.specimen.gbif.in;\r
+import java.io.IOException;\r
+import java.net.URISyntaxException;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+\r
+import org.apache.commons.lang.StringUtils;\r
+import org.apache.http.client.ClientProtocolException;\r
+import org.apache.log4j.Logger;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;\r
+import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifQueryServiceWrapper;\r
+import eu.etaxonomy.cdm.ext.occurrence.gbif.GbifResponse;\r
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
+import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;\r
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportBase;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportUtility;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.FieldUnit;\r
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
+import eu.etaxonomy.cdm.model.taxon.Classification;\r
+\r
+// $Id$\r
+/**\r
+ * Copyright (C) 2016 EDIT\r
+ * European Distributed Institute of Taxonomy\r
+ * http://www.e-taxonomy.eu\r
+ *\r
+ * The contents of this file are subject to the Mozilla Public License Version 1.1\r
+ * See LICENSE.TXT at the top of this package for the full license terms.\r
+ */\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public class GbifImport extends SpecimenImportBase<DwcaImportConfigurator, GbifImportState> {\r
+    /**\r
+     *\r
+     */\r
+    private static final long serialVersionUID = 1L;\r
+    private static final Logger logger = Logger.getLogger(GbifImport.class);\r
+\r
+    @Override\r
+    protected boolean doCheck(GbifImportState state) {\r
+        logger.warn("Checking not yet implemented for " + this.getClass().getSimpleName());\r
+        return true;\r
+    }\r
+\r
+\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)\r
+     */\r
+    @Override\r
+    protected boolean isIgnore(GbifImportState state) {\r
+        // TODO Auto-generated method stub\r
+        return false;\r
+    }\r
+\r
+\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.specimen.SpecimenImportBase#doInvoke(eu.etaxonomy.cdm.io.common.ImportStateBase)\r
+     */\r
+    @Override\r
+    protected void doInvoke(GbifImportState state) {\r
+        GbifImportState gbifImportState = state;\r
+        GbifImportConfigurator config = state.getConfig();\r
+\r
+            state.setTx(startTransaction());\r
+            logger.info("INVOKE Specimen Import from ABCD2.06 XML ");\r
+            Collection<GbifResponse> results = null;\r
+            //init cd repository\r
+            if(state.getCdmRepository()==null){\r
+                state.setCdmRepository(this);\r
+            }\r
+            if (config.getOccurenceQuery() != null){\r
+                 try {\r
+                    results = new GbifQueryServiceWrapper().query(config.getOccurenceQuery());\r
+                } catch (ClientProtocolException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                } catch (IOException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                } catch (URISyntaxException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                }\r
+\r
+\r
+            }\r
+\r
+           if(state.getConfig().getClassificationUuid()!=null){\r
+                //load classification from config if it exists\r
+                state.setClassification(getClassificationService().load(state.getConfig().getClassificationUuid()));\r
+            }\r
+            if(state.getClassification()==null){//no existing classification was set in config\r
+                List<Classification> classificationList = getClassificationService().list(Classification.class, null, null, null, null);\r
+                //get classification via user interaction\r
+                if (state.getConfig().isUseClassification() && state.getConfig().isInteractWithUser()){\r
+                    Map<String,Classification> classMap = new HashMap<String, Classification>();\r
+                    for (Classification tree : classificationList) {\r
+                        if (! StringUtils.isBlank(tree.getTitleCache())) {\r
+                            classMap.put(tree.getTitleCache(),tree);\r
+                        }\r
+                    }\r
+\r
+                }\r
+                // use default classification as the classification to import into\r
+                if (state.getClassification() == null) {\r
+                    String name = NB(state.getConfig().getClassificationName());\r
+                    for (Classification classif : classificationList){\r
+                        if (classif.getTitleCache() != null && classif.getTitleCache().equalsIgnoreCase(name)) {\r
+                            state.setClassification(classif);\r
+                        }\r
+                    }\r
+                    if (state.getClassification() == null){\r
+                        state.setClassification(Classification.NewInstance(name, state.getRef(), Language.DEFAULT()));\r
+                        //we do not need a default classification when creating an empty new one\r
+                        state.setDefaultClassification(state.getClassification());\r
+\r
+                    }\r
+\r
+                }\r
+            }\r
+            String message = "nb units to insert: " + results.size();\r
+            logger.info(message);\r
+            state.getConfig().getProgressMonitor().beginTask("Importing ABCD file", results.size());\r
+            updateProgress(state, message);\r
+\r
+            state.setDataHolder(new GbifDataHolder());\r
+            state.getDataHolder().reset();\r
+\r
+            for (GbifResponse response:results) {\r
+                if(state.getConfig().getProgressMonitor().isCanceled()){\r
+                    break;\r
+                }\r
+\r
+\r
+\r
+\r
+                //this.setUnitPropertiesXML( item, abcdFieldGetter, state);\r
+            //   updateProgress(state, "Importing data for unit "+state.getDataHolder().unitID+" ("+i+"/"+unitsList.getLength()+")");\r
+\r
+                //import unit + field unit data\r
+                this.handleSingleUnit(state, response);\r
+\r
+            }\r
+\r
+\r
+            commitTransaction(state.getTx());\r
+\r
+\r
+\r
+    }\r
+\r
+    @Override\r
+    protected void importAssociatedUnits(GbifImportState state, Object item, DerivedUnitFacade derivedUnitFacade) {\r
+\r
+        //import associated units\r
+        FieldUnit currentFieldUnit = derivedUnitFacade.innerFieldUnit();\r
+        //TODO: push state (think of implementing stack architecture for state\r
+        DerivedUnit currentUnit = state.getDerivedUnitBase();\r
+        DerivationEvent currentDerivedFrom = currentUnit.getDerivedFrom();\r
+        String currentPrefix = state.getPrefix();\r
+      /*  NodeList unitAssociationList = item.getElementsByTagName(currentPrefix+"UnitAssociation");\r
+        for(int k=0;k<unitAssociationList.getLength();k++){\r
+            if(unitAssociationList.item(k) instanceof Element){\r
+                Element unitAssociation = (Element)unitAssociationList.item(k);\r
+                UnitAssociationParser unitAssociationParser = new UnitAssociationParser(currentPrefix, state.getReport(), state.getCdmRepository());\r
+                UnitAssociationWrapper associationWrapper = unitAssociationParser.parse(unitAssociation);\r
+                if(associationWrapper!=null){\r
+                    NodeList associatedUnits = associationWrapper.getAssociatedUnits();\r
+                    if(associatedUnits!=null){\r
+                        for(int m=0;m<associatedUnits.getLength();m++){\r
+                            if(associatedUnits.item(m) instanceof Element){\r
+                                state.reset();\r
+                                state.setPrefix(associationWrapper.getPrefix());\r
+                                this.setUnitPropertiesXML((Element) associatedUnits.item(m), new Abcd206XMLFieldGetter(state.getDataHolder(), state.getPrefix()), state);\r
+                                handleSingleUnit(state, associatedUnits.item(m));\r
+\r
+                                DerivedUnit associatedUnit = state.getDerivedUnitBase();\r
+                                FieldUnit associatedFieldUnit = null;\r
+                                java.util.Collection<FieldUnit> associatedFieldUnits = state.getCdmRepository().getOccurrenceService().getFieldUnits(associatedUnit.getUuid());\r
+                                //ignore field unit if associated unit has more than one\r
+                                if(associatedFieldUnits.size()>1){\r
+                                    state.getReport().addInfoMessage(String.format("%s has more than one field unit.", associatedUnit));\r
+                                }\r
+                                else if(associatedFieldUnits.size()==1){\r
+                                    associatedFieldUnit = associatedFieldUnits.iterator().next();\r
+                                }\r
+\r
+                                //attach current unit and associated unit depending on association type\r
+\r
+                                //parent-child relation:\r
+                                //copy derivation event and connect parent and sub derivative\r
+                                if(associationWrapper.getAssociationType().contains("individual")){\r
+                                    if(currentDerivedFrom==null){\r
+                                        state.getReport().addInfoMessage(String.format("No derivation event found for unit %s. Defaulting to ACCESSIONING event.",AbcdImportUtility.getUnitID(currentUnit, config)));\r
+                                        DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, DerivationEventType.ACCESSIONING());\r
+                                    }\r
+                                    else{\r
+                                        DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedUnit, currentUnit, currentDerivedFrom.getType());\r
+                                        updatedDerivationEvent.setActor(currentDerivedFrom.getActor());\r
+                                        updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());\r
+                                        updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());\r
+                                        updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());\r
+                                    }\r
+                                    state.getReport().addDerivate(associatedUnit, currentUnit, config);\r
+                                }\r
+                                //siblings relation\r
+                                //connect current unit to field unit of associated unit\r
+                                else if(associationWrapper.getAssociationType().contains("population")){\r
+                                    //no associated field unit -> using current one\r
+                                    if(associatedFieldUnit==null){\r
+                                        if(currentFieldUnit!=null){\r
+                                            DerivationEvent.NewSimpleInstance(currentFieldUnit, associatedUnit, DerivationEventType.ACCESSIONING());\r
+                                        }\r
+                                    }\r
+                                    else{\r
+                                        if(currentDerivedFrom==null){\r
+                                            state.getReport().addInfoMessage("No derivation event found for unit "+AbcdImportUtility.getUnitID(currentUnit, config)+". Defaulting to ACCESIONING event.");\r
+                                            DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, DerivationEventType.ACCESSIONING());\r
+                                        }\r
+                                        if(currentDerivedFrom!=null && associatedFieldUnit!=currentFieldUnit){\r
+                                            DerivationEvent updatedDerivationEvent = DerivationEvent.NewSimpleInstance(associatedFieldUnit, currentUnit, currentDerivedFrom.getType());\r
+                                            updatedDerivationEvent.setActor(currentDerivedFrom.getActor());\r
+                                            updatedDerivationEvent.setDescription(currentDerivedFrom.getDescription());\r
+                                            updatedDerivationEvent.setInstitution(currentDerivedFrom.getInstitution());\r
+                                            updatedDerivationEvent.setTimeperiod(currentDerivedFrom.getTimeperiod());\r
+                                        }\r
+                                    }\r
+                                }\r
+\r
+                                //delete current field unit if replaced\r
+                                if(currentFieldUnit!=null && currentDerivedFrom!=null\r
+                                        && currentFieldUnit.getDerivationEvents().size()==1  && currentFieldUnit.getDerivationEvents().contains(currentDerivedFrom) //making sure that the field unit\r
+                                        && currentDerivedFrom.getDerivatives().size()==1 && currentDerivedFrom.getDerivatives().contains(currentUnit) //is not attached to other derived units\r
+                                        && currentDerivedFrom!=currentUnit.getDerivedFrom() // <- derivation has been replaced and can be deleted\r
+                                        ){\r
+                                    currentFieldUnit.removeDerivationEvent(currentDerivedFrom);\r
+                                    state.getCdmRepository().getOccurrenceService().delete(currentFieldUnit);\r
+                                }\r
+\r
+                                save(associatedUnit, state);\r
+                            }\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }*/\r
+        //TODO: pop state\r
+        state.reset();\r
+        state.setDerivedUnitBase(currentUnit);\r
+        state.setPrefix(currentPrefix);\r
+    }\r
+@Override\r
+protected void handleSingleUnit(GbifImportState state, Object itemObject){\r
+    GbifResponse item;\r
+    if (itemObject instanceof GbifResponse){\r
+        item = (GbifResponse) itemObject;\r
+    } else{\r
+        logger.error("For Gbif Import the item has to be of type GbifResponse.");\r
+        return;\r
+    }\r
+    if (DEBUG) {\r
+        logger.info("handleSingleUnit "+state.getRef());\r
+    }\r
+    try {\r
+        ICdmApplicationConfiguration cdmAppController = state.getConfig().getCdmAppController();\r
+        if(cdmAppController==null){\r
+            cdmAppController = this;\r
+        }\r
+        //check if unit already exists\r
+        DerivedUnitFacade derivedUnitFacade = null;\r
+        if(state.getConfig().isIgnoreImportOfExistingSpecimens()){\r
+            String[] tripleId = item.getTripleID();\r
+            SpecimenOrObservationBase<?> existingSpecimen = findExistingSpecimen(tripleId[0], state);\r
+            if(existingSpecimen!=null && existingSpecimen.isInstanceOf(DerivedUnit.class)){\r
+                DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(existingSpecimen, DerivedUnit.class);\r
+                state.setDerivedUnitBase(derivedUnit);\r
+                derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());\r
+                importAssociatedUnits(state, item, derivedUnitFacade);\r
+                state.getReport().addAlreadyExistingSpecimen(SpecimenImportUtility.getUnitID(derivedUnit, state.getConfig()), derivedUnit);\r
+                return;\r
+            }\r
+        }\r
+        // TODO: implement overwrite/merge specimen\r
+//      else if(state.getConfig().isOverwriteExistingSpecimens()){\r
+//          Pager<SpecimenOrObservationBase> existingSpecimens = cdmAppController.getOccurrenceService().findByTitle(config);\r
+//          if(!existingSpecimens.getRecords().isEmpty()){\r
+//              derivedUnitFacade = DerivedUnitFacade.NewInstance(derivedUnit);\r
+//              derivedUnitBase = derivedUnitFacade.innerDerivedUnit();\r
+//              fieldUnit = derivedUnitFacade.getFieldUnit(true);\r
+//          }\r
+//      }\r
+        //import new specimen\r
+\r
+        // import DNA unit\r
+        //TODO!!!!\r
+//        if(state.getDataHolder().catalogNumber!=null && state.getDataHolder()..equalsIgnoreCase("dna")){\r
+//            AbcdDnaParser dnaParser = new AbcdDnaParser(state.getPrefix(), state.getReport(), state.getCdmRepository());\r
+//            DnaSample dnaSample = dnaParser.parse(item, state);\r
+//            save(dnaSample, state);\r
+//            //set dna as derived unit to avoid creating an extra specimen for this dna sample (instead just the field unit will be created)\r
+//            state.setDerivedUnitBase(dnaSample);\r
+//            derivedUnitFacade = DerivedUnitFacade.NewInstance(state.getDerivedUnitBase());\r
+//        }\r
+//        else{\r
+//            // create facade\r
+//            derivedUnitFacade = getFacade(state);\r
+//            state.setDerivedUnitBase(derivedUnitFacade.innerDerivedUnit());\r
+//        }\r
+\r
+        /**\r
+         * GATHERING EVENT\r
+         */\r
+        // gathering event\r
+      /*  UnitsGatheringEvent unitsGatheringEvent = new UnitsGatheringEvent(cdmAppController.getTermService(),\r
+                state.getDataHolder().locality, state.getDataHolder().languageIso, state.getDataHolder().longitude,\r
+                state.getDataHolder().latitude, state.getDataHolder().gatheringElevationText,\r
+                state.getDataHolder().gatheringElevationMin, state.getDataHolder().gatheringElevationMax,\r
+                state.getDataHolder().gatheringElevationUnit, state.getDataHolder().gatheringDateText,\r
+                state.getDataHolder().gatheringNotes, state.getTransformer().getReferenceSystemByKey(\r
+                        state.getDataHolder().gatheringSpatialDatum), state.getDataHolder().gatheringAgentList,\r
+                state.getDataHolder().gatheringTeamList, state.getConfig());\r
+\r
+        // country\r
+        UnitsGatheringArea unitsGatheringArea = new UnitsGatheringArea();\r
+        //  unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(), getTermService());\r
+        unitsGatheringArea.setParams(state.getDataHolder().isocountry, state.getDataHolder().country, state.getConfig(), cdmAppController.getTermService(), cdmAppController.getOccurrenceService());\r
+\r
+        DefinedTermBase<?> areaCountry =  unitsGatheringArea.getCountry();\r
+\r
+        // other areas\r
+        unitsGatheringArea = new UnitsGatheringArea();\r
+        //            unitsGatheringArea.setConfig(state.getConfig(),getOccurrenceService(),getTermService());\r
+        unitsGatheringArea.setAreas(state.getDataHolder().namedAreaList,state.getConfig(), cdmAppController.getTermService(), cdmAppController.getVocabularyService());\r
+        ArrayList<DefinedTermBase> nas = unitsGatheringArea.getAreas();\r
+        for (DefinedTermBase namedArea : nas) {\r
+            unitsGatheringEvent.addArea(namedArea);\r
+        }\r
+\r
+        // copy gathering event to facade\r
+        GatheringEvent gatheringEvent = unitsGatheringEvent.getGatheringEvent();\r
+        derivedUnitFacade.setLocality(gatheringEvent.getLocality());\r
+        derivedUnitFacade.setExactLocation(gatheringEvent.getExactLocation());\r
+        derivedUnitFacade.setCollector(gatheringEvent.getCollector());\r
+        derivedUnitFacade.setCountry((NamedArea)areaCountry);\r
+        derivedUnitFacade.setAbsoluteElevationText(gatheringEvent.getAbsoluteElevationText());\r
+        derivedUnitFacade.setAbsoluteElevation(gatheringEvent.getAbsoluteElevation());\r
+        derivedUnitFacade.setAbsoluteElevationMax(gatheringEvent.getAbsoluteElevationMax());\r
+        derivedUnitFacade.setGatheringPeriod(gatheringEvent.getTimeperiod());\r
+\r
+        for(DefinedTermBase<?> area:unitsGatheringArea.getAreas()){\r
+            derivedUnitFacade.addCollectingArea((NamedArea) area);\r
+        }\r
+        //            derivedUnitFacade.addCollectingAreas(unitsGatheringArea.getAreas());\r
+        // TODO exsiccatum\r
+\r
+        // add fieldNumber\r
+        derivedUnitFacade.setFieldNumber(NB(state.getDataHolder().fieldNumber));\r
+\r
+        // add unitNotes\r
+        derivedUnitFacade.addAnnotation(Annotation.NewDefaultLanguageInstance(NB(state.getDataHolder().unitNotes)));\r
+\r
+        // //add Multimedia URLs\r
+        if (state.getDataHolder().multimediaObjects.size() != -1) {\r
+            for (String multimediaObject : state.getDataHolder().multimediaObjects) {\r
+                Media media;\r
+                try {\r
+                    media = getImageMedia(multimediaObject, READ_MEDIA_DATA);\r
+                    derivedUnitFacade.addDerivedUnitMedia(media);\r
+                    if(state.getConfig().isAddMediaAsMediaSpecimen()){\r
+                        //add media also as specimen scan\r
+                        MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.Media);\r
+                        mediaSpecimen.setMediaSpecimen(media);\r
+                        DefinedTermBase specimenScanTerm = getTermService().load(SPECIMEN_SCAN_TERM);\r
+                        if(specimenScanTerm instanceof DefinedTerm){\r
+                            mediaSpecimen.setKindOfUnit((DefinedTerm) specimenScanTerm);\r
+                        }\r
+                        DerivationEvent derivationEvent = DerivationEvent.NewInstance(DerivationEventType.PREPARATION());\r
+                        derivationEvent.addDerivative(mediaSpecimen);\r
+                        derivedUnitFacade.innerDerivedUnit().addDerivationEvent(derivationEvent);\r
+                    }\r
+\r
+                } catch (MalformedURLException e) {\r
+                    // TODO Auto-generated catch block\r
+                    e.printStackTrace();\r
+                }\r
+\r
+            }\r
+        }\r
+\r
+        //          /*\r
+        //           * merge AND STORE DATA\r
+        //           */\r
+        //          getTermService().saveOrUpdate(areaCountry);// TODO save area sooner\r
+        //\r
+        //          for (NamedArea area : otherAreas) {\r
+        //              getTermService().saveOrUpdate(area);// merge it sooner (foreach area)\r
+        //          }\r
+/*\r
+        save(unitsGatheringEvent.getLocality(), state);\r
+\r
+        // handle collection data\r
+        setCollectionData(state, derivedUnitFacade);\r
+\r
+        //Reference stuff\r
+        SpecimenUserInteraction sui = state.getConfig().getSpecimenUserInteraction();\r
+        Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<String, OriginalSourceBase<?>>();\r
+\r
+        state.getDataHolder().docSources = new ArrayList<String>();\r
+        for (String[] fullReference : state.getDataHolder().referenceList) {\r
+            String strReference=fullReference[0];\r
+            String citationDetail = fullReference[1];\r
+            String citationURL = fullReference[2];\r
+\r
+            if (!citationURL.isEmpty()) {\r
+                citationDetail+=", "+citationURL;\r
+            }\r
+\r
+            Reference reference;\r
+            if(strReference.equals(state.getRef().getTitleCache())){\r
+                reference = state.getRef();\r
+            }\r
+            else{\r
+                reference = ReferenceFactory.newGeneric();\r
+                reference.setTitle(strReference);\r
+            }\r
+\r
+            IdentifiableSource sour = getIdentifiableSource(reference,citationDetail);\r
+\r
+            try{\r
+                if (sour.getCitation() != null){\r
+                    if(StringUtils.isNotBlank(sour.getCitationMicroReference())) {\r
+                        state.getDataHolder().docSources.add(sour.getCitation().getTitleCache()+ "---"+sour.getCitationMicroReference());\r
+                    } else {\r
+                        state.getDataHolder().docSources.add(sour.getCitation().getTitleCache());\r
+                    }\r
+                }\r
+            }catch(Exception e){\r
+                logger.warn("oups");\r
+            }\r
+            reference.addSource(sour);\r
+            save(reference, state);\r
+        }\r
+        List<IdentifiableSource> issTmp = new ArrayList<IdentifiableSource>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);\r
+        List<DescriptionElementSource> issTmp2 = new ArrayList<DescriptionElementSource>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);\r
+\r
+        Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();\r
+        if(issTmp2!=null) {\r
+            osbSet.addAll(issTmp2);\r
+        }\r
+        if(issTmp!=null) {\r
+            osbSet.addAll(issTmp);\r
+        }\r
+\r
+        addToSourceMap(sourceMap, osbSet);\r
+\r
+        if( state.getConfig().isInteractWithUser()){\r
+            List<OriginalSourceBase<?>>sources=null;\r
+            if(!state.isDerivedUnitSourcesSet()){\r
+                sources= sui.askForSource(sourceMap, "the unit itself","",getReferenceService(), state.getDataHolder().docSources);\r
+                state.setDerivedUnitSources(sources);\r
+                state.setDerivedUnitSourcesSet(true);\r
+            }\r
+            else{\r
+                sources=state.getDerivedUnitSources();\r
+            }\r
+//          System.out.println("nb sources: "+sources.size());\r
+//          System.out.println("derivedunitfacade : "+derivedUnitFacade.getTitleCache());\r
+            for (OriginalSourceBase<?> sour:sources){\r
+                if(sour.isInstanceOf(IdentifiableSource.class)){\r
+                    if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {\r
+//                      System.out.println("add source to derivedunitfacade1 "+derivedUnitFacade.getTitleCache());\r
+                        derivedUnitFacade.addSource((IdentifiableSource)sour.clone());\r
+                    }\r
+                }else{\r
+                    if(sourceNotLinkedToElement(derivedUnitFacade,sour)) {\r
+//                      System.out.println("add source to derivedunitfacade2 "+derivedUnitFacade.getTitleCache());\r
+                        derivedUnitFacade.addSource(OriginalSourceType.Import,sour.getCitation(),sour.getCitationMicroReference(), ioName);\r
+                    }\r
+                }\r
+            }\r
+        }else{\r
+            for (OriginalSourceBase<?> sr : sourceMap.values()){\r
+                if(sr.isInstanceOf(IdentifiableSource.class)){\r
+                    if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {\r
+//                      System.out.println("add source to derivedunitfacade3 "+derivedUnitFacade.getTitleCache());\r
+                        derivedUnitFacade.addSource((IdentifiableSource)sr.clone());\r
+                    }\r
+                }else{\r
+                    if(sourceNotLinkedToElement(derivedUnitFacade,sr)) {\r
+//                      System.out.println("add source to derivedunitfacade4 "+derivedUnitFacade.getTitleCache());\r
+                        derivedUnitFacade.addSource(OriginalSourceType.Import,sr.getCitation(),sr.getCitationMicroReference(), ioName);\r
+                    }\r
+                }\r
+            }\r
+        }\r
+\r
+        save(state.getDerivedUnitBase(), state);\r
+\r
+        if(DEBUG) {\r
+            logger.info("saved ABCD specimen ...");\r
+        }\r
+\r
+        // handle identifications\r
+        handleIdentifications(state, derivedUnitFacade);\r
+\r
+        //associatedUnits\r
+        importAssociatedUnits(state, item, derivedUnitFacade);\r
+\r
+*/\r
+\r
+    } catch (Exception e) {\r
+        String message = "Error when reading record!";\r
+        logger.warn(message);\r
+        state.getReport().addException(message, e);\r
+        e.printStackTrace();\r
+        state.setUnsuccessfull();\r
+    }\r
+\r
+    return;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+    /*\r
+     * "key": 1257570425,\r
+"datasetKey": "7bd65a7a-f762-11e1-a439-00145eb45e9a",\r
+"publishingOrgKey": "90fd6680-349f-11d8-aa2d-b8a03c50a862",\r
+"publishingCountry": "US",\r
+"protocol": "DWC_ARCHIVE",\r
+"lastCrawled": "2016-06-06T11:11:35.800+0000",\r
+"lastParsed": "2016-03-21T14:11:42.224+0000",\r
+"extensions": { },\r
+"basisOfRecord": "PRESERVED_SPECIMEN",\r
+"individualCount": 1,\r
+"taxonKey": 5338762,\r
+"kingdomKey": 6,\r
+"phylumKey": 7707728,\r
+"classKey": 220,\r
+"orderKey": 412,\r
+"familyKey": 8798,\r
+"genusKey": 2907867,\r
+"speciesKey": 5338762,\r
+"scientificName": "Mitchella repens L.",\r
+"kingdom": "Plantae",\r
+"phylum": "Tracheophyta",\r
+"order": "Gentianales",\r
+"family": "Rubiaceae",\r
+"genus": "Mitchella",\r
+"species": "Mitchella repens",\r
+"genericName": "Mitchella",\r
+"specificEpithet": "repens",\r
+"taxonRank": "SPECIES",\r
+"dateIdentified": "2005-12-31T23:00:00.000+0000",\r
+"decimalLongitude": -98.70693,\r
+"decimalLatitude": 20.77805,\r
+"elevation": 1524.0,\r
+"continent": "NORTH_AMERICA",\r
+"stateProvince": "Hidalgo",\r
+"year": 2006,\r
+"month": 6,\r
+"day": 11,\r
+"eventDate": "2006-06-10T22:00:00.000+0000",\r
+"issues": [\r
+\r
+    "COORDINATE_ROUNDED",\r
+    "GEODETIC_DATUM_ASSUMED_WGS84"\r
+\r
+],\r
+"lastInterpreted": "2016-04-17T13:34:52.325+0000",\r
+"identifiers": [ ],\r
+"facts": [ ],\r
+"relations": [ ],\r
+"geodeticDatum": "WGS84",\r
+"class": "Magnoliopsida",\r
+"countryCode": "MX",\r
+"country": "Mexico",\r
+"nomenclaturalStatus": "No opinion",\r
+"rightsHolder": "Missouri Botanical Garden",\r
+"identifier": "urn:catalog:MO:Tropicos:100217973",\r
+"recordNumber": "Oberle 274",\r
+"nomenclaturalCode": "ICNafp",\r
+"county": "Metztitlán",\r
+"locality": "Along trail downslope of road between Molango and Zacualtipan.",\r
+"datasetName": "Tropicos",\r
+"gbifID": "1257570425",\r
+"collectionCode": "MO",\r
+"occurrenceID": "urn:catalog:MO:Tropicos:100217973",\r
+"type": "PhysicalObject",\r
+"taxonID": "27902971",\r
+"license": "http://creativecommons.org/licenses/by/4.0/legalcode",\r
+"catalogNumber": "100217973",\r
+"recordedBy": "Brad Oberle",\r
+"institutionCode": "MO",\r
+"ownerInstitutionCode": "MOBOT",\r
+"bibliographicCitation": "http://www.tropicos.org/Specimen/100217973",\r
+"identifiedBy": "B. Oberle",\r
+"collectionID": "http://biocol.org/urn:lsid:biocol.org:col:15859\r
+     *\r
+     */\r
+\r
+\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index 6fe841f..540dd8d
@@ -1,68 +1,68 @@
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.gbif.in;
-
-import eu.etaxonomy.cdm.io.common.ImportStateBase;
-import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
-import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
-import eu.etaxonomy.cdm.model.reference.Reference;
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public class GbifImportConfigurator<GbifImportState> extends SpecimenImportConfiguratorBase{
-
-    /**
-     * @param transformer
-     */
-    public GbifImportConfigurator(IInputTransformer transformer) {
-        super(transformer);
-        // TODO Auto-generated constructor stub
-    }
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#makeIoClassList()
-     */
-    @Override
-    protected void makeIoClassList() {
-        System.out.println("makeIOClassList");
-        ioClassList = new Class[]{
-               GbifImport.class,
-        };
-
-    }
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()
-     */
-    @Override
-    public Reference getSourceReference() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()
-     */
-    @Override
-    public <STATE extends ImportStateBase> STATE getNewState() {
-        // TODO Auto-generated method stub
-        return null;
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.gbif.in;\r
+\r
+import eu.etaxonomy.cdm.io.common.ImportStateBase;\r
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public class GbifImportConfigurator<GbifImportState> extends SpecimenImportConfiguratorBase{\r
+\r
+    /**\r
+     * @param transformer\r
+     */\r
+    public GbifImportConfigurator(IInputTransformer transformer) {\r
+        super(transformer);\r
+        // TODO Auto-generated constructor stub\r
+    }\r
+\r
+    /**\r
+     *\r
+     */\r
+    private static final long serialVersionUID = 1L;\r
+\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#makeIoClassList()\r
+     */\r
+    @Override\r
+    protected void makeIoClassList() {\r
+        System.out.println("makeIOClassList");\r
+        ioClassList = new Class[]{\r
+               GbifImport.class,\r
+        };\r
+\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSourceReference()\r
+     */\r
+    @Override\r
+    public Reference getSourceReference() {\r
+        // TODO Auto-generated method stub\r
+        return null;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()\r
+     */\r
+    @Override\r
+    public <STATE extends ImportStateBase> STATE getNewState() {\r
+        // TODO Auto-generated method stub\r
+        return null;\r
+    }\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index 4680319..b8c2d5e
@@ -1,21 +1,21 @@
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.gbif.in;
-
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public class GbifImportReport extends SpecimenImportReport{
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.gbif.in;\r
+\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public class GbifImportReport extends SpecimenImportReport{\r
+\r
+}\r
old mode 100755 (executable)
new mode 100644 (file)
index d63ff88..f8cf22b
-// $Id$
-/**
-* Copyright (C) 2016 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.gbif.in;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.transaction.TransactionStatus;
-
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
-import eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdTransformer;
-import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
-import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
-import eu.etaxonomy.cdm.model.description.TaxonDescription;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-import eu.etaxonomy.cdm.model.reference.Reference;
-import eu.etaxonomy.cdm.model.taxon.Classification;
-
-/**
- * @author k.luther
- * @date 15.07.2016
- *
- */
-public class GbifImportState extends SpecimenImportStateBase<GbifImportConfigurator, GbifImportState> {
-
-    private TransactionStatus tx;
-
-
-
-
-    private ICdmApplicationConfiguration cdmRepository;
-
-    private String prefix;
-
-    private GbifImportReport report;
-
-    private Classification classification = null;
-    private Classification defaultClassification = null;
-    private Reference ref = null;
-
-    private GbifDataHolder dataHolder;
-    private DerivedUnit derivedUnitBase;
-
-    private List<OriginalSourceBase<?>> associationRefs = new ArrayList<OriginalSourceBase<?>>();
-    private boolean associationSourcesSet=false;
-    private List<OriginalSourceBase<?>> descriptionRefs = new ArrayList<OriginalSourceBase<?>>();
-    private boolean descriptionSourcesSet=false;
-    private List<OriginalSourceBase<?>> derivedUnitSources = new ArrayList<OriginalSourceBase<?>>();
-    private boolean derivedUnitSourcesSet=false;
-    private boolean descriptionGroupSet = false;
-    private TaxonDescription descriptionGroup = null;
-
-
-    /**
-     * @param config
-     */
-    protected GbifImportState(GbifImportConfigurator config) {
-        super(config);
-        report = new GbifImportReport();
-        setTransformer(new AbcdTransformer());
-    }
-
-    /* ------Getter/Setter -----*/
-
-    @Override
-    public TransactionStatus getTx() {
-        return tx;
-    }
-
-
-    @Override
-    public void setTx(TransactionStatus tx) {
-        this.tx = tx;
-    }
-
-
-    @Override
-    public ICdmApplicationConfiguration getCdmRepository() {
-        return cdmRepository;
-    }
-
-
-    @Override
-    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {
-        this.cdmRepository = cdmRepository;
-    }
-
-
-    public String getPrefix() {
-        return prefix;
-    }
-
-
-    public void setPrefix(String prefix) {
-        this.prefix = prefix;
-    }
-
-
-    @Override
-    public SpecimenImportReport getReport() {
-        return report;
-    }
-
-
-    public void setReport(GbifImportReport report) {
-        this.report = report;
-    }
-
-
-    @Override
-    public Classification getClassification() {
-        return classification;
-    }
-
-
-    @Override
-    public void setClassification(Classification classification) {
-        this.classification = classification;
-    }
-
-
-    @Override
-    public Classification getDefaultClassification() {
-        return defaultClassification;
-    }
-
-
-    @Override
-    public void setDefaultClassification(Classification defaultClassification) {
-        this.defaultClassification = defaultClassification;
-    }
-
-
-    @Override
-    public Reference getRef() {
-        return ref;
-    }
-
-
-    @Override
-    public void setRef(Reference ref) {
-        this.ref = ref;
-    }
-
-
-    @Override
-    public GbifDataHolder getDataHolder() {
-        return dataHolder;
-    }
-
-
-    public void setDataHolder(GbifDataHolder dataHolder) {
-        this.dataHolder = dataHolder;
-    }
-
-
-    @Override
-    public DerivedUnit getDerivedUnitBase() {
-        return derivedUnitBase;
-    }
-
-
-    @Override
-    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
-        this.derivedUnitBase = derivedUnitBase;
-    }
-
-
-    public List<OriginalSourceBase<?>> getAssociationRefs() {
-        return associationRefs;
-    }
-
-
-    public void setAssociationRefs(List<OriginalSourceBase<?>> associationRefs) {
-        this.associationRefs = associationRefs;
-    }
-
-
-    public boolean isAssociationSourcesSet() {
-        return associationSourcesSet;
-    }
-
-
-    public void setAssociationSourcesSet(boolean associationSourcesSet) {
-        this.associationSourcesSet = associationSourcesSet;
-    }
-
-
-    public List<OriginalSourceBase<?>> getDescriptionRefs() {
-        return descriptionRefs;
-    }
-
-
-    public void setDescriptionRefs(List<OriginalSourceBase<?>> descriptionRefs) {
-        this.descriptionRefs = descriptionRefs;
-    }
-
-
-    public boolean isDescriptionSourcesSet() {
-        return descriptionSourcesSet;
-    }
-
-
-    public void setDescriptionSourcesSet(boolean descriptionSourcesSet) {
-        this.descriptionSourcesSet = descriptionSourcesSet;
-    }
-
-
-    public List<OriginalSourceBase<?>> getDerivedUnitSources() {
-        return derivedUnitSources;
-    }
-
-
-    public void setDerivedUnitSources(List<OriginalSourceBase<?>> derivedUnitSources) {
-        this.derivedUnitSources = derivedUnitSources;
-    }
-
-
-    public boolean isDerivedUnitSourcesSet() {
-        return derivedUnitSourcesSet;
-    }
-
-
-    public void setDerivedUnitSourcesSet(boolean derivedUnitSourcesSet) {
-        this.derivedUnitSourcesSet = derivedUnitSourcesSet;
-    }
-
-
-    public boolean isDescriptionGroupSet() {
-        return descriptionGroupSet;
-    }
-
-
-    public void setDescriptionGroupSet(boolean descriptionGroupSet) {
-        this.descriptionGroupSet = descriptionGroupSet;
-    }
-
-
-    @Override
-    public TaxonDescription getDescriptionGroup() {
-        return descriptionGroup;
-    }
-
-
-    @Override
-    public void setDescriptionGroup(TaxonDescription descriptionGroup) {
-        this.descriptionGroup = descriptionGroup;
-    }
-
-    /* (non-Javadoc)
-     * @see eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase#reset()
-     */
-    @Override
-    public void reset() {
-        // TODO Auto-generated method stub
-
-    }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2016 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.gbif.in;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import org.springframework.transaction.TransactionStatus;\r
+\r
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdTransformer;\r
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;\r
+import eu.etaxonomy.cdm.model.common.OriginalSourceBase;\r
+import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
+import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.taxon.Classification;\r
+\r
+/**\r
+ * @author k.luther\r
+ * @date 15.07.2016\r
+ *\r
+ */\r
+public class GbifImportState extends SpecimenImportStateBase<GbifImportConfigurator, GbifImportState> {\r
+\r
+    private TransactionStatus tx;\r
+\r
+\r
+\r
+\r
+    private ICdmApplicationConfiguration cdmRepository;\r
+\r
+    private String prefix;\r
+\r
+    private GbifImportReport report;\r
+\r
+    private Classification classification = null;\r
+    private Classification defaultClassification = null;\r
+    private Reference ref = null;\r
+\r
+    private GbifDataHolder dataHolder;\r
+    private DerivedUnit derivedUnitBase;\r
+\r
+    private List<OriginalSourceBase<?>> associationRefs = new ArrayList<OriginalSourceBase<?>>();\r
+    private boolean associationSourcesSet=false;\r
+    private List<OriginalSourceBase<?>> descriptionRefs = new ArrayList<OriginalSourceBase<?>>();\r
+    private boolean descriptionSourcesSet=false;\r
+    private List<OriginalSourceBase<?>> derivedUnitSources = new ArrayList<OriginalSourceBase<?>>();\r
+    private boolean derivedUnitSourcesSet=false;\r
+    private boolean descriptionGroupSet = false;\r
+    private TaxonDescription descriptionGroup = null;\r
+\r
+\r
+    /**\r
+     * @param config\r
+     */\r
+    protected GbifImportState(GbifImportConfigurator config) {\r
+        super(config);\r
+        report = new GbifImportReport();\r
+        setTransformer(new AbcdTransformer());\r
+    }\r
+\r
+    /* ------Getter/Setter -----*/\r
+\r
+    @Override\r
+    public TransactionStatus getTx() {\r
+        return tx;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setTx(TransactionStatus tx) {\r
+        this.tx = tx;\r
+    }\r
+\r
+\r
+    @Override\r
+    public ICdmApplicationConfiguration getCdmRepository() {\r
+        return cdmRepository;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setCdmRepository(ICdmApplicationConfiguration cdmRepository) {\r
+        this.cdmRepository = cdmRepository;\r
+    }\r
+\r
+\r
+    public String getPrefix() {\r
+        return prefix;\r
+    }\r
+\r
+\r
+    public void setPrefix(String prefix) {\r
+        this.prefix = prefix;\r
+    }\r
+\r
+\r
+    @Override\r
+    public SpecimenImportReport getReport() {\r
+        return report;\r
+    }\r
+\r
+\r
+    public void setReport(GbifImportReport report) {\r
+        this.report = report;\r
+    }\r
+\r
+\r
+    @Override\r
+    public Classification getClassification() {\r
+        return classification;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setClassification(Classification classification) {\r
+        this.classification = classification;\r
+    }\r
+\r
+\r
+    @Override\r
+    public Classification getDefaultClassification() {\r
+        return defaultClassification;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setDefaultClassification(Classification defaultClassification) {\r
+        this.defaultClassification = defaultClassification;\r
+    }\r
+\r
+\r
+    @Override\r
+    public Reference getRef() {\r
+        return ref;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setRef(Reference ref) {\r
+        this.ref = ref;\r
+    }\r
+\r
+\r
+    @Override\r
+    public GbifDataHolder getDataHolder() {\r
+        return dataHolder;\r
+    }\r
+\r
+\r
+    public void setDataHolder(GbifDataHolder dataHolder) {\r
+        this.dataHolder = dataHolder;\r
+    }\r
+\r
+\r
+    @Override\r
+    public DerivedUnit getDerivedUnitBase() {\r
+        return derivedUnitBase;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {\r
+        this.derivedUnitBase = derivedUnitBase;\r
+    }\r
+\r
+\r
+    public List<OriginalSourceBase<?>> getAssociationRefs() {\r
+        return associationRefs;\r
+    }\r
+\r
+\r
+    public void setAssociationRefs(List<OriginalSourceBase<?>> associationRefs) {\r
+        this.associationRefs = associationRefs;\r
+    }\r
+\r
+\r
+    public boolean isAssociationSourcesSet() {\r
+        return associationSourcesSet;\r
+    }\r
+\r
+\r
+    public void setAssociationSourcesSet(boolean associationSourcesSet) {\r
+        this.associationSourcesSet = associationSourcesSet;\r
+    }\r
+\r
+\r
+    public List<OriginalSourceBase<?>> getDescriptionRefs() {\r
+        return descriptionRefs;\r
+    }\r
+\r
+\r
+    public void setDescriptionRefs(List<OriginalSourceBase<?>> descriptionRefs) {\r
+        this.descriptionRefs = descriptionRefs;\r
+    }\r
+\r
+\r
+    public boolean isDescriptionSourcesSet() {\r
+        return descriptionSourcesSet;\r
+    }\r
+\r
+\r
+    public void setDescriptionSourcesSet(boolean descriptionSourcesSet) {\r
+        this.descriptionSourcesSet = descriptionSourcesSet;\r
+    }\r
+\r
+\r
+    public List<OriginalSourceBase<?>> getDerivedUnitSources() {\r
+        return derivedUnitSources;\r
+    }\r
+\r
+\r
+    public void setDerivedUnitSources(List<OriginalSourceBase<?>> derivedUnitSources) {\r
+        this.derivedUnitSources = derivedUnitSources;\r
+    }\r
+\r
+\r
+    public boolean isDerivedUnitSourcesSet() {\r
+        return derivedUnitSourcesSet;\r
+    }\r
+\r
+\r
+    public void setDerivedUnitSourcesSet(boolean derivedUnitSourcesSet) {\r
+        this.derivedUnitSourcesSet = derivedUnitSourcesSet;\r
+    }\r
+\r
+\r
+    public boolean isDescriptionGroupSet() {\r
+        return descriptionGroupSet;\r
+    }\r
+\r
+\r
+    public void setDescriptionGroupSet(boolean descriptionGroupSet) {\r
+        this.descriptionGroupSet = descriptionGroupSet;\r
+    }\r
+\r
+\r
+    @Override\r
+    public TaxonDescription getDescriptionGroup() {\r
+        return descriptionGroup;\r
+    }\r
+\r
+\r
+    @Override\r
+    public void setDescriptionGroup(TaxonDescription descriptionGroup) {\r
+        this.descriptionGroup = descriptionGroup;\r
+    }\r
+\r
+    /* (non-Javadoc)\r
+     * @see eu.etaxonomy.cdm.io.specimen.SpecimenImportStateBase#reset()\r
+     */\r
+    @Override\r
+    public void reset() {\r
+        // TODO Auto-generated method stub\r
+\r
+    }\r
+\r
+}\r