-// $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
+// $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.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
+// $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 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
+// $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) 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
+// $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 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
+// $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, SpecimenImportReport 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, SpecimenImportReport report){
+ if(nodeList.getLength()>0){
+ return parseDouble(nodeList.item(0), report);
+ }
+ return null;
+ }
+
+ public static Double parseDouble(Node node, SpecimenImportReport 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, SpecimenImportReport 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.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
+// $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 SpecimenImportReport report;
+
+ private final ICdmApplicationConfiguration cdmAppController;
+
+
+ public AbcdPersonParser(String prefix, SpecimenImportReport 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.io.File;\r
-import java.io.FileNotFoundException;\r
-import java.io.PrintStream;\r
-import java.io.PrintWriter;\r
-import java.io.StringWriter;\r
-import java.net.URI;\r
-import java.util.ArrayList;\r
-import java.util.HashMap;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Set;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;\r
-import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;\r
-import eu.etaxonomy.cdm.model.taxon.Taxon;\r
-import eu.etaxonomy.cdm.model.taxon.TaxonNode;\r
-\r
-/**\r
- * Gathers information about the ABCD import and presents them in a suitable way.\r
- * @author pplitzner\r
- * @date Jan 23, 2015\r
- *\r
- */\r
-public class SpecimenImportReport {\r
-\r
- static private final Logger logger = Logger.getLogger(SpecimenImportReport.class);\r
-\r
-\r
- private final List<Taxon> createdTaxa = new ArrayList<Taxon>();\r
- private final Map<Taxon, List<UnitIdSpecimen>> taxonToAssociatedSpecimens = new HashMap<Taxon, List<UnitIdSpecimen>>();\r
- private final Map<UnitIdSpecimen, List<UnitIdSpecimen>> derivateMap = new HashMap<UnitIdSpecimen, List<UnitIdSpecimen>>();\r
- private final List<UnitIdSpecimen> alreadyExistingSpecimens = new ArrayList<UnitIdSpecimen>();\r
- private final List<TaxonNameBase<?, ?>> createdNames = new ArrayList<TaxonNameBase<?,?>>();\r
- private final List<TaxonNode> createdTaxonNodes = new ArrayList<TaxonNode>();\r
- private final List<String> infoMessages = new ArrayList<String>();\r
-\r
- public void addTaxon(Taxon taxon){\r
- createdTaxa.add(taxon);\r
- }\r
-\r
- public void addName(TaxonNameBase<?, ?> taxonName){\r
- createdNames.add(taxonName);\r
- }\r
-\r
- public void addTaxonNode(TaxonNode taxonNode){\r
- createdTaxonNodes.add(taxonNode);\r
- }\r
-\r
- public void addDerivate(DerivedUnit parent, Abcd206ImportConfigurator config){\r
- addDerivate(parent, null, config);\r
- }\r
-\r
- public void addDerivate(DerivedUnit parent, DerivedUnit child, Abcd206ImportConfigurator config){\r
- UnitIdSpecimen parentUnitIdSpecimen = new UnitIdSpecimen(SpecimenImportUtility.getUnitID(parent, config), parent);\r
- List<UnitIdSpecimen> children = derivateMap.get(parentUnitIdSpecimen);\r
- if(children==null){\r
- children = new ArrayList<UnitIdSpecimen>();\r
- }\r
- if(child!=null){\r
- children.add(new UnitIdSpecimen(SpecimenImportUtility.getUnitID(child, config), child));\r
- }\r
- derivateMap.put(parentUnitIdSpecimen, children);\r
- }\r
-\r
- public void addIndividualAssociation(Taxon taxon, String derivedUnitId, DerivedUnit derivedUnitBase) {\r
- UnitIdSpecimen derivedUnitIdSpecimen = new UnitIdSpecimen(derivedUnitId, derivedUnitBase);\r
- List<UnitIdSpecimen> associatedSpecimens = taxonToAssociatedSpecimens.get(taxon);\r
- if(associatedSpecimens==null){\r
- associatedSpecimens = new ArrayList<UnitIdSpecimen>();\r
- }\r
- associatedSpecimens.add(derivedUnitIdSpecimen);\r
- taxonToAssociatedSpecimens.put(taxon, associatedSpecimens);\r
- }\r
-\r
- public void addAlreadyExistingSpecimen(String unitId, DerivedUnit derivedUnit){\r
- alreadyExistingSpecimens.add(new UnitIdSpecimen(unitId, derivedUnit));\r
- }\r
-\r
- public void addException(String message, Exception e) {\r
- StringWriter errors = new StringWriter();\r
- e.printStackTrace(new PrintWriter(errors));\r
- infoMessages.add(message+"\n"+e.getMessage()+"\n"+errors.toString());\r
- }\r
-\r
- public void addInfoMessage(String message) {\r
- infoMessages.add(message);\r
- }\r
-\r
- public void printReport(URI reportUri) {\r
- PrintStream out;\r
- if(reportUri != null){\r
- try {\r
- out = new PrintStream(new File(reportUri));\r
- } catch (FileNotFoundException e) {\r
- logger.warn("Report file could not be found.");\r
- out = System.out;\r
- }\r
- }\r
- else{\r
- out = System.out;\r
- }\r
- printReport(out);\r
- }\r
-\r
-\r
- public void printReport(PrintStream out) {\r
-\r
- out.println("++++++++Import Report+++++++++");\r
- //all specimens\r
- Set<UnitIdSpecimen> allSpecimens = new HashSet<UnitIdSpecimen>();\r
- for (Entry<UnitIdSpecimen, List<UnitIdSpecimen>> entry : derivateMap.entrySet()) {\r
- UnitIdSpecimen parentSpecimen = entry.getKey();\r
- allSpecimens.add(parentSpecimen);\r
- for (UnitIdSpecimen childSpecimen : entry.getValue()) {\r
- allSpecimens.add(childSpecimen);\r
- }\r
- }\r
- out.println("Specimens created: "+allSpecimens.size());\r
- Map<SpecimenOrObservationType, Integer> specimenTypeToCount = new HashMap<SpecimenOrObservationType, Integer>();\r
- for (UnitIdSpecimen unitIdSpecimen : allSpecimens) {\r
- incrementSpecimenTypeCount(specimenTypeToCount, unitIdSpecimen);\r
- }\r
- for(Entry<SpecimenOrObservationType, Integer> entry:specimenTypeToCount.entrySet()){\r
- SpecimenOrObservationType type = entry.getKey();\r
- out.println(type+": "+entry.getValue());\r
- }\r
- out.println("\n");\r
-\r
- //taxon name\r
- out.println("---Created Taxon Names ("+createdNames.size()+")---");\r
- for (TaxonNameBase<?, ?> taxonName : createdNames) {\r
- out.println(taxonName.getTitleCache());\r
- }\r
- out.println("\n");\r
-\r
- //taxa\r
- out.println("---Created Taxa ("+createdTaxa.size()+")---");\r
- for (Taxon taxon : createdTaxa) {\r
- out.println(taxon.getTitleCache());\r
- }\r
- out.println("\n");\r
-\r
- //taxon nodes\r
- out.println("---Created Taxon Nodes ("+createdTaxonNodes.size()+")---");\r
- for (TaxonNode taxonNode : createdTaxonNodes) {\r
- String nodeString = taxonNode.toString();\r
- if(taxonNode.getTaxon()!=null){\r
- nodeString += " ("+taxonNode.getTaxon().getTitleCache()+")";\r
- }\r
- if(taxonNode.getParent()!=null){\r
- nodeString += " with parent "+taxonNode.getParent();\r
- if(taxonNode.getParent().getTaxon()!=null){\r
- nodeString += " ("+taxonNode.getParent().getTaxon().getTitleCache()+")";\r
- }\r
- }\r
- out.println(nodeString);\r
- }\r
- out.println("\n");\r
-\r
- //not imported\r
- out.println("---Already existing specimen (not imported)---");\r
- for(UnitIdSpecimen specimen:alreadyExistingSpecimens){\r
- out.println(formatSpecimen(specimen));\r
- }\r
- out.println("\n");\r
-\r
- //taxa with associated specimens\r
- out.println("---Taxa with associated specimens---");\r
- for(Entry<Taxon, List<UnitIdSpecimen>> entry:taxonToAssociatedSpecimens.entrySet()){\r
- Taxon taxon = entry.getKey();\r
- List<UnitIdSpecimen> specimens = entry.getValue();\r
- out.println(taxon.getTitleCache() + " ("+specimens.size()+")");\r
- for (UnitIdSpecimen derivedUnit : specimens) {\r
- out.println("\t- "+formatSpecimen(derivedUnit));\r
- //check for derivatives\r
- List<UnitIdSpecimen> list = derivateMap.get(derivedUnit);\r
- for (UnitIdSpecimen derivate : list) {\r
- out.println("\t\t- "+formatSpecimen(derivate));\r
- }\r
- }\r
- }\r
- out.println("\n");\r
- out.println("\n");\r
- //info messages\r
- out.println("---Info messages---");\r
- for(String message:infoMessages){\r
- out.println(message);\r
- out.println("---");\r
- }\r
- if(out!=System.out){\r
- out.close();\r
- }\r
- }\r
-\r
- private void incrementSpecimenTypeCount(Map<SpecimenOrObservationType, Integer> specimenTypeToCount,\r
- UnitIdSpecimen specimen) {\r
- SpecimenOrObservationType specimenType = specimen.getSpecimen().getRecordBasis();\r
- Integer count = specimenTypeToCount.get(specimenType);\r
- if(count==null){\r
- count = 1;\r
- }\r
- else{\r
- count++;\r
- }\r
- specimenTypeToCount.put(specimenType, count);\r
- }\r
-\r
- private String formatSpecimen(UnitIdSpecimen specimen){\r
- return "("+specimen.getUnitId()+") ["+specimen.getSpecimen().getRecordBasis()+"] "+specimen.getSpecimen().getTitleCache();\r
- }\r
-\r
- private class UnitIdSpecimen{\r
- private final String unitId;\r
- private final SpecimenOrObservationBase<?> specimen;\r
-\r
-\r
- public UnitIdSpecimen(String unitId, SpecimenOrObservationBase<?> specimen) {\r
- super();\r
- this.unitId = unitId;\r
- this.specimen = specimen;\r
- }\r
- public String getUnitId() {\r
- return unitId;\r
- }\r
- public SpecimenOrObservationBase<?> getSpecimen() {\r
- return specimen;\r
- }\r
- @Override\r
- public int hashCode() {\r
- final int prime = 31;\r
- int result = 1;\r
- result = prime * result + ((specimen == null) ? 0 : specimen.hashCode());\r
- result = prime * result + ((unitId == null) ? 0 : unitId.hashCode());\r
- return result;\r
- }\r
- @Override\r
- public boolean equals(Object obj) {\r
- if (this == obj) {\r
- return true;\r
- }\r
- if (obj == null) {\r
- return false;\r
- }\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
- UnitIdSpecimen other = (UnitIdSpecimen) obj;\r
- if (specimen == null) {\r
- if (other.specimen != null) {\r
- return false;\r
- }\r
- } else if (!specimen.equals(other.specimen)) {\r
- return false;\r
- }\r
- if (unitId == null) {\r
- if (other.unitId != null) {\r
- return false;\r
- }\r
- } else if (!unitId.equals(other.unitId)) {\r
- return false;\r
- }\r
- return true;\r
- }\r
-\r
- }\r
-\r
-}\r
+// $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.File;
+import java.io.FileNotFoundException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+
+/**
+ * Gathers information about the ABCD import and presents them in a suitable way.
+ * @author pplitzner
+ * @date Jan 23, 2015
+ *
+ */
+public class SpecimenImportReport {
+
+ static private final Logger logger = Logger.getLogger(SpecimenImportReport.class);
+
+
+ private final List<Taxon> createdTaxa = new ArrayList<Taxon>();
+ private final Map<Taxon, List<UnitIdSpecimen>> taxonToAssociatedSpecimens = new HashMap<Taxon, List<UnitIdSpecimen>>();
+ private final Map<UnitIdSpecimen, List<UnitIdSpecimen>> derivateMap = new HashMap<UnitIdSpecimen, List<UnitIdSpecimen>>();
+ private final List<UnitIdSpecimen> alreadyExistingSpecimens = new ArrayList<UnitIdSpecimen>();
+ private final List<TaxonNameBase<?, ?>> createdNames = new ArrayList<TaxonNameBase<?,?>>();
+ private final List<TaxonNode> createdTaxonNodes = new ArrayList<TaxonNode>();
+ private final List<String> infoMessages = new ArrayList<String>();
+
+ public void addTaxon(Taxon taxon){
+ createdTaxa.add(taxon);
+ }
+
+ public void addName(TaxonNameBase<?, ?> taxonName){
+ createdNames.add(taxonName);
+ }
+
+ public void addTaxonNode(TaxonNode taxonNode){
+ createdTaxonNodes.add(taxonNode);
+ }
+
+ public void addDerivate(DerivedUnit parent, Abcd206ImportConfigurator config){
+ addDerivate(parent, null, config);
+ }
+
+ public void addDerivate(DerivedUnit parent, DerivedUnit child, Abcd206ImportConfigurator config){
+ 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(SpecimenImportUtility.getUnitID(child, config), child));
+ }
+ derivateMap.put(parentUnitIdSpecimen, children);
+ }
+
+ public void addIndividualAssociation(Taxon taxon, String derivedUnitId, DerivedUnit derivedUnitBase) {
+ UnitIdSpecimen derivedUnitIdSpecimen = new UnitIdSpecimen(derivedUnitId, derivedUnitBase);
+ List<UnitIdSpecimen> associatedSpecimens = taxonToAssociatedSpecimens.get(taxon);
+ if(associatedSpecimens==null){
+ associatedSpecimens = new ArrayList<UnitIdSpecimen>();
+ }
+ associatedSpecimens.add(derivedUnitIdSpecimen);
+ taxonToAssociatedSpecimens.put(taxon, associatedSpecimens);
+ }
+
+ public void addAlreadyExistingSpecimen(String unitId, DerivedUnit derivedUnit){
+ alreadyExistingSpecimens.add(new UnitIdSpecimen(unitId, derivedUnit));
+ }
+
+ 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());
+ }
+
+ public void addInfoMessage(String message) {
+ infoMessages.add(message);
+ }
+
+ public void printReport(URI reportUri) {
+ PrintStream out;
+ if(reportUri != null){
+ try {
+ out = new PrintStream(new File(reportUri));
+ } catch (FileNotFoundException e) {
+ logger.warn("Report file could not be found.");
+ out = System.out;
+ }
+ }
+ else{
+ out = System.out;
+ }
+ printReport(out);
+ }
+
+
+ public void printReport(PrintStream out) {
+
+ out.println("++++++++Import Report+++++++++");
+ //all specimens
+ Set<UnitIdSpecimen> allSpecimens = new HashSet<UnitIdSpecimen>();
+ for (Entry<UnitIdSpecimen, List<UnitIdSpecimen>> entry : derivateMap.entrySet()) {
+ UnitIdSpecimen parentSpecimen = entry.getKey();
+ allSpecimens.add(parentSpecimen);
+ for (UnitIdSpecimen childSpecimen : entry.getValue()) {
+ allSpecimens.add(childSpecimen);
+ }
+ }
+ out.println("Specimens created: "+allSpecimens.size());
+ Map<SpecimenOrObservationType, Integer> specimenTypeToCount = new HashMap<SpecimenOrObservationType, Integer>();
+ for (UnitIdSpecimen unitIdSpecimen : allSpecimens) {
+ incrementSpecimenTypeCount(specimenTypeToCount, unitIdSpecimen);
+ }
+ for(Entry<SpecimenOrObservationType, Integer> entry:specimenTypeToCount.entrySet()){
+ SpecimenOrObservationType type = entry.getKey();
+ out.println(type+": "+entry.getValue());
+ }
+ out.println("\n");
+
+ //taxon name
+ out.println("---Created Taxon Names ("+createdNames.size()+")---");
+ for (TaxonNameBase<?, ?> taxonName : createdNames) {
+ out.println(taxonName.getTitleCache());
+ }
+ out.println("\n");
+
+ //taxa
+ out.println("---Created Taxa ("+createdTaxa.size()+")---");
+ for (Taxon taxon : createdTaxa) {
+ out.println(taxon.getTitleCache());
+ }
+ out.println("\n");
+
+ //taxon nodes
+ out.println("---Created Taxon Nodes ("+createdTaxonNodes.size()+")---");
+ for (TaxonNode taxonNode : createdTaxonNodes) {
+ String nodeString = taxonNode.toString();
+ if(taxonNode.getTaxon()!=null){
+ nodeString += " ("+taxonNode.getTaxon().getTitleCache()+")";
+ }
+ if(taxonNode.getParent()!=null){
+ nodeString += " with parent "+taxonNode.getParent();
+ if(taxonNode.getParent().getTaxon()!=null){
+ nodeString += " ("+taxonNode.getParent().getTaxon().getTitleCache()+")";
+ }
+ }
+ out.println(nodeString);
+ }
+ out.println("\n");
+
+ //not imported
+ out.println("---Already existing specimen (not imported)---");
+ for(UnitIdSpecimen specimen:alreadyExistingSpecimens){
+ out.println(formatSpecimen(specimen));
+ }
+ out.println("\n");
+
+ //taxa with associated specimens
+ out.println("---Taxa with associated specimens---");
+ for(Entry<Taxon, List<UnitIdSpecimen>> entry:taxonToAssociatedSpecimens.entrySet()){
+ Taxon taxon = entry.getKey();
+ List<UnitIdSpecimen> specimens = entry.getValue();
+ out.println(taxon.getTitleCache() + " ("+specimens.size()+")");
+ for (UnitIdSpecimen derivedUnit : specimens) {
+ out.println("\t- "+formatSpecimen(derivedUnit));
+ //check for derivatives
+ List<UnitIdSpecimen> list = derivateMap.get(derivedUnit);
+ for (UnitIdSpecimen derivate : list) {
+ out.println("\t\t- "+formatSpecimen(derivate));
+ }
+ }
+ }
+ out.println("\n");
+ out.println("\n");
+ //info messages
+ out.println("---Info messages---");
+ for(String message:infoMessages){
+ out.println(message);
+ out.println("---");
+ }
+ if(out!=System.out){
+ out.close();
+ }
+ }
+
+ private void incrementSpecimenTypeCount(Map<SpecimenOrObservationType, Integer> specimenTypeToCount,
+ UnitIdSpecimen specimen) {
+ SpecimenOrObservationType specimenType = specimen.getSpecimen().getRecordBasis();
+ Integer count = specimenTypeToCount.get(specimenType);
+ if(count==null){
+ count = 1;
+ }
+ else{
+ count++;
+ }
+ specimenTypeToCount.put(specimenType, count);
+ }
+
+ private String formatSpecimen(UnitIdSpecimen specimen){
+ return "("+specimen.getUnitId()+") ["+specimen.getSpecimen().getRecordBasis()+"] "+specimen.getSpecimen().getTitleCache();
+ }
+
+ private class UnitIdSpecimen{
+ private final String unitId;
+ private final SpecimenOrObservationBase<?> specimen;
+
+
+ public UnitIdSpecimen(String unitId, SpecimenOrObservationBase<?> specimen) {
+ super();
+ this.unitId = unitId;
+ this.specimen = specimen;
+ }
+ public String getUnitId() {
+ return unitId;
+ }
+ public SpecimenOrObservationBase<?> getSpecimen() {
+ return specimen;
+ }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((specimen == null) ? 0 : specimen.hashCode());
+ result = prime * result + ((unitId == null) ? 0 : unitId.hashCode());
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ UnitIdSpecimen other = (UnitIdSpecimen) obj;
+ if (specimen == null) {
+ if (other.specimen != null) {
+ return false;
+ }
+ } else if (!specimen.equals(other.specimen)) {
+ return false;
+ }
+ if (unitId == null) {
+ if (other.unitId != null) {
+ return false;
+ }
+ } else if (!unitId.equals(other.unitId)) {
+ return false;
+ }
+ return true;
+ }
+
+ }
+
+}
-// $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.io.specimen.SpecimenImportConfiguratorBase;\r
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;\r
-\r
-/**\r
- * @author pplitzner\r
- * @date 16.06.2015\r
- *\r
- */\r
-public class SpecimenImportUtility {\r
-\r
- public static String getUnitID(DerivedUnit derivedUnit, SpecimenImportConfiguratorBase config){\r
- if (config instanceof Abcd206ImportConfigurator){\r
- if(((Abcd206ImportConfigurator)config).isMapUnitIdToAccessionNumber()){\r
- return derivedUnit.getAccessionNumber();\r
- }\r
- if(((Abcd206ImportConfigurator)config).isMapUnitIdToBarcode()){\r
- return derivedUnit.getBarcode();\r
- }\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
+// $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.io.specimen.SpecimenImportConfiguratorBase;
+import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
+
+/**
+ * @author pplitzner
+ * @date 16.06.2015
+ *
+ */
+public class SpecimenImportUtility {
+
+ public static String getUnitID(DerivedUnit derivedUnit, SpecimenImportConfiguratorBase config){
+ if (config instanceof Abcd206ImportConfigurator){
+ if(((Abcd206ImportConfigurator)config).isMapUnitIdToAccessionNumber()){
+ return derivedUnit.getAccessionNumber();
+ }
+ if(((Abcd206ImportConfigurator)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 java.io.IOException;\r
-import java.io.InputStream;\r
-import java.net.URI;\r
-import java.util.HashSet;\r
-import java.util.Set;\r
-\r
-import org.apache.http.client.ClientProtocolException;\r
-import org.apache.log4j.Logger;\r
-import org.w3c.dom.Element;\r
-\r
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
-import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;\r
-import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;\r
-\r
-/**\r
- * @author pplitzner\r
- * @date 16.06.2015\r
- *\r
- */\r
-public class UnitAssociationParser {\r
-\r
- private static final Logger logger = Logger.getLogger(UnitAssociationParser.class);\r
-\r
- private final String prefix;\r
-\r
- private final SpecimenImportReport report;\r
-\r
- private final ICdmApplicationConfiguration cdmAppController;\r
-\r
- public UnitAssociationParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {\r
- this.prefix = prefix;\r
- this.report = report;\r
- this.cdmAppController = cdmAppController;\r
- }\r
-\r
- public UnitAssociationWrapper parse(Element unitAssociation){\r
- if(prefix.equals("abcd:")){\r
-\r
- }\r
- else if(prefix.equals("abcd21:")){\r
-\r
- }\r
- //unit id\r
- String unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"UnitID"));\r
- if(unitId==null){\r
- unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitID"));//abcd 2.0.6\r
- }\r
- //institution code\r
- String institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceInstitutionCode"));\r
- if(institutionCode==null){\r
- institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceInstitutionCode"));//abcd 2.0.6\r
- }\r
- //institution name\r
- String institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceName"));\r
- if(institutionName==null){\r
- institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceName"));//abcd 2.0.6\r
- }\r
- //data access point\r
- URI datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"DatasetAccessPoint"), report);\r
- if(datasetAccessPoint==null){\r
- datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"Comment"), report);//abcd 2.0.6\r
- }\r
- //association type\r
- String associationType = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociationType"));\r
-\r
- String unableToLoadMessage = String.format("Unable to load unit %s from %s", unitId, datasetAccessPoint);\r
- if(unitId!=null && datasetAccessPoint!=null){\r
- BioCaseQueryServiceWrapper serviceWrapper = new BioCaseQueryServiceWrapper();\r
- Set<String[]> unitIds = new HashSet<String[]>();\r
- String[] unitIdArray = {unitId};\r
- unitIds.add(unitIdArray);\r
- OccurenceQuery query = new OccurenceQuery(unitIds);\r
- try {\r
- InputStream inputStream = serviceWrapper.query(query, datasetAccessPoint);\r
- if(inputStream!=null){\r
- UnitAssociationWrapper unitAssociationWrapper = null;\r
- try {\r
- unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(inputStream, report);\r
- } catch (Exception e) {\r
- String exceptionMessage = "An exception occurred during parsing of associated units!";\r
- logger.error(exceptionMessage, e);\r
- report.addException(exceptionMessage, e);\r
- }\r
-\r
- if(unitAssociationWrapper!=null){\r
- unitAssociationWrapper.setAssociationType(associationType);\r
- if(unitAssociationWrapper.getAssociatedUnits()!=null && unitAssociationWrapper.getAssociatedUnits().getLength()>1){\r
- String moreThanOneUnitFoundMessage = String.format("More than one unit was found for unit association to %s", unitId);\r
- logger.warn(moreThanOneUnitFoundMessage);\r
- report.addInfoMessage(moreThanOneUnitFoundMessage);\r
- }\r
- }\r
- return unitAssociationWrapper;\r
- }\r
- else{\r
- logger.error(unableToLoadMessage);\r
- report.addInfoMessage(unableToLoadMessage);\r
- }\r
- } catch (ClientProtocolException e) {\r
- logger.error(unableToLoadMessage, e);\r
- report.addInfoMessage(unableToLoadMessage);\r
- } catch (IOException e) {\r
- logger.error(unableToLoadMessage, e);\r
- report.addInfoMessage(unableToLoadMessage);\r
- }\r
- }\r
- else{\r
- report.addInfoMessage(unableToLoadMessage);\r
- }\r
- return null;\r
- }\r
-\r
-}\r
+// $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.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.http.client.ClientProtocolException;
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
+import eu.etaxonomy.cdm.ext.occurrence.bioCase.BioCaseQueryServiceWrapper;
+
+/**
+ * @author pplitzner
+ * @date 16.06.2015
+ *
+ */
+public class UnitAssociationParser {
+
+ private static final Logger logger = Logger.getLogger(UnitAssociationParser.class);
+
+ private final String prefix;
+
+ private final SpecimenImportReport report;
+
+ private final ICdmApplicationConfiguration cdmAppController;
+
+ public UnitAssociationParser(String prefix, SpecimenImportReport report, ICdmApplicationConfiguration cdmAppController) {
+ this.prefix = prefix;
+ this.report = report;
+ this.cdmAppController = cdmAppController;
+ }
+
+ public UnitAssociationWrapper parse(Element unitAssociation){
+ if(prefix.equals("abcd:")){
+
+ }
+ else if(prefix.equals("abcd21:")){
+
+ }
+ //unit id
+ String unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"UnitID"));
+ if(unitId==null){
+ unitId = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitID"));//abcd 2.0.6
+ }
+ //institution code
+ String institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceInstitutionCode"));
+ if(institutionCode==null){
+ institutionCode = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceInstitutionCode"));//abcd 2.0.6
+ }
+ //institution name
+ String institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"SourceName"));
+ if(institutionName==null){
+ institutionName = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociatedUnitSourceName"));//abcd 2.0.6
+ }
+ //data access point
+ URI datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"DatasetAccessPoint"), report);
+ if(datasetAccessPoint==null){
+ datasetAccessPoint = AbcdParseUtility.parseFirstUri(unitAssociation.getElementsByTagName(prefix+"Comment"), report);//abcd 2.0.6
+ }
+ //association type
+ String associationType = AbcdParseUtility.parseFirstTextContent(unitAssociation.getElementsByTagName(prefix+"AssociationType"));
+
+ String unableToLoadMessage = String.format("Unable to load unit %s from %s", unitId, datasetAccessPoint);
+ if(unitId!=null && datasetAccessPoint!=null){
+ BioCaseQueryServiceWrapper serviceWrapper = new BioCaseQueryServiceWrapper();
+ Set<String[]> unitIds = new HashSet<String[]>();
+ String[] unitIdArray = {unitId};
+ unitIds.add(unitIdArray);
+ OccurenceQuery query = new OccurenceQuery(unitIds);
+ try {
+ InputStream inputStream = serviceWrapper.query(query, datasetAccessPoint);
+ if(inputStream!=null){
+ UnitAssociationWrapper unitAssociationWrapper = null;
+ try {
+ unitAssociationWrapper = AbcdParseUtility.parseUnitsNodeList(inputStream, report);
+ } catch (Exception e) {
+ String exceptionMessage = "An exception occurred during parsing of associated units!";
+ logger.error(exceptionMessage, e);
+ report.addException(exceptionMessage, e);
+ }
+
+ if(unitAssociationWrapper!=null){
+ unitAssociationWrapper.setAssociationType(associationType);
+ if(unitAssociationWrapper.getAssociatedUnits()!=null && unitAssociationWrapper.getAssociatedUnits().getLength()>1){
+ String moreThanOneUnitFoundMessage = String.format("More than one unit was found for unit association to %s", unitId);
+ logger.warn(moreThanOneUnitFoundMessage);
+ report.addInfoMessage(moreThanOneUnitFoundMessage);
+ }
+ }
+ return unitAssociationWrapper;
+ }
+ else{
+ logger.error(unableToLoadMessage);
+ report.addInfoMessage(unableToLoadMessage);
+ }
+ } catch (ClientProtocolException e) {
+ logger.error(unableToLoadMessage, e);
+ report.addInfoMessage(unableToLoadMessage);
+ } catch (IOException e) {
+ logger.error(unableToLoadMessage, e);
+ report.addInfoMessage(unableToLoadMessage);
+ }
+ }
+ else{
+ report.addInfoMessage(unableToLoadMessage);
+ }
+ return null;
+ }
+
+}
-// $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
+// $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.Abcd206ImportState;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdPersonParser;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
+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 SpecimenImportReport report;
+
+ private final ICdmApplicationConfiguration cdmAppController;
+
+ public AbcdDnaParser(String prefix, SpecimenImportReport 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.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
+// $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.Abcd206ImportState;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.AbcdParseUtility;
+import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
+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 SpecimenImportReport report;
+
+ private final ICdmApplicationConfiguration cdmAppController;
+
+ public AbcdGgbnParser(SpecimenImportReport 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) 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
+// $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;
+ }
+
+
+
+
+}
-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
+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
+ *
+ */
+
+
+
+}
-// $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
+// $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.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
+// $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 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
+// $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
+
+ }
+
+}