ref #6619: integrate excel distribution update in taxeditor
authorKatja Luther <k.luther@bgbm.org>
Thu, 4 May 2017 10:52:43 +0000 (12:52 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 4 May 2017 10:52:43 +0000 (12:52 +0200)
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ImportManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelDistributionUpdateWizard.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ImportFromFileAndChooseVocIdWizardOage.java [new file with mode: 0755]

index f139b844563ee3c7f544cce1dffe6f387f2c0e39..a7560e51cae643aeb56e3a548a1581527bfa94ee 100644 (file)
@@ -176,4 +176,5 @@ viewCommandMapping.viewerName.CLASSIFICATION_WIZARD = Classification Wizard
 viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxon node Wizard\r
 command.label.CHANGE_PASSWORD = Change password\r
 wizard.name.22 = Output Model\r
+wizard.name.23 = Excel Distribution Data Update\r
 command.label.25 = Import Preferences
\ No newline at end of file
index 0fcccba796378d33ba26e343355f60881c3fb9b5..832293050fa4109c8c55c3781117cf42383813e5 100644 (file)
@@ -177,4 +177,5 @@ viewCommandMapping.viewerName.CLASSIFICATION_WIZARD = Klassifikations-Wizard
 viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxonknoten-Wizard
 command.label.CHANGE_PASSWORD = Kennwort ändern
 wizard.name.22 = Output Model
+wizard.name.23 = Excel Verbreitungsdaten Update
 command.label.25 = Import Präferenzen
\ No newline at end of file
index 177e9b99a30adbb159d9fced9c3f20070413bb84..df19313483202878e127b3deceec232e68a56aed 100755 (executable)
             class="eu.etaxonomy.taxeditor.io.wizard.AbcdImportWizard"
             id="eu.etaxonomy.taxeditor.io.import.abcd"
             name="%wizard.name.3">
+      </wizard>
+       <wizard
+            category="eu.etaxonomy.taxeditor.import.category.cdm"
+            class="eu.etaxonomy.taxeditor.io.wizard.ExcelDistributionUpdateWizard"
+            id="eu.etaxonomy.taxeditor.io.import.excelDistribution"
+            name="%wizard.name.23">
       </wizard>
       <wizard
             category="eu.etaxonomy.taxeditor.import.category.cdm"
index 4be9f81b52323b69000586fdadfd1c44bf82bcf0..523addd4be5bb1ee3722b241a944740db080cbf3 100644 (file)
@@ -29,7 +29,7 @@ public abstract class AbstractIOManager<CONFIGURATOR extends IIoConfigurator> {
        protected ICdmRepository applicationConfiguration;
 
        public static enum TYPE {
-               Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd, SpecimenCdmExcel, Excel_Name, SpecimenSearch, Gbif
+               Jaxb, Tcs, Excel_Taxa, Endnote, Sdd, Abcd, SpecimenCdmExcel, Excel_Name, SpecimenSearch, Gbif, Excel_Distribution
        }
 
        /**
index d3438c330104e8c576ca0f8952e00328c4715bcd..ae75c2898aeb1f86b02e7b6388dab8e7cf846ce7 100644 (file)
@@ -36,6 +36,7 @@ import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
 import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
 import eu.etaxonomy.cdm.io.common.ImportResult;
 import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
+import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
 import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
 import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
 import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
@@ -309,6 +310,8 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
                    return Abcd206ImportConfigurator.NewInstance(null, null);
                case Gbif:
                    return DwcaImportConfigurator.NewInstance(null, null);
+               case Excel_Distribution:
+            return ExcelDistributionUpdateConfigurator.NewInstance(null, null, null);
                default:
                        MessagingUtils.notImplementedMessage(this);
                        throw new IllegalArgumentException("Import not supported yet");
@@ -516,6 +519,9 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
                 } else if (configurator instanceof CacheUpdaterConfigurator){
                     CacheUpdaterConfigurator config = (CacheUpdaterConfigurator) configurator;
                     ioService.updateCaches(config);
+                } else if (configurator instanceof ExcelDistributionUpdateConfigurator){
+                    ExcelDistributionUpdateConfigurator config = (ExcelDistributionUpdateConfigurator) configurator;
+                    ioService.updateDistributionData(config);
                 }
 
                 monitor.done();
@@ -536,6 +542,13 @@ public class ImportManager extends AbstractIOManager<IImportConfigurator> implem
 
     }
 
+    /**
+     * @return
+     */
+    public ExcelDistributionUpdateConfigurator ExcelDistributionUpdateConfigurator() {
+        return (ExcelDistributionUpdateConfigurator) getConfigurator(TYPE.Excel_Distribution);
+    }
+
 
 
 
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelDistributionUpdateWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExcelDistributionUpdateWizard.java
new file mode 100755 (executable)
index 0000000..35ea899
--- /dev/null
@@ -0,0 +1,104 @@
+/**
+* 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.taxeditor.io.wizard;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.util.UUID;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbench;
+
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 03.05.2017
+ *
+ */
+public class ExcelDistributionUpdateWizard extends AbstractImportWizard<ExcelDistributionUpdateConfigurator> {
+    private ExcelDistributionUpdateConfigurator configurator;
+
+    private ImportFromFileAndChooseVocIdWizardOage dataSourcePage;
+
+    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public ExcelDistributionUpdateConfigurator getConfigurator() {
+        return configurator;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public boolean performFinish() {
+        URI source = dataSourcePage.getUri();
+       // configurator.setSource(source);
+        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
+        File file = new File(source);
+        FileInputStream fis = null;
+
+        try {
+            fis = new FileInputStream(file);
+        } catch (FileNotFoundException e) {
+            logger.error("Error while reading file" + source.toString());
+        }
+        try {
+            configurator.setStream(IOUtils.toByteArray(fis));
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+        UUID vocUuid = dataSourcePage.getVocUuid();
+
+        configurator.setAreaVocabularyUuid(vocUuid);
+        Job job = CdmStore.getImportManager().createIOServiceJob(configurator);
+        CdmStore.getImportManager().run(job);
+
+        return true;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void init(IWorkbench workbench, IStructuredSelection selection) {
+        super.init(workbench, selection);
+        configurator =  CdmStore.getImportManager().ExcelDistributionUpdateConfigurator();
+
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void addPages() {
+        super.addPages();
+
+        dataSourcePage = new ImportFromFileAndChooseVocIdWizardOage("Choose NormalExplicit",
+                "Please choose an xls file in the NormalExplicit format.", new String[]{"*.xlsx", "*.xls", "*.*"});
+        addPage(dataSourcePage);
+    }
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ImportFromFileAndChooseVocIdWizardOage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ImportFromFileAndChooseVocIdWizardOage.java
new file mode 100755 (executable)
index 0000000..90fbfdc
--- /dev/null
@@ -0,0 +1,111 @@
+/**
+* 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.taxeditor.io.wizard;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+
+import eu.etaxonomy.cdm.api.service.IVocabularyService;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.DefinedTermBase;
+import eu.etaxonomy.cdm.model.common.TermType;
+import eu.etaxonomy.cdm.model.common.TermVocabulary;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 04.05.2017
+ *
+ */
+public class ImportFromFileAndChooseVocIdWizardOage extends ImportFromFileDataSourceWizardPage {
+
+    private Combo vocabularyCombo;
+    UUID vocUuid;
+    String[][] labelAndValues;
+    /**
+     * @param title
+     * @param description
+     * @param extensions
+     */
+    protected ImportFromFileAndChooseVocIdWizardOage(String title, String description, String[] extensions) {
+        super(title, description, extensions);
+
+    }
+
+    @Override
+    public void createControl(Composite parent) {
+        super.createControl(parent);
+        Composite composite = (Composite)getControl();
+      //  final Composite composite = new Composite(parent, SWT.NULL);
+
+        vocabularyCombo = new Combo(composite, SWT.DROP_DOWN);
+        List<TermVocabulary<DefinedTermBase>> vocs = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea);
+        for(TermVocabulary voc: vocs){
+            vocabularyCombo.add(voc.getLabel());
+        }
+        getLabelAndValues(vocs);
+        vocabularyCombo.addSelectionListener(new SelectionAdapter(){
+
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                String name = vocabularyCombo.getText();
+
+                for (String[] labelAndValue: labelAndValues){
+                    if (labelAndValue[0].equals(name)){
+                        String uuidString = labelAndValue[1];
+                        vocUuid = UUID.fromString(uuidString);
+                        if (text_source.getText() != null){
+                            setPageComplete(true);
+                        } else{
+                            setPageComplete(false);
+                        }
+                    }
+                }
+
+            }
+
+        });
+        //setControl(composite);
+    }
+
+    public UUID getVocUuid() {
+        return vocUuid;
+    }
+
+    public void setVocUuid(UUID vocUuid) {
+        this.vocUuid = vocUuid;
+    }
+
+    /**
+     * @return
+     */
+    private String[][] getLabelAndValues(List<TermVocabulary<DefinedTermBase>> vocs) {
+
+        labelAndValues = new String[vocs.size()][2];
+        for (int i = 0; i < vocs.size(); i++) {
+            labelAndValues[i][0] = vocs.get(i).getLabel();
+            labelAndValues[i][1] = vocs.get(i).getUuid().toString();
+        }
+        return labelAndValues;
+    }
+
+    @Override
+    public boolean isPageComplete() {
+        boolean result = CdmUtils.isNotBlank(text_source.getText()) && vocUuid != null;
+
+        return result;
+    }
+
+}