ref #6314: adaption to changes in exports
authorKatja Luther <k.luther@bgbm.org>
Thu, 23 Mar 2017 09:42:00 +0000 (10:42 +0100)
committerKatja Luther <k.luther@bgbm.org>
Thu, 23 Mar 2017 09:47:21 +0000 (10:47 +0100)
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/ExportManager.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/OutputModelExportWizard.java [new file with mode: 0755]
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java

index 411f2a9e8f515f8bd8d84ede4df4d051ff167742..89b5bdbf38b7960fab4c793fbaa2c7c8ea689e61 100644 (file)
@@ -175,4 +175,5 @@ command.name.OPEN_TAXONNODE_WIZARD = Open Taxon Node Wizard
 command.name.INSPECT_ACTIVE_SESSIONS = Inspect Active Session\r
 viewCommandMapping.viewerName.CLASSIFICATION_WIZARD = Classification Wizard\r
 viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxon node Wizard\r
-command.label.CHANGE_PASSWORD = Change password
\ No newline at end of file
+command.label.CHANGE_PASSWORD = Change password\r
+wizard.name.22 = Output Model
\ No newline at end of file
index e4276d7d40d9a4853f03c97359407c91bd95e1e6..c87c0875b623b6bf3849a332e3d94c105745e559 100644 (file)
@@ -176,4 +176,5 @@ command.name.OPEN_TAXONNODE_WIZARD = \u00d6ffne Taxonknoten-Wizard
 command.name.INSPECT_ACTIVE_SESSIONS = Aktive Session untersuchen
 viewCommandMapping.viewerName.CLASSIFICATION_WIZARD = Klassifikations-Wizard
 viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxonknoten-Wizard
-command.label.CHANGE_PASSWORD = Kennwort √§ndern
\ No newline at end of file
+command.label.CHANGE_PASSWORD = Kennwort √§ndern
+wizard.name.22 = Output Model
\ No newline at end of file
index dba3174e308361f2f06b836f16b33946dcdf1ac5..95f416857655b0d5366a1927d8f53947d421cd1c 100755 (executable)
             id="eu.etaxonomy.taxeditor.io.export.csv_print"
             name="%wizard.name.20">
       </wizard>
+      <wizard
+            category="eu.etaxonomy.taxeditor.export.category.cdm"
+            class="eu.etaxonomy.taxeditor.io.wizard.OutputModelExportWizard"
+            id="eu.etaxonomy.taxeditor.io.export.output_model"
+            name="%wizard.name.22">
+      </wizard>
    </extension>
    <extension
          point="org.eclipse.ui.newWizards">
index 6c32044238076d032caf5a18cf3f07cbc2e2ea31..bd2144d51f437ef970f657de0e9334ec25efe1d3 100644 (file)
@@ -11,6 +11,8 @@ package eu.etaxonomy.taxeditor.io;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.util.Map;
+import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.eclipse.core.runtime.Assert;
@@ -27,9 +29,11 @@ import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
 import eu.etaxonomy.cdm.io.common.ExportDataWrapper;
 import eu.etaxonomy.cdm.io.common.ExportResult;
+import eu.etaxonomy.cdm.io.common.ExportResultType;
 import eu.etaxonomy.cdm.io.common.IExportConfigurator;
 import eu.etaxonomy.cdm.io.common.IIoConfigurator;
 import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
+import eu.etaxonomy.cdm.io.outputmodel.OutputModelConfigurator;
 import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
 import eu.etaxonomy.cdm.io.service.IIOService;
 import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
@@ -182,12 +186,27 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
                        ExportResult result = ioService.export(configurator);
                        ExportDataWrapper data = result.getExportData();
                        try{
-                           byte[] exportData = (byte[])data.getExportData();
-                           if(exportData != null){
-                            FileOutputStream stream = new FileOutputStream(exportFile);
-                            stream.write(exportData);
-                            stream.close();
-                        }
+                       if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
+                           byte[] exportData = (byte[])data.getExportData();
+                               if(exportData != null){
+                                   FileOutputStream stream = new FileOutputStream(exportFile);
+                                stream.write(exportData);
+                                stream.close();
+                            }
+//                     } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
+//                         Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
+//                         Set<String> keySet = resultMap.keySet();
+//                         for (String key: keySet){
+//                             byte[] fileData = resultMap.get(key);
+//                             File file = new File(urlString)
+//                             FileOutputStream stream = new FileOutputStream(key);
+//                                stream.write(fileData);
+//                                stream.close();
+//                         }
+
+                       }else{
+                           logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
+                       }
                        } catch(Exception e){
                            logger.error(e.getStackTrace());
                        }
