cleanup
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / specimen / abcd206 / in / Abcd206ImportConfigurator.java
index 20411946723c7c4d3dd2cab0d8f3c56c1c71446f..4930fbd6741e253adb52c43c2342d6ad84d7ae93 100644 (file)
-/**\r
- * Copyright (C) 2007 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
-package eu.etaxonomy.cdm.io.specimen.abcd206.in;\r
-\r
-\r
-import java.net.URI;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.UUID;\r
-\r
-import org.apache.log4j.Logger;\r
-\r
-import eu.etaxonomy.cdm.database.ICdmDataSource;\r
-import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
-import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;\r
-import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;\r
-import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
-import eu.etaxonomy.cdm.model.agent.Person;\r
-import eu.etaxonomy.cdm.model.agent.Team;\r
-import eu.etaxonomy.cdm.model.reference.Reference;\r
-import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
-\r
-/**\r
- * @author p.kelbert\r
- * @created 20.10.2008\r
- * @version 1.0\r
- */\r
-public class Abcd206ImportConfigurator extends ImportConfiguratorBase<Abcd206ImportState, URI> implements IImportConfigurator, IMatchingImportConfigurator {\r
-    private static final Logger logger = Logger.getLogger(Abcd206ImportConfigurator.class);\r
-    private boolean doParsing = false;\r
-    private boolean reuseMetadata = false;\r
-    private boolean reuseTaxon = true;\r
-    private String taxonReference = null;\r
-    private boolean doCreateIndividualsAssociations = true;\r
-    private boolean doReuseExistingDescription = false;\r
-    private boolean doMatchTaxa = true;\r
-    private final Map<UUID, UUID> taxonToDescriptionMap = new HashMap<UUID, UUID>();\r
-    private Map<String, Team> titleCacheTeam;\r
-    private Map<String, Person> titleCachePerson;\r
-    private String defaultAuthor="";\r
-\r
-    //TODO\r
-    private static IInputTransformer defaultTransformer = null;\r
-\r
-    @Override\r
-    @SuppressWarnings("unchecked")\r
-    protected void makeIoClassList(){\r
-        System.out.println("makeIOClassList");\r
-        ioClassList = new Class[]{\r
-                Abcd206Import.class,\r
-        };\r
-    };\r
-\r
-    public static Abcd206ImportConfigurator NewInstance(URI uri,\r
-            ICdmDataSource destination){\r
-        return new Abcd206ImportConfigurator(uri, destination);\r
-    }\r
-\r
-\r
-    /**\r
-     * @param berlinModelSource\r
-     * @param sourceReference\r
-     * @param destination\r
-     */\r
-    private Abcd206ImportConfigurator(URI uri, ICdmDataSource destination) {\r
-        super(defaultTransformer);\r
-        setSource(uri);\r
-        setDestination(destination);\r
-    }\r
-\r
-\r
-\r
-\r
-    // /* (non-Javadoc)\r
-    //  * @see eu.etaxonomy.cdm.io.common.ImportConfiguratorBase#getSource()\r
-    //  */\r
-    // public String getSource() {\r
-    //         return (String)super.getSource();\r
-    // }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.cdm.io.common.IImportConfigurator#getNewState()\r
-     */\r
-    @Override\r
-    public Abcd206ImportState getNewState() {\r
-        return new Abcd206ImportState(this);\r
-    }\r
-\r
-\r
-    @Override\r
-    public URI getSource(){\r
-        return super.getSource();\r
-    }\r
-\r
-    /**\r
-     * @param file\r
-     */\r
-    @Override\r
-    public void setSource(URI uri) {\r
-        super.setSource(uri);\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\r
-        if (this.sourceReference == null){\r
-            logger.warn("getSource Reference not yet fully implemented");\r
-            ReferenceFactory refFactory = ReferenceFactory.newInstance();\r
-            sourceReference = refFactory.newDatabase();\r
-            sourceReference.setTitleCache("ABCD specimen import", true);\r
-        }\r
-        return sourceReference;\r
-    }\r
-\r
-    public void setTaxonReference(String taxonReference) {\r
-        this.taxonReference = taxonReference;\r
-    }\r
-\r
-    public Reference getTaxonReference() {\r
-        //TODO\r
-        if (this.taxonReference == null){\r
-            logger.info("getTaxonReference not yet fully implemented");\r
-        }\r
-        return sourceReference;\r
-    }\r
-\r
-    public void setDoAutomaticParsing(boolean doParsing){\r
-        this.doParsing=doParsing;\r
-    }\r
-\r
-    public boolean isDoAutomaticParsing(){\r
-        return this.doParsing;\r
-    }\r
-\r
-    public void setReUseExistingMetadata(boolean reuseMetadata){\r
-        this.reuseMetadata = reuseMetadata;\r
-    }\r
-\r
-    public boolean isReUseExistingMetadata(){\r
-        return this.reuseMetadata;\r
-    }\r
-\r
-    public void setReUseTaxon(boolean reuseTaxon){\r
-        this.reuseTaxon = reuseTaxon;\r
-    }\r
-\r
-    /**\r
-     * if {@link #doMatchTaxa} is set false or no matching taxon is found new\r
-     * taxa will be created. If this flag is set <code>true</code> the newly created taxa\r
-     * will be reused if possible. Setting this flag to <code>false</code> may lead to\r
-     * multiple identical taxa.\r
-     *\r
-     * @return\r
-     */\r
-    public boolean isDoReUseTaxon(){\r
-        return this.reuseTaxon;\r
-    }\r
-\r
-    public void setDoCreateIndividualsAssociations(\r
-            boolean doCreateIndividualsAssociations) {\r
-        this.doCreateIndividualsAssociations = doCreateIndividualsAssociations;\r
-    }\r
-\r
-    /**\r
-     * Create an IndividualsAssociations for each determination element in the ABCD data. ABCD has no such concept as IndividualsAssociations so the only way to\r
-     *\r
-     * @return\r
-     */\r
-    public boolean isDoCreateIndividualsAssociations() {\r
-        return doCreateIndividualsAssociations;\r
-    }\r
-\r
-    /**\r
-     * @param doReuseExistingDescription the doReuseExistingDescription to set\r
-     */\r
-    public void setDoReuseExistingDescription(boolean doReuseExistingDescription) {\r
-        this.doReuseExistingDescription = doReuseExistingDescription;\r
-    }\r
-\r
-    /**\r
-     * @return the doReuseExistingDescription\r
-     */\r
-    public boolean isDoMatchToExistingDescription() {\r
-        return doReuseExistingDescription;\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#isDoMatchTaxa()\r
-     */\r
-    @Override\r
-    public boolean isDoMatchTaxa() {\r
-        return doMatchTaxa;\r
-    }\r
-\r
-    /* (non-Javadoc)\r
-     * @see eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator#setDoMatchTaxa(boolean)\r
-     */\r
-    @Override\r
-    public void setDoMatchTaxa(boolean doMatchTaxa) {\r
-        this.doMatchTaxa = doMatchTaxa;\r
-    }\r
-\r
-    /**\r
-     * @return\r
-     */\r
-    public Map<UUID, UUID> getTaxonToDescriptionMap() {\r
-        // TODO Auto-generated method stub\r
-        return taxonToDescriptionMap ;\r
-    }\r
-\r
-\r
-\r
-    public Map<String, Team> getTeams() {\r
-        return titleCacheTeam;\r
-    }\r
-\r
-    public void setTeams(Map<String, Team> titleCacheTeam) {\r
-        this.titleCacheTeam = titleCacheTeam;\r
-    }\r
-\r
-    public Map<String, Person> getPersons() {\r
-        return titleCachePerson;\r
-    }\r
-\r
-    public void setPersons(Map<String, Person> titleCachePerson) {\r
-        this.titleCachePerson = titleCachePerson;\r
-    }\r
-\r
-    /**\r
-     * @param string\r
-     */\r
-    public void setDefaultAuthor(String string) {\r
-        defaultAuthor=string;\r
-\r
-    }\r
-\r
-    public String getDefaultAuthor(){\r
-        return defaultAuthor;\r
-    }\r
-\r
-\r
-\r
-}\r
+/**
+ * Copyright (C) 2007 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 org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import eu.etaxonomy.cdm.common.URI;
+import eu.etaxonomy.cdm.common.UriUtils;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.IMatchingImportConfigurator;
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
+import eu.etaxonomy.cdm.io.specimen.SpecimenImportConfiguratorBase;
+import eu.etaxonomy.cdm.model.reference.Reference;
+
+/**
+ * @author p.kelbert
+ * @since 20.10.2008
+ */
+public class Abcd206ImportConfigurator
+        extends SpecimenImportConfiguratorBase<Abcd206ImportConfigurator, Abcd206ImportState, InputStream>
+        implements IMatchingImportConfigurator {
+
+    private static final long serialVersionUID = -7204105522522645681L;
+    @SuppressWarnings("unused")
+    private static final Logger logger = LogManager.getLogger();
+
+    //TODO
+    private static IInputTransformer defaultTransformer = null;
+
+    private URI sourceUri;
+
+    private boolean getSiblings = false;
+
+    private URI dnaSoure; // = URI.create("https://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=DNA_Bank");
+
+    @Override
+    @SuppressWarnings("unchecked")
+    protected void makeIoClassList(){
+        System.out.println("makeIOClassList");
+        ioClassList = new Class[]{
+                Abcd206Import.class,
+        };
+    }
+
+    public static Abcd206ImportConfigurator NewInstance(URI uri,ICdmDataSource destination){
+        return new Abcd206ImportConfigurator(null, uri, destination, false);
+    }
+
+    public static Abcd206ImportConfigurator NewInstance(URI uri, ICdmDataSource destination, boolean interact) {
+        return new Abcd206ImportConfigurator(null, uri, destination, interact);
+    }
+
+    private Abcd206ImportConfigurator(InputStream stream, URI uri, ICdmDataSource destination, boolean interact) {
+        super(defaultTransformer);
+        if (stream != null){
+               setSource(stream);
+        }else{
+               this.sourceUri = uri;
+        }
+        setDestination(destination);
+        setSourceReferenceTitle("ABCD classic");
+        setInteractWithUser(interact);
+    }
+
+    @Override
+    public Abcd206ImportState getNewState() {
+        return new Abcd206ImportState(this);
+    }
+
+    @Override
+    public InputStream getSource(){
+        if (super.getSource() != null){
+               return super.getSource();
+        }else if (this.sourceUri != null){
+               try {
+                               InputStream is = UriUtils.getInputStream(sourceUri);
+                               setSource(is);
+                               return is;
+                       } catch (Exception e) {
+                               throw new RuntimeException(e);
+                       }
+        }else{
+               return null;
+        }
+    }
+
+    public URI getSourceUri(){
+       return this.sourceUri;
+    }
+
+    public void setSourceUri(URI sourceUri) {
+        this.sourceUri = sourceUri;
+        super.setSource(null);
+    }
+
+    public URI getDnaSoure() {
+        return dnaSoure;
+    }
+
+    public void setDnaSoure(URI dnaSoure) {
+        this.dnaSoure = dnaSoure;
+    }
+
+    @Override
+    public Reference getSourceReference() {
+        //TODO
+        return sourceReference;
+    }
+
+    public boolean isGetSiblings() {
+        return getSiblings;
+    }
+
+    public void setGetSiblings(boolean getSiblings) {
+        this.getSiblings = getSiblings;
+    }
+
+    @Override
+    public String toString(){
+
+        StringBuffer result = new StringBuffer();
+        //the preference value is build like this:
+        //<section1>:true;<section2>:false....
+
+        result.append("ignoreImportOfExistingSpecimen");
+        result.append(":");
+        result.append(this.isIgnoreImportOfExistingSpecimen());
+        result.append(";");
+        result.append("addIndividualsAssociationsSuchAsSpecimenAndObservations");
+        result.append(":");
+        result.append(this.isAddIndividualsAssociationsSuchAsSpecimenAndObservations());
+        result.append(";");
+        result.append("reuseExistingTaxaWhenPossible");
+        result.append(":");
+        result.append(this.isReuseExistingTaxaWhenPossible());
+        result.append(";");
+        result.append("ignoreAuthorship");
+        result.append(":");
+        result.append(this.isIgnoreAuthorship());
+        result.append(";");
+        result.append("addMediaAsMediaSpecimen");
+        result.append(":");
+        result.append(this.isAddMediaAsMediaSpecimen());
+        result.append(";");
+        result.append("reuseExistingMetaData");
+        result.append(":");
+        result.append(this.isReuseExistingMetaData());
+        result.append(";");
+        result.append("reuseExistingDescriptiveGroups");
+        result.append(":");
+        result.append(this.isReuseExistingDescriptiveGroups());
+        result.append(";");
+        result.append("allowReuseOtherClassifications");
+        result.append(":");
+        result.append(this.isAllowReuseOtherClassifications());
+        result.append(";");
+        result.append("deduplicateReferences");
+        result.append(":");
+        result.append(this.isDeduplicateReferences());
+        result.append(";");
+        result.append("deduplicateClassifications");
+        result.append(":");
+        result.append(this.isDeduplicateClassifications());
+        result.append(";");
+        result.append("moveNewTaxaToDefaultClassification");
+        result.append(":");
+        result.append(this.isMoveNewTaxaToDefaultClassification());
+        result.append(";");
+        result.append("getSiblings");
+        result.append(":");
+        result.append(this.isGetSiblings());
+        result.append(";");
+        result.append("removeCountryFromLocalityText");
+        result.append(":");
+        result.append(this.isRemoveCountryFromLocalityText());
+        result.append(";");
+
+        result.append("mapUnitIdToCatalogNumber");
+        result.append(":");
+        result.append(this.isMapUnitIdToCatalogNumber());
+        result.append(";");
+        result.append("mapUnitIdToAccessionNumber");
+        result.append(":");
+        result.append(this.isMapUnitIdToAccessionNumber());
+        result.append(";");
+        result.append("mapUnitIdToBarcode");
+        result.append(":");
+        result.append(this.isMapUnitIdToBarcode());
+        result.append(";");
+
+        result.append("overwriteExistingSpecimens");
+        result.append(":");
+        result.append(this.isOverwriteExistingSpecimens());
+        result.append(";");
+        result.append("nomenclaturalCode");
+        result.append(":");
+        result.append(this.getNomenclaturalCode() != null ? this.getNomenclaturalCode().getKey():"");
+        result.append(";");
+        result.append("dnaSource");
+        result.append(":");
+        result.append(this.getDnaSoure() != null ? this.getDnaSoure().toString():"");
+        result.append(";");
+        result.append("classificationUUID");
+        result.append(":");
+        result.append(this.getClassificationUuid() != null ? this.getClassificationUuid().toString():"");
+        result.append(";");
+        result.append("classificationName");
+        result.append(":");
+        result.append(this.getClassificationName() != null ? this.getClassificationName():"");
+        result.append(";");
+
+        return result.toString();
+    }
+}
\ No newline at end of file