cdmLight Export create zip is configurable and save last export folder
authorKatja Luther <k.luther@bgbm.org>
Tue, 20 Jun 2017 08:24:58 +0000 (10:24 +0200)
committerKatja Luther <k.luther@bgbm.org>
Tue, 20 Jun 2017 08:25:58 +0000 (10:25 +0200)
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/CdmLightExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvNameExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/CsvPrintExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/DarwinCoreArchiveExportWizard.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/JaxbExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/SddExportWizard.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/TcsExportWizard.java

index 014ffca201ac0e932cf97d179b6976be0a699c89..b4da3e0db560e08fe8ace2af8b50882a0a5ed8f5 100644 (file)
@@ -315,23 +315,34 @@ public class ExportManager extends AbstractIOManager<IExportConfigurator> {
                          } 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 CdmLightExportConfigurator){
-                                     fileEnding  = ".csv";
-                                 }
-
-                                 File file = new File(urlString+File.separator + key + fileEnding);
+                             SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
+                             Calendar cal = Calendar.getInstance();
+                             String fileEnding = ".csv";
+                             
+                             if (configurator.isCreateZipFile()){      
+                                        File file = new File(urlString+File.separator + "csv_light_" + sdf.format(cal.getTime())+ ".zip");                              
                                  FileOutputStream stream = new FileOutputStream(file);
-                                 Writer out = new BufferedWriter(new OutputStreamWriter(
-                                               stream, "UTF8"));
-                                 stream.write(fileData);
-                                 stream.close();
-                             }
-                        
-
-                         }else{
+                                 ZipOutputStream zos = new ZipOutputStream(stream);
+                                 for (String key: keySet){
+                                       byte[] fileData = resultMap.get(key);
+                                       ZipEntry entry = new ZipEntry( key + fileEnding); 
+                                                               zos.putNextEntry(entry);
+                                                               zos.write(fileData);
+                                                               zos.closeEntry();
+                                 }
+                                 zos.close();
+                                }else{
+                                        for (String key: keySet){
+                                                byte[] fileData = resultMap.get(key);
+                                                File file = new File(urlString+File.separator + key + fileEnding);
+                                     FileOutputStream stream = new FileOutputStream(file);
+                                     Writer out = new BufferedWriter(new OutputStreamWriter(
+                                                       stream, "UTF8"));
+                                     stream.write(fileData);
+                                     stream.close();
+                                 }
+                                }
+                        }else{
                              logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
                          }
                      } catch(Exception e){
index 39afb3bddbb05fbf42c971ccb7a1d87704091bbc..bffea5af546cf396d1f0e8c02a3f2c5097aaae1e 100755 (executable)
@@ -23,6 +23,7 @@ import org.eclipse.ui.progress.IProgressConstants;
 
 import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -98,7 +99,7 @@ public class CdmLightExportWizard extends
             job.setUser(true);
             // schedule job
             job.schedule();
-            
+            PreferencesUtil.getPreferenceStore().setValue("exportFolder", page.getFolderText());
             return true;
         }
 
@@ -114,7 +115,7 @@ public class CdmLightExportWizard extends
 
 
             //standard page
-            page =  ExportToFileDestinationWizardPage.OutputModel();
+            page =  ExportToFileDestinationWizardPage.OutputModel(configurator);
 
             addPage(page);
         }
index 3e0140d133454d8de06e6a283c6718ca459d184a..acdd9079426002585a8045dbc460ae2e7af4e252 100644 (file)
@@ -116,7 +116,7 @@ public class CsvExportWizard extends AbstractExportWizard<CsvDemoExportConfigura
 
 
                //standard page
-               page =  ExportToFileDestinationWizardPage.Csv();
+               page =  ExportToFileDestinationWizardPage.Csv(configurator);
 
                addPage(page);
        }
index f147d5651697105c6fbd34596c087cc01ed91297..f56e49c0170f328a946db41c1c676c22e1e30604 100644 (file)
@@ -90,7 +90,7 @@ public class CsvNameExportWizard extends AbstractExportWizard<CsvNameExportConfi
 \r
 \r
                //standard page\r
-               page =  ExportToFileDestinationWizardPage.CsvNames();\r
+               page =  ExportToFileDestinationWizardPage.CsvNames(configurator);\r
 \r
                addPage(page);\r
        }\r
index dbda86082f2e06a0fc20adb5df0f8f9e2cb5513f..205c31ed4dde862ed1a702d8ae2a799f0e00bf50 100644 (file)
@@ -45,7 +45,7 @@ public class CsvPrintExportWizard extends CsvNameExportWizard{
 \r
 \r
                //standard page\r
-               page =  ExportToFileDestinationWizardPage.CsvPrint();\r
+               page =  ExportToFileDestinationWizardPage.CsvPrint(configurator);\r
 \r
                addPage(page);\r
        }\r
