ref #9041 first incomplete version for AltitudeExcelImport
authorAndreas Müller <a.mueller@bgbm.org>
Tue, 2 Jun 2020 07:40:37 +0000 (09:40 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Tue, 2 Jun 2020 07:40:37 +0000 (09:40 +0200)
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/excel/common/ExcelImportBase.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImport.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportConfigurator.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportRow.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportState.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportBase.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportConfiguratorBase.java [new file with mode: 0644]
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportStateBase.java [new file with mode: 0644]

index 00e73259ee1928d814e73dc643ab102ecc89c050..16525094c01af7072c0c89932b93a76dea66fe62 100755 (executable)
@@ -249,6 +249,9 @@ public abstract class ExcelImportBase<STATE extends ExcelImportState<CONFIG, ROW
         }
     }
 
+    protected String getValue(STATE state, String key){
+        return getValue(state.getOriginalRecord(), key);
+    }
 
     /**
      * Returns the taxon for the given CDM uuid. If no taxon exists for the given id
@@ -271,7 +274,7 @@ public abstract class ExcelImportBase<STATE extends ExcelImportState<CONFIG, ROW
             String colNameCache, String colNameTitleCache, String colTaxonTitleCache,
             Class<T> clazz, String line) {
 
-        Map<String, String> record = state.getOriginalRecord();
+        Map<String, String> record = getRecord(state);
         String strUuidTaxon = record.get(colTaxonUuid);
         if (strUuidTaxon != null){
             UUID uuidTaxon;
@@ -305,6 +308,11 @@ public abstract class ExcelImportBase<STATE extends ExcelImportState<CONFIG, ROW
         }
     }
 
+    protected Map<String, String> getRecord(STATE state) {
+        Map<String, String> record = state.getOriginalRecord();
+        return record;
+    }
+
 
     /**
      * @see #getTaxonByCdmId(ExcelImportState, String, String, String, String, Class, String)
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImport.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImport.java
new file mode 100644 (file)
index 0000000..795d1e2
--- /dev/null
@@ -0,0 +1,76 @@
+/**
+* Copyright (C) 2017 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.fact.altitude.in;
+
+import java.math.BigDecimal;
+import java.util.UUID;
+
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
+import eu.etaxonomy.cdm.io.fact.in.FactExcelImportBase;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.QuantitativeData;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+
+/**
+ *
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+@Component
+public class AltitudeExcelImport
+        extends FactExcelImportBase<AltitudeExcelImportState, AltitudeExcelImportConfigurator, ExcelRowBase>{
+
+    private static final long serialVersionUID = 8264900898340386516L;
+
+    private static final String COL_ALTITUDE_MIN = "Altitude min";
+    private static final String COL_ALTITUDE_MAX = "Altitude max";
+
+
+    @Override
+    protected void doFirstPass(AltitudeExcelImportState state, Taxon taxon,
+            String line, String linePure){
+
+        if (taxon == null){
+            return;
+        }
+
+        UUID uuid = Feature.uuidAltitude;
+        String featureLabel = "Altitude";
+        Feature feature = getFeature(state, uuid, featureLabel, featureLabel, null, null);
+
+        String minStr = getValue(state, COL_ALTITUDE_MIN);
+        String maxStr = getValue(state, COL_ALTITUDE_MAX);
+
+        BigDecimal min = new BigDecimal(minStr);
+        BigDecimal max = new BigDecimal(maxStr);
+
+        //source
+        String id = null;
+        String idNamespace = null;
+        Reference reference = getSourceReference(state);
+
+
+        QuantitativeData qd = QuantitativeData.NewMinMaxInstance(feature, min, max);
+
+        TaxonDescription taxonDescription = this.getTaxonDescription(taxon, reference, !IMAGE_GALLERY, true);
+        taxonDescription.addElement(qd);
+        qd.addImportSource(id, idNamespace, reference, linePure);
+
+    }
+
+    @Override
+    protected boolean isIgnore(AltitudeExcelImportState state) {
+        return false;
+    }
+
+}
\ No newline at end of file
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportConfigurator.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportConfigurator.java
new file mode 100644 (file)
index 0000000..69d1c9c
--- /dev/null
@@ -0,0 +1,70 @@
+/**
+* Copyright (C) 2017 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.fact.altitude.in;
+
+import java.net.URI;
+import java.util.UUID;
+
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
+import eu.etaxonomy.cdm.io.fact.in.FactExcelImportConfiguratorBase;
+
+/**
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public class AltitudeExcelImportConfigurator
+        extends FactExcelImportConfiguratorBase{
+
+    private static final long serialVersionUID = -6403743396163163359L;
+
+    private UUID featureUuid;
+
+    public static AltitudeExcelImportConfigurator NewInstance(URI uri, ICdmDataSource destination){
+        return new AltitudeExcelImportConfigurator(uri, destination, null);
+    }
+
+    /**
+     * How to fill the media title if not explicit value is given.
+     */
+    public enum MediaTitleEnum{
+        NONE,
+        NAME_CACHE,  //use name cache
+        NAME_TITLE_CACHE,  //use name title cache
+        TAXON_TITLE_CACHE,   //use taxon title
+        FILE_NAME    //use file name
+    }
+
+    private AltitudeExcelImportConfigurator(URI uri, ICdmDataSource destination, IInputTransformer transformer) {
+        super(uri, destination, transformer);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    public AltitudeExcelImportState getNewState() {
+        return new AltitudeExcelImportState(this);
+    }
+
+    @SuppressWarnings("unchecked")
+    @Override
+    protected void makeIoClassList() {
+        ioClassList = new Class[]{
+                AltitudeExcelImport.class,
+        };
+    }
+
+    public UUID getFeatureUuid() {
+        return featureUuid;
+    }
+
+    public void setFeatureUuid(UUID featureUuid) {
+        this.featureUuid = featureUuid;
+    }
+
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportRow.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportRow.java
new file mode 100644 (file)
index 0000000..12f832a
--- /dev/null
@@ -0,0 +1,26 @@
+/**
+* Copyright (C) 2017 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.fact.altitude.in;
+
+import java.util.UUID;
+
+/**
+ * Data holder class for altitude import for taxa.
+ *
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public class AltitudeExcelImportRow {
+    private UUID taxonUuid;
+    private String fullTaxonName;
+    private String fileName;
+    private String copyright;
+    private String artist;
+
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportState.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/altitude/in/AltitudeExcelImportState.java
new file mode 100644 (file)
index 0000000..abaac62
--- /dev/null
@@ -0,0 +1,23 @@
+/**
+* Copyright (C) 2017 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.fact.altitude.in;
+
+import eu.etaxonomy.cdm.io.fact.in.FactExcelImportStateBase;
+
+/**
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public class AltitudeExcelImportState
+        extends FactExcelImportStateBase<AltitudeExcelImportConfigurator>{
+
+    public AltitudeExcelImportState(AltitudeExcelImportConfigurator config) {
+        super(config);
+    }
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportBase.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportBase.java
new file mode 100644 (file)
index 0000000..a127771
--- /dev/null
@@ -0,0 +1,57 @@
+/**
+* Copyright (C) 2020 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.fact.in;
+
+import java.util.Map;
+
+import eu.etaxonomy.cdm.io.excel.common.ExcelImportBase;
+import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+
+/**
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public abstract class FactExcelImportBase<STATE extends FactExcelImportStateBase<CONFIG>, CONFIG extends FactExcelImportConfiguratorBase, ROW extends ExcelRowBase>
+        extends ExcelImportBase<STATE, CONFIG, ExcelRowBase>{
+
+    private static final long serialVersionUID = 2233954525898978414L;
+
+    protected static final String COL_TAXON_UUID = "taxonUuid";
+    protected static final String COL_NAME_CACHE = "nameCache";
+    protected static final String COL_NAME_TITLE = "nameTitle";
+    protected static final String COL_TAXON_TITLE = "taxonTitle";
+
+    @Override
+    protected void analyzeRecord(Map<String, String> record, STATE state) {
+        // do nothing
+    }
+
+    @Override
+    protected void firstPass(STATE state) {
+        Map<String, String> record = state.getOriginalRecord();
+        String line = "row " + state.getCurrentLine() + ": ";
+        String linePure = "row " + state.getCurrentLine();
+        System.out.println(linePure);
+
+        //taxon
+        Taxon taxon = getTaxonByCdmId(state, COL_TAXON_UUID,
+                COL_NAME_CACHE, COL_NAME_TITLE, COL_TAXON_TITLE,
+                Taxon.class, linePure);
+
+        doFirstPass(state, taxon, line, linePure);
+    }
+
+    protected abstract void doFirstPass(STATE state, Taxon taxon, String line, String linePure);
+
+    @Override
+    protected void secondPass(STATE state) {
+        //override if necessary
+    }
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportConfiguratorBase.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportConfiguratorBase.java
new file mode 100644 (file)
index 0000000..edc54a0
--- /dev/null
@@ -0,0 +1,32 @@
+/**
+* Copyright (C) 2020 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.fact.in;
+
+import java.net.URI;
+
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
+import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
+
+/**
+ * Configurator base class for taxon fact excel imports.
+ *
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public abstract class FactExcelImportConfiguratorBase
+        extends ExcelImportConfiguratorBase{
+
+    private static final long serialVersionUID = 1649010514975388511L;
+
+    protected FactExcelImportConfiguratorBase(URI uri, ICdmDataSource destination, IInputTransformer transformer) {
+        super(uri, destination, transformer);
+    }
+
+}
diff --git a/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportStateBase.java b/cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/fact/in/FactExcelImportStateBase.java
new file mode 100644 (file)
index 0000000..acdbee7
--- /dev/null
@@ -0,0 +1,24 @@
+/**
+* Copyright (C) 2020 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.fact.in;
+
+import eu.etaxonomy.cdm.io.excel.common.ExcelImportState;
+import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
+
+/**
+ * @author a.mueller
+ * @since 28.05.2020
+ */
+public abstract class FactExcelImportStateBase<CONFIG extends FactExcelImportConfiguratorBase>
+        extends ExcelImportState<CONFIG, ExcelRowBase>{
+
+    public FactExcelImportStateBase(CONFIG config) {
+        super(config);
+    }
+}