ref #7005 Migrate RIS import
authorPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 5 Oct 2017 09:16:23 +0000 (11:16 +0200)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Thu, 5 Oct 2017 09:16:23 +0000 (11:16 +0200)
eu.etaxonomy.taxeditor.store/fragment.e4xmi
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/OpenRisImportWizard.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/RISImportWizardE4.java [new file with mode: 0755]

index 1df719f87b9c84d12e660d65b424424d6e6dbfe2..6fed598728950d9cc7b1a13a23010526d540c0c4 100644 (file)
     <elements xsi:type="commands:Command" xmi:id="_QbHeEKmQEeeDJPU_cUTI2g" elementId="eu.etaxonomy.taxeditor.store.command.importAbcd" commandName="%wizard.name.3"/>
     <elements xsi:type="commands:Command" xmi:id="_tpPnUKmfEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.store.command.importExcelDistribution" commandName="%wizard.name.23"/>
     <elements xsi:type="commands:Command" xmi:id="_qAEkYKmjEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.store.command.importExcelTaxa" commandName="%wizard.name.2"/>
+    <elements xsi:type="commands:Command" xmi:id="_tBCr8KmsEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.store.command.imnportRisReference" commandName="%wizard.name.24"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
     <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_2yHUgKmYEeeDJPU_cUTI2g" elementId="eu.etaxonomy.taxeditor.io.e4.abcd.OpenAbcdImportWizard" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.io.e4.abcd.OpenAbcdImportWizard" command="_QbHeEKmQEeeDJPU_cUTI2g"/>
     <elements xsi:type="commands:Handler" xmi:id="_6slh0KmfEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.io.e4.excel.distribution.OpenExcelDistributionImportWizard" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.io.e4.excel.distribution.OpenExcelDistributionImportWizard" command="_tpPnUKmfEeeTAPHmaMLwQQ"/>
     <elements xsi:type="commands:Handler" xmi:id="_wvx9oKmjEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.io.e4.excel.taxa.OpenExcelTaxaImportWizard" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.io.e4.excel.taxa.OpenExcelTaxaImportWizard" command="_qAEkYKmjEeeTAPHmaMLwQQ"/>
+    <elements xsi:type="commands:Handler" xmi:id="_96ANIKmsEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.io.e4.ris.OpenRisImportWizard" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.io.e4.ris.OpenRisImportWizard" command="_tBCr8KmsEeeTAPHmaMLwQQ"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_qT4hgIfTEeecZ4F2Y9Z0Og" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.window" positionInList="before:eu.etaxonomy.taxeditor.application.windowMenu.last">
     <elements xsi:type="menu:Menu" xmi:id="_LT3P8IfcEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.termeditor" label="Term Editor">
         <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_wnmZYKmgEeeTAPHmaMLwQQ" coreExpressionId="isShowExperimentalFeatures"/>
       </children>
       <children xsi:type="menu:HandledMenuItem" xmi:id="_0z1o8KmjEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exceldistribution" label="%wizard.name.2" command="_qAEkYKmjEeeTAPHmaMLwQQ"/>
+      <children xsi:type="menu:HandledMenuItem" xmi:id="_pQNeoKmsEeeTAPHmaMLwQQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.risReference" label="%wizard.name.24" command="_qAEkYKmjEeeTAPHmaMLwQQ"/>
     </elements>
   </fragments>
 </fragment:ModelFragments>
index 393a437b76c97d5871b16a3548762bb84e533b80..f9d7ceed1b83341c50945e7b898c3bcd21addcaa 100755 (executable)
             id="eu.etaxonomy.taxeditor.io.import.endnote"
             name="%wizard.name.1">
       </wizard>-->