index ec77256c86c4b7cb24c409dbd1d0fc58843c328b..55a54133add9cc343270646afa61c9ba305f9ad6 100644 (file)
@@ -82,7 +82,7 @@ public class DarwinCoreArchiveExportWizard extends
        public void addPages() {
                super.addPages();
 
-               page = ExportToFileDestinationWizardPage.Dwca();
+               page = ExportToFileDestinationWizardPage.Dwca(configurator);
                addPage(page);
        }
 }
index 1cb5cf79ce49f23fdc2322d76f40f5ef590d2988..ead0452c59f3fdc3cd04953c2ca50c01761f153c 100644 (file)
@@ -33,8 +33,18 @@ import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Text;
 
 import eu.etaxonomy.cdm.api.service.IClassificationService;
+import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
+import eu.etaxonomy.cdm.io.common.ExportConfiguratorBase;
+import eu.etaxonomy.cdm.io.csv.caryophyllales.out.CsvNameExportConfigurator;
+import eu.etaxonomy.cdm.io.csv.redlist.demo.CsvDemoExportConfigurator;
+import eu.etaxonomy.cdm.io.csv.redlist.out.CsvTaxExportConfiguratorRedlist;
+import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
+import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
+import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
+import eu.etaxonomy.cdm.io.tcsxml.out.TcsXmlExportConfigurator;
 import eu.etaxonomy.cdm.model.taxon.Classification;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.remoting.source.CdmRemoteSourceException;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
@@ -66,7 +76,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
        public static final String CSV_EXPORT = "CSV_EXPORT";
        public static final String CSV_NAME_EXPORT = "CSV_NAME_EXPORT";
        private static final String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
-
+       private static final String EXPORT_FOLDER ="EXPORT_FOLDER";
        public static final String XML = "xml";
 
        public static final String CSV = "csv";
@@ -99,16 +109,17 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
     private List<Classification> classifications;
 
     private Classification selectedClassification;
-    private String lastDirectory;
+    
+    private ExportConfiguratorBase configurator;
 
        /**
         * @param pageName
         * @param selection
         */
        protected ExportToFileDestinationWizardPage(String pageName, String type,
-                       String title, String description, String extension) {
+                       String title, String description, String extension, ExportConfiguratorBase configurator) {
                super(pageName);
-
+               this.configurator = configurator;
                this.type = type;
                switch(type) {
                   case CSV_EXPORT :
@@ -139,13 +150,13 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
         */
-       public static ExportToFileDestinationWizardPage Jaxb() {
+       public static ExportToFileDestinationWizardPage Jaxb(JaxbExportConfigurator configurator) {
                return new ExportToFileDestinationWizardPage(
                                JAXB_EXPORT,
                                "jaxb",
                                "JAXB Export",
                                "Exports the contents of the currently selected database into the cdm jaxb format.",
-                               XML);
+                               XML, configurator);
        }
 
        /**
@@ -157,13 +168,13 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
         */
-       public static ExportToFileDestinationWizardPage Tcs() {
+       public static ExportToFileDestinationWizardPage Tcs(TcsXmlExportConfigurator config) {
                return new ExportToFileDestinationWizardPage(
                                TCS_EXPORT,
                                "tcs",
                                "Tcs Export",
                                "Export the contents of the currently selected database into TCS format.",
-                               XML);
+                               XML, config);
        }
 
        /**
@@ -175,78 +186,78 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
         *         {@link eu.etaxonomy.taxeditor.io.wizard.ExportToFileDestinationWizardPage}
         *         object.
         */
-       public static ExportToFileDestinationWizardPage Sdd() {
+       public static ExportToFileDestinationWizardPage Sdd(SDDExportConfigurator config) {
                return new ExportToFileDestinationWizardPage(
                                SDD_EXPORT,
                                "sdd",
                                "Sdd Export",
                                "Export the contents of the currently selected database into SDD format.",
-                               XML);
+                               XML, config);
        }
 
        /**
         * @return
         */
-       public static ExportToFileDestinationWizardPage Dwca() {
+       public static ExportToFileDestinationWizardPage Dwca(DwcaTaxExportConfigurator config) {
                return new ExportToFileDestinationWizardPage(
                                DWCA_EXPORT,
                                DWCA_EXPORT,
                                "DwC-Archive Export",
                                "Export the contents of the currently selected database into Darwin Core Archive format.",
-                               ZIP);
+                               ZIP, config);
        }
 
        /**
      * @return
      */
-    public static ExportToFileDestinationWizardPage OutputModel() {
+    public static ExportToFileDestinationWizardPage OutputModel(CdmLightExportConfigurator config) {
         
         return new ExportToFileDestinationWizardPage(
                 OUTPUT_MODEL_EXPORT,
                 OUTPUT_MODEL_EXPORT,
                 "Output Model Export",
                 "Export the contents of the currently selected database into the output model format.",
-                CSV);
+                CSV,config);
     }
 
 
     /**
      * @return
      */
-    public static ExportToFileDestinationWizardPage Csv() {
+    public static ExportToFileDestinationWizardPage Csv(CsvDemoExportConfigurator config) {
         
         return new ExportToFileDestinationWizardPage(
                 CSV_EXPORT,
                 CSV_EXPORT,
                 "CSV Export",
                 "Export the contents of the currently selected database into Comma Separated Value format.",
-                CSV);
+                CSV, config);
     }
 
     /**
      * @return
      */
-    public static ExportToFileDestinationWizardPage CsvNames() {
+    public static ExportToFileDestinationWizardPage CsvNames(CsvNameExportConfigurator config) {
        
         return new ExportToFileDestinationWizardPage(
                 CSV_NAME_EXPORT,
                 CSV_NAME_EXPORT,
                 "CSV Name Export",
                 "Export the names of the currently selected database into Semicolon Separated Value format.",
-                CSV);
+                CSV, config);
     }
 
     /**
      * @return
      */
-    public static ExportToFileDestinationWizardPage CsvPrint() {
+    public static ExportToFileDestinationWizardPage CsvPrint(CsvNameExportConfigurator config) {
        
         return new ExportToFileDestinationWizardPage(
                 CSV_PRINT_EXPORT,
                 CSV_NAME_EXPORT,
                 "CSV Print Export",
                 "Export the content of the currently selected database into Semicolon Separated Value format.",
-                CSV);
+                CSV, config);
     }
 
        /*
@@ -298,13 +309,31 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                    classificationSelectionCombo.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));
+               if (outputModelExport){
+                        Label zipLabel = new Label(composite, SWT.NONE);
+                       zipLabel.setText("Create zip-File");
+                  Button zip = new Button(composite, SWT.CHECK);
+                  zip.addSelectionListener(new SelectionAdapter() {
+                               /*
+                                * (non-Javadoc)
+                                *
+                                * @see
+                                * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
+                                * .swt.events.SelectionEvent)
+                                */
+                               @Override
+                               public void widgetSelected(SelectionEvent e) {
+                                       super.widgetSelected(e);
+                                       ((CdmLightExportConfigurator)configurator).setCreateZipFile(zip.getSelection());
+                               }
+                       });
+               }else {
+                        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));
                }
 
                Label folderLabel = new Label(composite, SWT.NONE);