@@ -249,6 +268,73 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
                return (SDDExportConfigurator) getConfigurator(TYPE.Sdd);
        }
 
+    /**
+     * @param configurator
+     * @param urlString
+     * @return
+     */
+    public Job createIOServiceJob(OutputModelConfigurator configurator, String urlString) {
+        Assert.isNotNull(configurator, "Configuration may not be null");
+
+        // final Display display = Display.getCurrent();
+
+         Job job = new Job("Export: " + configurator.getClass().getSimpleName()) { //$NON-NLS-1$
+             @Override
+             protected IStatus run(IProgressMonitor monitor) {
+                 monitor.beginTask("Exporting database. This will take some time.", IProgressMonitor.UNKNOWN);
+                 try {
+                     IIOService ioService = CdmApplicationState.getIOService();
+
+                     ExportResult result = ioService.export(configurator);
+                     ExportDataWrapper data = result.getExportData();
+                     try{
+                         if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
+                             byte[] exportData = (byte[])data.getExportData();
+                             if(exportData != null){
+                                 File file = new File(urlString);
+                                 FileOutputStream stream = new FileOutputStream(file);
+                                 stream.write(exportData);
+                                 stream.close();
+                             }
+                         } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
+                             Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
+                             Set<String> keySet = resultMap.keySet();
+                             for (String key: keySet){
+                                 byte[] fileData = resultMap.get(key);
+                                 String fileEnding ="";
+                                 if (configurator instanceof OutputModelConfigurator){
+                                     fileEnding  = ".csv";
+                                 }
+                                 File file = new File(urlString+File.separator + key + fileEnding);
+                                 FileOutputStream stream = new FileOutputStream(file);
+                                 stream.write(fileData);
+                                 stream.close();
+                             }
+
+                         }else{
+                             logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
+                         }
+                     } catch(Exception e){
+                         logger.error(e.getStackTrace());
+                     }
+
+
+
+
+                 } catch (Exception e) {
+                     MessagingUtils.errorDialog("Error exporting data",
+                             this,
+                             e.getMessage(),
+                             TaxeditorStorePlugin.PLUGIN_ID,
+                             e,
+                             true);
+                 }
+                 return Status.OK_STATUS;
+             }
+         };
+         return job;
+    }
+
 
 
 }
index 461336da77e38697e48d78ad218a277ef2138d70..01c5143c4f019d61472dd604401e5f1a271e65e9 100644 (file)
@@ -61,7 +61,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
        public static final String SDD_EXPORT = "SDD_EXPORT";
 
        public static final String DWCA_EXPORT = "DWCA_EXPORT";
-
+       public static final String OUTPUT_MODEL_EXPORT = "OUTPUT_MODEL_EXPORT";
        public static final String CSV_EXPORT = "CSV_EXPORT";
        public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
 
@@ -81,6 +81,8 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
 
        private static boolean csvPrintExport = false;
 
+       private static boolean outputModelExport = false;
+
        private DirectoryDialog folderDialog;
        private Text text_exportFileName;
 
@@ -176,6 +178,18 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                                ZIP);
        }
 