-       <wizard
-            category="eu.etaxonomy.taxeditor.import.category.cdm"
-            class="eu.etaxonomy.taxeditor.io.wizard.RISImportWizard"
-            id="eu.etaxonomy.taxeditor.io.import.risImport"
-            name="%wizard.name.24">
-          
-      </wizard>
       <wizard
             category="eu.etaxonomy.taxeditor.import.category.cdm"
             class="eu.etaxonomy.taxeditor.io.wizard.SddImportWizard"
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/OpenRisImportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/OpenRisImportWizard.java
new file mode 100644 (file)
index 0000000..26b7768
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+* 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.e4.ris;
+
+import eu.etaxonomy.taxeditor.io.e4.AbstractImportWizardE4;
+import eu.etaxonomy.taxeditor.io.e4.AbstractOpenImportWizard;
+
+/**
+ * @author pplitzner
+ * @since Oct 5, 2017
+ *
+ */
+public class OpenRisImportWizard extends AbstractOpenImportWizard {
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected Class<? extends AbstractImportWizardE4> getImportWizardClass() {
+        return RISImportWizardE4.class;
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/RISImportWizardE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/e4/ris/RISImportWizardE4.java
new file mode 100755 (executable)
index 0000000..05f152e
--- /dev/null
@@ -0,0 +1,117 @@
+/**
+* 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.e4.ris;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.contexts.ContextInjectionFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
+import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
+import eu.etaxonomy.taxeditor.io.e4.AbstractImportWizardE4;
+import eu.etaxonomy.taxeditor.io.e4.GenericConfiguratorWizardPageE4;
+import eu.etaxonomy.taxeditor.io.e4.ImportFromFileDataSourceWizardPageE4;
+import eu.etaxonomy.taxeditor.io.wizard.ExcelDistributionUpdateWizard;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 12.05.2017
+ *
+ */
+public class RISImportWizardE4 extends AbstractImportWizardE4<RisReferenceImportConfigurator>{
+
+    private RisReferenceImportConfigurator configurator;
+
+    private ImportFromFileDataSourceWizardPageE4 dataSourcePage;
+
+    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
+
+    @Inject
+    public RISImportWizardE4(IEclipseContext context, EPartService partService) {
+        super(context, partService, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public RisReferenceImportConfigurator getConfigurator() {
+        return configurator;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public boolean performFinish() {
+        URI source = dataSourcePage.getUri();
+        configurator.setDbSchemaValidation(DbSchemaValidation.CREATE);
+        File file = new File(source);
+       FileInputStream fis;
+
+        try {
+            fis = new FileInputStream(file);
+            byte[] data;
+            data = IOUtils.toByteArray(fis);
+            configurator.setStream(data);
+//TODO: workaround, needs to be changed to source as byte array
+            Job job = CdmStore.getImportManager().createIOServiceJob(configurator, data, SOURCE_TYPE.INPUTSTREAM);
+            CdmStore.getImportManager().run(job);
+        } catch (FileNotFoundException e) {
+            logger.error("Error while reading file" + source.toString());
+        } catch (IOException e){
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void init() {
+        configurator = RisReferenceImportConfigurator.NewInstance();
+
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void addPages() {
+        addDataSourcePage();
+    }
+    @Override
+    protected void addConfiguratorPage(){
+        List<String> ignoreMethods = new ArrayList<>();
+        ignoreMethods.add("setIgnoreNull");
+        ignoreMethods.add("setInteractWithUser");
+        ignoreMethods.add("setUseClassification");
+        pageConfiguration = ContextInjectionFactory.make(GenericConfiguratorWizardPageE4.class, context);
+        pageConfiguration.initImport(getConfigurator(), ignoreMethods, "Ris Import");
+        addPage(pageConfiguration);
+    }
+
+    private void addDataSourcePage(){
+        dataSourcePage = ContextInjectionFactory.make(ImportFromFileDataSourceWizardPageE4.class, context);
+        dataSourcePage.setTitle("Choose Ris File");
+        dataSourcePage.setDescription("Please choose an xls file in the Distribution Update format.");
+        dataSourcePage.setExtensions(new String[]{"*.txt"});
+        addPage(dataSourcePage);
+    }
+
+}