* 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.model;
import java.io.BufferedWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
+import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.NotEnabledException;
-import org.eclipse.core.commands.NotHandledException;
-import org.eclipse.core.commands.common.NotDefinedException;
import org.eclipse.core.commands.operations.AbstractOperation;
import org.eclipse.core.commands.operations.IOperationHistory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.e4.ui.di.UISynchronize;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
import org.eclipse.ui.progress.IProgressConstants;
-import org.eclipse.ui.progress.IProgressService;
-import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
-import org.eclipse.ui.themes.ITheme;
-import org.eclipse.ui.themes.IThemeManager;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
+import eu.etaxonomy.cdm.api.service.UpdateResult;
+import eu.etaxonomy.cdm.api.service.dto.CdmEntityIdentifier;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.common.SetMap;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
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.ExportType;
-import eu.etaxonomy.cdm.model.common.IEnumTerm;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.model.term.IEnumTerm;
import eu.etaxonomy.taxeditor.event.EventUtility;
+import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.operation.RemotingCdmHandler;
-import eu.etaxonomy.taxeditor.operation.e4.RemotingCdmHandlerE4;
+import eu.etaxonomy.taxeditor.operation.e4.CdmHandlerE4;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
import eu.etaxonomy.taxeditor.ui.dialog.ReportTextDialog;
-import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewerE4;
+import eu.etaxonomy.taxeditor.view.e4.AbstractCdmDataViewer;
import eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4;
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
/**
- *
* @author n.hoffmann
* @created 11.05.2009
- * @version 1.0
*/
public abstract class AbstractUtility {
- private static final Logger logger = Logger.getLogger(AbstractUtility.class);
+ protected static final Logger logger = LogManager.getLogger(AbstractUtility.class);
/** Constant <code>statusLineManager</code> */
protected static IStatusLineManager statusLineManager;
return TaxeditorStorePlugin.getDefault().getWorkbench();
}
+ @SuppressWarnings("unchecked")
public static Object getService(Class api) {
return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
}
- public static ITheme getCurrentTheme() {
- IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
- .getWorkbench().getThemeManager();
- return themeManager.getCurrentTheme();
- }
-
public static Font getFont(String symbolicName) {
return FontResources.getFont(symbolicName);
}
"There is no operation history for this context");
}
- final IAdaptable uiInfoAdapter = WorkspaceUndoUtil
- .getUIInfoAdapter(getShell());
+ final IAdaptable uiInfoAdapter = WorkspaceUndoUtil.getUIInfoAdapter(getShell());
Job job = Job.create(operation.getLabel(), (ICoreRunnable) monitor -> {
sync.syncExec(() -> {
String statusString = status.equals(Status.OK_STATUS) ? "completed"
: "cancelled";
setStatusLine(operationlabel + " " + statusString + ".");
+ IPostOperationEnabled postOperationEnabled = operation
+ .getPostOperationEnabled();
+ if (postOperationEnabled != null) {
+ postOperationEnabled.onComplete();
+ }
});
});
job.setUser(true);
job.schedule();
} catch (Exception e) {
- MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+ MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occurred while executing " + operation.getLabel(), e);
}
- IPostOperationEnabled postOperationEnabled = operation
- .getPostOperationEnabled();
- if (postOperationEnabled != null) {
- postOperationEnabled.onComplete();
- }
return Status.OK_STATUS;
}
- public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandlerE4 handler, UISynchronize sync) {
+ public static IStatus executeOperation(final AbstractOperation operation, final CdmHandlerE4 handler, UISynchronize sync) {
return executeOperation_internal(operation, handler, sync);
}
- public static IStatus executeOperation(final AbstractOperation operation, final RemotingCdmHandler handler, UISynchronize sync) {
- return executeOperation_internal(operation, handler, sync);
- }
-
- private static IStatus executeOperation_internal(final AbstractOperation operation, final Object handler,
+ private static IStatus executeOperation_internal(final AbstractOperation operation, final CdmHandlerE4 handler,
UISynchronize sync) {
if (getOperationHistory() == null) {
throw new IllegalArgumentException(
operation.addContext(IOperationHistory.GLOBAL_UNDO_CONTEXT);
status = operation.execute(monitor,
uiInfoAdapter);
- if(handler instanceof RemotingCdmHandler) {
- ((RemotingCdmHandler) handler).postOperation(status);
- }
- else if(handler instanceof RemotingCdmHandlerE4) {
- ((RemotingCdmHandlerE4) handler).postOperation(status);
- }
+ handler.postOperation(status);
} catch (ExecutionException e) {
MessagingUtils.operationDialog(AbstractUtility.class, e, TaxeditorStorePlugin.PLUGIN_ID, operationlabel, null);
} finally {
job.setUser(true);
sync.syncExec(()->job.schedule());
} catch (Exception e) {
- MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occured while executing " + operation.getLabel(), e);
+ MessagingUtils.messageDialog("Error executing operation", AbstractUtility.class, "An error occurred while executing " + operation.getLabel(), e);
}
return Status.OK_STATUS;
if(firstRemotingMonitor == null) {
throw new IllegalStateException("Remoting progress monitor is null");
}
+ if (firstRemotingMonitor.isDone()){
+ createExportResult(label, urlString, createZip, firstRemotingMonitor);
+ }
Job job = new Job(label) {
@Override
public IStatus run(IProgressMonitor monitor) {
// run the monitor until the operation is finished
- monitor.beginTask("Start", 100);
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
+ //subMonitor.beginTask("Start", 100);
IRemotingProgressMonitor remotingMonitor;
try {
remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label,
pollInterval,
postOp,
feedbackGenerator,
- monitor);
+ subMonitor);
} catch (Exception ex) {
- return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
- }
- final StringBuilder reportSb = new StringBuilder();
- if (remotingMonitor.getResult() instanceof ExportResult){
- ExportResult result = (ExportResult)remotingMonitor.getResult();
-
- reportSb.append(result.createReport());
-
- if(!StringUtils.isBlank(reportSb.toString())) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- // display reports with possibility to save
- ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
- dialog.setTitle(label + " Report");
- dialog.setReportText(reportSb.toString());
- dialog.open();
- }
- });
- }
-
- if (urlString != null){
- 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);
- Writer out = new BufferedWriter(new OutputStreamWriter(
- stream, "UTF8"));
-
- stream.write(exportData);
- out.flush();
- 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();
- SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
- Calendar cal = Calendar.getInstance();
- String fileEnding = ".csv";
-
- if (createZip){
- File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip");
- FileOutputStream stream = new FileOutputStream(file);
- 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{
- if(result.getExportType().equals(ExportType.DWCA)){
-
- File file = new File(urlString);
- FileOutputStream stream = new FileOutputStream(file);
- 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){
- logger.error(e.getStackTrace());
- }
- }
+ return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
}
+
+ createExportResult(label, urlString, createZip, remotingMonitor);
return Status.OK_STATUS;
}
+
+
@Override
protected void canceling() {
CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
// configure the job
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
job.setUser(true);
+ job.setName(label);
// schedule job
job.schedule();
} catch (Exception e) {
MessagingUtils.errorDialog("Error executing operation",
AbstractUtility.class,
- "An error occured while executing " + label,
+ "An error occurred while executing " + label,
TaxeditorStorePlugin.PLUGIN_ID,
e,
true);
newMonitor.worked(steps);
}
- public static IProgressService getProgressService() {
- IWorkbench workbench = PlatformUI.getWorkbench();
- return workbench.getProgressService();
- }
-
- public static IWorkbenchSiteProgressService getProgressService2() {
- return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
- }
-
public static String getPluginId() {
return "eu.taxeditor";
}
public static void refreshDetailsViewer(EPartService partService) {
if (getDetailsView(partService) != null) {
- ((AbstractCdmDataViewerE4) getDetailsView(partService).getViewer()).refresh();
+ ((AbstractCdmDataViewer) getDetailsView(partService).getViewer()).refresh();
}
}
public static void reflowDetailsViewer(EPartService partService) {
if (getDetailsView(partService) != null) {
- ((AbstractCdmDataViewerE4) getDetailsView(partService).getViewer()).reflow();
+ ((AbstractCdmDataViewer) getDetailsView(partService).getViewer()).reflow();
}
}
if(depth>0){
indentString += "- ";
}
- result.put(node.term, indentString + node.term.getMessage());
+ result.put(node.term, indentString + node.term.getLabel());
parseTermTree(node.children, result, depth);
}
}
if (getClass() != obj.getClass()) {
return false;
}
- TermNode other = (TermNode) obj;
+ TermNode<?> other = (TermNode<?>) obj;
if (term == null) {
if (other.term != null) {
return false;
@Override
public int compareTo(TermNode<T> that) {
- return this.term.getMessage().compareTo(that.term.getMessage());
- }
- }
-
-
- public static void executeCommand(String commandId, Object source, String pluginId) {
- IHandlerService handlerService = (IHandlerService) AbstractUtility.getService(IHandlerService.class);
- Exception exception = null;
- try {
- handlerService.executeCommand(commandId, null);
- } catch (ExecutionException e) {
- exception = e;
- } catch (NotDefinedException e) {
- exception = e;
- } catch (NotEnabledException e) {
- exception = e;
- } catch (NotHandledException e) {
- exception = e;
- } finally {
- if(exception != null) {
- MessagingUtils.errorDialog("Error executing command",
- source,
- "Could not execute command with id " + commandId ,
- pluginId,
- exception,
- true);
- }
+ return this.term.getLabel().compareTo(that.term.getLabel());
}
}
final int pollInterval,
final boolean cancelable,
final IPostMoniteredOperationEnabled postOp,
- final IFeedbackGenerator feedbackGenerator) {
+ final IFeedbackGenerator feedbackGenerator,
+ final boolean showResult,
+ final boolean updateNavigator) {
try{
// get the remoting monitor the first time to make sure that the
if(firstRemotingMonitor == null) {
throw new IllegalStateException("Remoting progress monitor is null");
}
+ if (firstRemotingMonitor.isDone()){
+ createResult(label, showResult, firstRemotingMonitor);
+ Set<Taxon> taxaToUpdate = getTaxaToUpdate(firstRemotingMonitor);
+ updateNameEditors(taxaToUpdate);
+ return Status.OK_STATUS;
+ }
Job job = new Job(label) {
-
-
@Override
public IStatus run(IProgressMonitor monitor) {
// run the monitor until the operation is finished
- monitor.beginTask("Start", 100);
+ SubMonitor subMonitor = SubMonitor.convert(monitor, 100);
+
+
IRemotingProgressMonitor remotingMonitor;
try {
remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor(label,
pollInterval,
postOp,
feedbackGenerator,
- monitor);
+ subMonitor);
} catch (Exception ex) {
- return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
+ return new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
}
- final StringBuilder reportSb = new StringBuilder();
+
// collect reports
// for(String report : remotingMonitor.getResult()) {
- reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
-// }
- if(!StringUtils.isBlank(reportSb.toString())) {
- Display.getDefault().asyncExec(new Runnable() {
- @Override
- public void run() {
- // display reports with possibility to save
- ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
- dialog.setTitle(label + " Report");
- dialog.setReportText(reportSb.toString());
- dialog.open();
- }
- });
+ createResult(label, showResult, remotingMonitor);
+ Set<Taxon> taxaToUpdate = getTaxaToUpdate(remotingMonitor);
+ updateNameEditors(taxaToUpdate);
+ if (!taxaToUpdate.isEmpty() && updateNavigator){
+ refreshNavigator();
}
+ subMonitor.subTask("");
return Status.OK_STATUS;
}
+ private void refreshNavigator() {
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAVIGATOR, true);
+ }
+
@Override
protected void canceling() {
CdmStore.getCurrentApplicationConfiguration().getProgressMonitorService().cancel(uuid);
// configure the job
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+
job.setUser(true);
// schedule job
job.schedule();
} catch (Exception e) {
MessagingUtils.errorDialog("Error executing operation",
AbstractUtility.class,
- "An error occured while executing " + label,
+ "An error occurred while executing " + label,
TaxeditorStorePlugin.PLUGIN_ID,
e,
true);
}
return Status.OK_STATUS;
+ }
+
+ private static Set<Taxon> getTaxaToUpdate(IRemotingProgressMonitor remotingMonitor) {
+ Set<Taxon> taxaToUpdate = new HashSet<>();
+ if (remotingMonitor != null && remotingMonitor.getResult() instanceof UpdateResult){
+ for (CdmBase object: ((UpdateResult)remotingMonitor.getResult()).getUpdatedObjects()){
+ Taxon taxon = null;
+
+ if (object instanceof Taxon){
+ taxon = HibernateProxyHelper.deproxy(object, Taxon.class);
+ }else if (object instanceof Synonym){
+ Synonym syn = HibernateProxyHelper.deproxy(object, Synonym.class);
+ taxon = syn.getAcceptedTaxon();
+ }else if (object instanceof TaxonNode){
+ taxon = ((TaxonNode)object).getTaxon() != null? ((TaxonNode)object).getTaxon():null;
+ }
+ if (taxon != null){
+ taxaToUpdate.add(taxon);
+ }
+ }
}
+ return taxaToUpdate;
+ }
+
+ public static void createResult(String label, boolean showResult,
+ IRemotingProgressMonitor remotingMonitor) {
+ final StringBuilder reportSb = new StringBuilder();
+ if (remotingMonitor == null){
+ reportSb.append("Something went wrong. No result returned from server.");
+ }else if (remotingMonitor.getResult() instanceof ExportResult) {
+ reportSb.append(((ExportResult)remotingMonitor.getResult()).createReport());
+ }else if (remotingMonitor.getResult() instanceof UpdateResult){
+ UpdateResult result = (UpdateResult)remotingMonitor.getResult();
+ createUpdateResultReport(reportSb, result);
+ }else if (remotingMonitor.getReports()!= null){
+ for (String o:remotingMonitor.getReports()){
+ reportSb.append(o);
+ }
+ }
+ String report = reportSb.toString();
+ if(showResult && !StringUtils.isBlank(report)) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ // display reports with possibility to save
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setTitle(label + " Report");
+ dialog.setReportText(report);
+ dialog.open();
+ }
+ });
+ }
+ }
+
+ public static void createUpdateResultReport(final StringBuilder reportSb, UpdateResult result) {
+ if (result.isOk() || result.isAbort()){
+ SetMap<Class<? extends CdmBase>, Integer> map = getUpdateResultStatistics(result);
+ reportSb.append("Update successful. \n"
+ + "Updated Objects: " + map.sizeAll() + "\n================\n");
+ for (Class<? extends CdmBase> clazz : map.keySet()){
+ reportSb.append( CdmUtils.userFriendlyClassName(clazz)+": " + map.get(clazz).size() + "\n");
+ }
+ }
+ if (!result.getExceptions().isEmpty()){
+ reportSb.append(result.getExceptions().toString());
+ }
+ }
-}
+ //TODO move to cdmlib
+ public static SetMap<Class<? extends CdmBase>, Integer> getUpdateResultStatistics(UpdateResult result) {
+ SetMap<Class<? extends CdmBase>, Integer> map = new SetMap<>();
+ for (CdmBase cdmBase : result.getUpdatedObjects()){
+ map.putItem(cdmBase.getClass(), cdmBase.getId());
+ }
+ for (CdmEntityIdentifier entity : result.getUpdatedCdmIds()){
+ map.putItem(entity.getCdmClass(), entity.getId());
+ }
+
+ return map;
+ }
+
+ private static void createExportResult(final String label, String urlString, boolean createZip,
+ IRemotingProgressMonitor remotingMonitor) {
+
+ final StringBuilder reportSb = new StringBuilder();
+ if (remotingMonitor.getResult() instanceof ExportResult){
+ ExportResult result = (ExportResult)remotingMonitor.getResult();
+
+ reportSb.append(result.createReport());
+
+ if(!StringUtils.isBlank(reportSb.toString())) {
+ Display.getDefault().asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ // display reports with possibility to save
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setTitle(label + " Report");
+ dialog.setReportText(reportSb.toString());
+ dialog.open();
+ }
+ });
+ }
+
+ if (urlString != null){
+ 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);
+ Writer out = new BufferedWriter(new OutputStreamWriter(
+ stream, "UTF8"));
+
+ stream.write(exportData);
+ out.flush();
+ 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();
+ SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
+ Calendar cal = Calendar.getInstance();
+ String fileEnding = ".csv";
+
+ if (createZip){
+// File file = new File(urlString+File.separator + sdf.format(cal.getTime())+ ".zip");
+ File file = new File(urlString+ ".zip");
+ FileOutputStream stream = new FileOutputStream(file);
+ 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{
+ if(result.getExportType().equals(ExportType.DWCA)){
+
+ File file = new File(urlString);
+ FileOutputStream stream = new FileOutputStream(file);
+ ZipOutputStream zos = new ZipOutputStream(stream);
+ for (String key: keySet){
+ byte[] fileData = resultMap.get(key);
+ ZipEntry entry = new ZipEntry( key);
+ 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){
+ logger.error(e.getStackTrace());
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ public static void updateNameEditors(Set<Taxon> taxaToUpdate){
+ for (Taxon tax: taxaToUpdate){
+ if (tax != null){
+ EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, tax.getUuid());
+ }
+ }
+ }
+}
\ No newline at end of file