ref #6640: first implementation for integrate RIS Import in TaxEditor
authorKatja Luther <k.luther@bgbm.org>
Tue, 16 May 2017 07:17:55 +0000 (09:17 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 16 May 2017 07:17:55 +0000 (09:17 +0200)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/handler/DeleteTaxonBaseHandler.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/GenericConfiguratorWizardPage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/RISImportWizard.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/NomenclaturalCodeHelper.java

index 8146960cd076af12575a6b2edb4b6904beccef23..5194c7a99d61a14ad66ef653780cdff9df3d49f4 100644 (file)
@@ -107,16 +107,18 @@ public class DeleteTaxonBaseHandler extends AbstractHandler implements IHandler,
 
                AbstractUtility.executeOperation(operation);
                DeleteResult result = ((DeleteTaxonBaseOperation)operation).getResult();
-               if (result.isError()){
-            DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID);
-        } else if (selectedElement instanceof Synonym){
-            this.editor.redraw();
-                   if (!result.getExceptions().isEmpty()){
-                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
-            }
-               } else if (selectedElement instanceof Taxon && !result.getExceptions().isEmpty()){
-               this.editor.redraw();
-            DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
+               if (result != null){
+               if (result.isError()){
+                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteDerivateOperation_DELETE_FAILED, TaxeditorEditorPlugin.PLUGIN_ID);
+            } else if (selectedElement instanceof Synonym){
+                this.editor.redraw();
+                   if (!result.getExceptions().isEmpty()){
+                    DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_SYNONYM_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
+                }
+               } else if (selectedElement instanceof Taxon && !result.getExceptions().isEmpty()){
+               this.editor.redraw();
+                DeleteResultMessagingUtils.messageDialogWithDetails(result, Messages.DeleteTaxonBaseHandler_DELETE_MISAPPLIEDNAME_SUCCESSFULL_BUT_REMAINING_RELATED_OBJECTS, TaxeditorEditorPlugin.PLUGIN_ID);
+               }
                }
 
 
index cc2c65e49487a9402437b11d80a78c52709ae5af..e586392f062c6a8e0926d7f693a16bfd687ba14c 100644 (file)
@@ -66,7 +66,11 @@ public class GenericConfiguratorWizardPage extends WizardPage {
 
     private ResourceBundle getResourceBundle(IIoConfigurator configurator){
         try{
-            return ResourceBundle.getBundle(configurator.getClass().getName());
+            if (configurator != null){
+                return ResourceBundle.getBundle(configurator.getClass().getName());
+            }else{
+                return ResourceBundle.getBundle("Configuration");
+            }
         }catch(MissingResourceException e){
             return null;
         }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/RISImportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/RISImportWizard.java
new file mode 100755 (executable)
index 0000000..c7f667d
--- /dev/null
@@ -0,0 +1,130 @@
+/**
+* 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.ArrayList;
+import java.util.List;
+
+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.common.IImportConfigurator.SOURCE_TYPE;
+import eu.etaxonomy.cdm.io.reference.ris.in.RisReferenceImportConfigurator;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 12.05.2017
+ *
+ */
+public class RISImportWizard extends AbstractImportWizard<RisReferenceImportConfigurator>{
+    private RisReferenceImportConfigurator configurator;
+
+    private ImportFromFileDataSourceWizardPage dataSourcePage;
+
+    private static final Logger logger = Logger.getLogger(ExcelDistributionUpdateWizard.class);
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#getConfigurator()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public RisReferenceImportConfigurator getConfigurator() {
+        return configurator;
+    }
+
+    /* (non-Javadoc)
+     * @see org.eclipse.jface.wizard.Wizard#performFinish()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public boolean performFinish() {
+        URI source = dataSourcePage.getUri();
+       // configurator.setSource(source);
+//        try {
+//            configurator = RisReferenceImportConfigurator.NewInstance(source, null);
+//        } catch (MalformedURLException e1) {
+//            // TODO Auto-generated catch block
+//            e1.printStackTrace();
+//        } catch (IOException e1) {
+//            // TODO Auto-generated catch block
+//            e1.printStackTrace();
+//        }
+        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){
+
+        }
+
+        //CdmStore.getImportManager().runMoniteredOperation(configurator, new File(source), SOURCE_TYPE.INPUTSTREAM);
+
+
+        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 = RisReferenceImportConfigurator.NewInstance();
+
+    }
+
+    /* (non-Javadoc)
+     * @see eu.etaxonomy.taxeditor.io.wizard.AbstractImportWizard#addPages()
+     */
+    /** {@inheritDoc} */
+    @Override
+    public void addPages() {
+        //addConfiguratorPage();
+        addDataSourcePage();
+
+
+    }
+    @Override
+    protected void addConfiguratorPage(){
+        List<String> ignoreMethods = new ArrayList<>();
+        ignoreMethods.add("setIgnoreNull");
+        ignoreMethods.add("setInteractWithUser");
+        ignoreMethods.add("setUseClassification");
+        pageConfiguration = GenericConfiguratorWizardPage.Import(CONFIGURATION_PAGE, getConfigurator(), ignoreMethods, "Ris Import");
+        addPage(pageConfiguration);
+    }
+
+    private void addDataSourcePage(){
+        dataSourcePage = new ImportFromFileDataSourceWizardPage("Choose Ris File",
+                "Please choose an xls file in the Distribution Update format.", new String[]{"*.txt"});
+        addPage(dataSourcePage);
+    }
+
+}
index 2ee64bba9f709b1167d1abcbb6b396533a0a2034..ea4c9303650b13c15bce17a559e2d18039fdf7a5 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -14,6 +14,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 
 /**
  * <p>NomenclaturalCodeHelper class.</p>
@@ -23,7 +24,7 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
  * @version 1.0
  */
 public class NomenclaturalCodeHelper {
-               
+
        /**
         * <p>getAllCodes</p>
         *
@@ -43,12 +44,16 @@ public class NomenclaturalCodeHelper {
                List<NomenclaturalCode> supportedCodes = new ArrayList<NomenclaturalCode>();
                for (NomenclaturalCode code : getAllCodes()) {
                        if (isSupported(code)) {
-                               supportedCodes.add(code);
+                           if (PreferencesUtil.getPreferredNomenclaturalCode().equals(code)){
+                               supportedCodes.add(0, code);
+                           }else{
+                               supportedCodes.add(code);
+                           }
                        }
                }
                return supportedCodes;
        }
-       
+
        /**
         * @param code
         * @return
@@ -80,13 +85,13 @@ public class NomenclaturalCodeHelper {
                }
                if (code.equals(NomenclaturalCode.ICZN)) {
                        return "International Code of Zoological Nomenclature (ICZN)";
-               }               
+               }
                if (code.equals(NomenclaturalCode.ICVCN)) {
                        return "International Code for Virus Classification and Nomenclature (ICVCN)";
-               } 
+               }
                return code.name();
        }
-       
+
        /**
         * <p>getDefaultCode</p>
         *