X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/395d11a17cffb18a3905e39cd0320a86a8988f71..159bb3e754631c608cca350a9e43adb2295fb21d:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java?ds=sidebyside
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 89aeca734..9918b79a7 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,7 +11,11 @@ package eu.etaxonomy.taxeditor.io;
import java.io.File;
import java.io.FileOutputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.log4j.Logger;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -19,6 +23,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.application.ICdmRepository;
@@ -26,15 +31,20 @@ 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.common.IoResultBase;
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;
import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
+import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
/**
*
@@ -47,6 +57,8 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
*/
public class ExportManager extends AbstractIOManager {
+ private static final Logger logger = Logger.getLogger(ExportManager.class);
+
/**
*
* @param applicationConfiguration
@@ -179,12 +191,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());
}
@@ -246,6 +273,106 @@ 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());
+ }
+ final StringBuilder reportText = new StringBuilder();
+ if(result!=null){
+ List reports = result.getErrors();
+ reportText.append("Errors:\\r");
+ for (IoResultBase.Error bs : reports) {
+ reportText.append(bs.getMessage() + " - " +bs.getException().getStackTrace());
+ }
+ List warnings = result.getWarnings();
+ reportText.append("Warnings:\\r");
+ for (String bs : warnings) {
+ reportText.append(bs);
+ }
+ List exceptions = result.getExceptions();
+ reportText.append("Exceptions:\\r");
+ for (IoResultBase.Error bs : exceptions) {
+ reportText.append(bs.getMessage() + " - " +bs.getException().getStackTrace());
+ }
+
+
+ }
+ final Display display = Display.getDefault();
+ display.asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ // display reports with possibility to save
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setTitle(configurator.getClass().getSimpleName()+" Report");
+ dialog.setReportText(reportText.toString());
+ dialog.open();
+ CdmStore.getContextManager().notifyContextRefresh();
+ }
+ });
+
+
+
+ } catch (Exception e) {
+ MessagingUtils.errorDialog("Error exporting data",
+ this,
+ e.getMessage(),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ e,
+ true);
+ }
+
+ return Status.OK_STATUS;
+ }
+ };
+ return job;
+ }
+
}