-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.cdm.io.specimen.abcd206.in;
-
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
-
-/**
- * @author pplitzner
- * @date 16.06.2015
- *
- */
-public class AbcdImportUtility {
-
- public static String getUnitID(DerivedUnit derivedUnit, Abcd206ImportConfigurator config){
- if(config.isMapUnitIdToAccessionNumber()){
- return derivedUnit.getAccessionNumber();
- }
- if(config.isMapUnitIdToBarcode()){
- return derivedUnit.getBarcode();
- }
- return derivedUnit.getCatalogNumber();
- }
-
- public static void setUnitID(DerivedUnit derivedUnit, String unitId, Abcd206ImportConfigurator config){
- if(config.isMapUnitIdToCatalogNumber()
- || !(config.isMapUnitIdToAccessionNumber() || config.isMapUnitIdToBarcode() || config.isMapUnitIdToCatalogNumber())){
- // set catalog number (default if nothing is set)
- derivedUnit.setCatalogNumber(unitId);
- }
- if(config.isMapUnitIdToAccessionNumber()){
- derivedUnit.setAccessionNumber(unitId);
- }
- if(config.isMapUnitIdToBarcode()){
- derivedUnit.setBarcode(unitId);
- }
- }
-
-}
+// $Id$\r
+/**\r
+* Copyright (C) 2015 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
+package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
+\r
+import eu.etaxonomy.cdm.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 java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-
-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 Abcd206ImportReport report;
-
- private final ICdmApplicationConfiguration cdmAppController;
-
- public UnitAssociationParser(String prefix, Abcd206ImportReport 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();
- OccurenceQuery query = new OccurenceQuery(unitId);
- 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;\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