@@ -317,6 +346,10 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                text_folder.setEditable(false);
                text_folder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
                                false));
+               if (PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER) != null){
+                       text_folder.setText(PreferencesUtil.getPreferenceStore().getString(EXPORT_FOLDER));
+                       setPageComplete(true);
+               }
 
                Button button = new Button(composite, SWT.PUSH);
                button.setText("Browse...");
@@ -335,6 +368,7 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
                                String path = folderDialog.open();
                                if (path != null) { // a folder was selected
                                        text_folder.setText(path);
+                                       PreferencesUtil.getPreferenceStore().setValue(EXPORT_FOLDER, path);
                                        setPageComplete(true);
                                }
                        }
@@ -453,23 +487,6 @@ public class ExportToFileDestinationWizardPage extends WizardPage implements Sel
        
        
 
-    private void loadLastState() {
-        if(lastDirectory!=null){
-            Text text = this.getFolderComposite();
-            Listener[] listeners = text.getListeners(SWT.Modify);
-            for (int i = 0; i < listeners.length; i++) {
-                text.removeListener(SWT.Modify, listeners[i]);
-            }
-            text.setText(lastDirectory);
-            for (int i = 0; i < listeners.length; i++) {
-                text.addListener(SWT.Modify, listeners[i]);
-            }
-
-        }
-    }
-    
-    public void saveLastState() {
-       lastDirectory = this.getFolderText();
-    }
+   
 
 }
index 2873411e67b65262f0c67e5e1312ac74c7530274..2f9bbfb38c15002fd0b165efe5b471b9d8db7600 100644 (file)
@@ -75,7 +75,7 @@ public class JaxbExportWizard extends AbstractExportWizard<JaxbExportConfigurato
        public void addPages() {
                super.addPages();
 
-               page = ExportToFileDestinationWizardPage.Jaxb();
+               page = ExportToFileDestinationWizardPage.Jaxb(configurator);
                addPage(page);
        }
 
index 3d065da3fa6385923a7c47061dfdad8fd195d7c3..1edc3d82552fb84e03cd3c780348c0cc4c4d6728 100644 (file)
@@ -68,7 +68,7 @@ public class SddExportWizard extends AbstractExportWizard<SDDExportConfigurator>
        public void addPages() {
                super.addPages();
 
-               page = ExportToFileDestinationWizardPage.Sdd();
+               page = ExportToFileDestinationWizardPage.Sdd(configurator);
                addPage(page);
        }
 
index 13dd8e25ae92d9e6a957dcc1be0d83595789b69a..ee9aba915c7cc0395009c998e6481928ec538f02 100644 (file)
@@ -81,7 +81,7 @@ public class TcsExportWizard extends
        public void addPages() {
                super.addPages();
 
-               page = ExportToFileDestinationWizardPage.Tcs();
+               page = ExportToFileDestinationWizardPage.Tcs(configurator);
                addPage(page);
        }