From f3e1e1fa6b27717d2bde670e0908b4d76c0d2325 Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Thu, 23 Mar 2017 10:42:00 +0100 Subject: [PATCH] ref #6314: adaption to changes in exports --- .../OSGI-INF/l10n/bundle.properties | 3 +- .../OSGI-INF/l10n/bundle_de.properties | 3 +- eu.etaxonomy.taxeditor.store/plugin.xml | 6 + .../etaxonomy/taxeditor/io/ExportManager.java | 98 ++++++++++++++- .../ExportToFileDestinationWizardPage.java | 37 ++++-- .../io/wizard/OutputModelExportWizard.java | 119 ++++++++++++++++++ .../session/CdmEntitySessionAwareTest.java | 7 +- 7 files changed, 248 insertions(+), 25 deletions(-) create mode 100755 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/OutputModelExportWizard.java diff --git a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties index 411f2a9e8..89b5bdbf3 100644 --- a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties +++ b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties @@ -175,4 +175,5 @@ command.name.OPEN_TAXONNODE_WIZARD = Open Taxon Node Wizard command.name.INSPECT_ACTIVE_SESSIONS = Inspect Active Session viewCommandMapping.viewerName.CLASSIFICATION_WIZARD = Classification Wizard viewCommandMapping.viewerName.TAXON_NODE_WIZARD = Taxon node Wizard -command.label.CHANGE_PASSWORD = Change password \ No newline at end of file +command.label.CHANGE_PASSWORD = Change password +wizard.name.22 = Output Model \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties index e4276d7d4..c87c0875b 100644 --- a/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties +++ b/eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties @@ -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 diff --git a/eu.etaxonomy.taxeditor.store/plugin.xml b/eu.etaxonomy.taxeditor.store/plugin.xml index dba3174e3..95f416857 100755 --- a/eu.etaxonomy.taxeditor.store/plugin.xml +++ b/eu.etaxonomy.taxeditor.store/plugin.xml @@ -958,6 +958,12 @@ id="eu.etaxonomy.taxeditor.io.export.csv_print" name="%wizard.name.20"> + + diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java index 6c3204423..bd2144d51 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java @@ -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 { 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 resultMap = (Map)data.getExportData(); +// Set 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 { 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 resultMap = (Map)data.getExportData(); + Set 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; + } + } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java index 461336da7..01c5143c4 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/ExportToFileDestinationWizardPage.java @@ -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 index 000000000..3a13622f5 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/wizard/OutputModelExportWizard.java @@ -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 { + + 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 listClassifications = CdmStore.getCurrentApplicationConfiguration().getClassificationService().listClassifications(null, null, null, null); + if(combo != null){ + int selectionIndex = combo.getSelectionIndex(); + HashSet set = new HashSet(); + 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); + } + + +} diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java index 8d96af93c..ae65419e3 100644 --- a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java +++ b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/taxeditor/session/CdmEntitySessionAwareTest.java @@ -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 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> mergeResults = vocabularyService.merge(vocs, true); - + for(MergeResult result : mergeResults){ TermVocabulary voc = result.getMergedEntity(); if(voc.getUuid().equals(vocNameFeatureUuid)) { -- 2.34.1