+       /**
+     * @return
+     */
+    public static ExportToFileDestinationWizardPage OutputModel() {
+        outputModelExport = true;
+        return new ExportToFileDestinationWizardPage(
+                OUTPUT_MODEL_EXPORT,
+                "output model",
+                "Output Model Export",
+                "Export the contents of the currently selected database into the output model format.",
+                CSV);
+    }
 
 
     /**
@@ -255,7 +269,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                }
 
 
-               if(csvExport || csvPrintExport){
+               if(csvExport || csvPrintExport || outputModelExport){
                    Label comboBoxLabel = new Label(composite, SWT.NONE);
                    comboBoxLabel.setText("Classification");
 
@@ -263,17 +277,14 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                    classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
                                true, false, 2, 1));
                }
-
-
-
-
-               Label fileLabel = new Label(composite, SWT.NONE);
-               fileLabel.setText("File");
-
-               text_exportFileName = new Text(composite, SWT.BORDER);
-               text_exportFileName.setText(generateFilename());
-               text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
-                               true, false, 2, 1));
+               if (!outputModelExport){
+                   Label fileLabel = new Label(composite, SWT.NONE);
+               fileLabel.setText("File");
+               text_exportFileName = new Text(composite, SWT.BORDER);
+               text_exportFileName.setText(generateFilename());
+               text_exportFileName.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
+                               true, false, 2, 1));
+               }
 
                Label folderLabel = new Label(composite, SWT.NONE);
                folderLabel.setText("Folder");
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/OutputModelExportWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/OutputModelExportWizard.java
new file mode 100755 (executable)
index 0000000..3a13622
--- /dev/null
@@ -0,0 +1,119 @@
+/**
+* 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.util.HashSet;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.progress.IProgressConstants;
+
+import eu.etaxonomy.cdm.io.outputmodel.OutputModelConfigurator;
+import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * @author k.luther
+ * @date 21.03.2017
+ *
+ */
+public class OutputModelExportWizard extends
+     AbstractExportWizard<OutputModelConfigurator> {
+
+        private OutputModelConfigurator configurator;
+        private ExportToFileDestinationWizardPage page;
+
+        private final String description = "Export the contents of the currently selected database into Comma Separated Value format.";
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench,
+         * org.eclipse.jface.viewers.IStructuredSelection)
+         */
+        @Override
+        public void init(IWorkbench workbench, IStructuredSelection selection) {
+            configurator = new OutputModelConfigurator(null);
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see
+         * eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#getConfigurator()
+         */
+        @Override
+        public OutputModelConfigurator getConfigurator() {
+            return configurator;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see org.eclipse.jface.wizard.Wizard#performFinish()
+         */
+        @Override
+        public boolean performFinish() {
+            String urlString = page.getFolderText() + File.separator;
+                    //+ page.getExportFileName();
+
+            final Combo combo = page.getCombo();
+            final List<Classification> listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null);
+            if(combo != null){
+                int selectionIndex = combo.getSelectionIndex();
+                HashSet<UUID> set = new HashSet<UUID>();
+                if(selectionIndex == -1){
+                    for(Classification c:listClassifications){
+                        set.add(c.getUuid());
+                    }
+                }else{
+                    for(Classification c:listClassifications){
+                        if(c.getTitleCache().equalsIgnoreCase(combo.getItem(selectionIndex))){
+                            set.add(c.getUuid());
+                        }
+                    }
+                    configurator.setClassificationUuids(set);
+
+                }
+            }
+
+            // create job
+            Job job = CdmStore.getExportManager().createIOServiceJob(configurator, urlString);
+            // configure the job
+            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+            job.setUser(true);
+            // schedule job
+            job.schedule();
+
+            return true;
+        }
+
+        /*
+         * (non-Javadoc)
+         *
+         * @see eu.etaxonomy.taxeditor.io.wizard.AbstractExportWizard#addPages()
+         */
+        @Override
+        public void addPages() {
+            //TODO create page with drop down menu for export for single classification.
+//          super.addPages();
+
+
+            //standard page
+            page =  ExportToFileDestinationWizardPage.OutputModel();
+
+            addPage(page);
+        }
+
+
+}
index 8d96af93ccc661f6d892ed8f8702f38c0820f378..ae65419e35e32da22d30ffc47610f76d16b4e20a 100644 (file)
@@ -32,7 +32,6 @@ import eu.etaxonomy.cdm.api.service.ITaxonService;
 import eu.etaxonomy.cdm.api.service.ITermService;
 import eu.etaxonomy.cdm.api.service.IUserService;
 import eu.etaxonomy.cdm.api.service.IVocabularyService;
-import eu.etaxonomy.cdm.api.service.pager.Pager;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.agent.AgentBase;
 import eu.etaxonomy.cdm.model.agent.Person;
@@ -175,7 +174,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
     }
 
     @Test
-    @Ignore
+@Ignore
     public void addGrandChildPolytomousKeyNode() {
 
         PolytomousKey pKey = CdmBase.deproxy(polytomousKeyService.find(polytomousKeyUuid),PolytomousKey.class);
@@ -467,7 +466,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
                        }
                }
                termService.delete(updateTerms);
-               
+
 //              if(termService.findByRepresentationText("UpdateTest", Feature.class, null, null) != null) {
 //                     Pager<Feature> terms =  termService.findByRepresentationText("UpdateTest", Feature.class, null, null);
 //                     if (!terms.getRecords().isEmpty()){
@@ -487,7 +486,7 @@ public class CdmEntitySessionAwareTest extends RemotingSessionAwareTest {
             vocNameFeature.addTerm(newTerm);
 
             List<MergeResult<TermVocabulary>> mergeResults = vocabularyService.merge(vocs, true);
-            
+
             for(MergeResult<TermVocabulary> result : mergeResults){
                TermVocabulary voc = result.getMergedEntity();
                 if(voc.getUuid().equals(vocNameFeatureUuid)) {