-// $Id$
/**
* Copyright (C) 2007 EDIT
* European Distributed Institute of Taxonomy
import java.util.UUID;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.PlatformUI;
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
-import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.api.application.ICdmRepository;
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
+import eu.etaxonomy.cdm.io.common.CacheUpdaterConfigurator;
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
+import eu.etaxonomy.cdm.io.common.ImportConfiguratorBase;
import eu.etaxonomy.cdm.io.common.ImportResult;
+import eu.etaxonomy.cdm.io.common.SortIndexUpdaterConfigurator;
+import eu.etaxonomy.cdm.io.distribution.excelupdate.ExcelDistributionUpdateConfigurator;
+import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
import eu.etaxonomy.cdm.io.excel.taxa.NormalExplicitImportConfigurator;
import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
import eu.etaxonomy.cdm.io.reference.endnote.in.EndnoteImportConfigurator;
import eu.etaxonomy.cdm.io.service.IIOService;
import eu.etaxonomy.cdm.io.specimen.abcd206.in.Abcd206ImportConfigurator;
import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenCdmExcelImportConfigurator;
+import eu.etaxonomy.cdm.io.specimen.gbif.in.GbifImportConfigurator;
+import eu.etaxonomy.cdm.io.specimen.gbif.in.GbifImportState;
import eu.etaxonomy.cdm.io.tcsxml.in.TcsXmlImportConfigurator;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
/**
* @param applicationConfiguration
*/
- private ImportManager(ICdmApplicationConfiguration applicationConfiguration) {
+ private ImportManager(ICdmRepository applicationConfiguration) {
super(applicationConfiguration);
}
* @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
*/
public static ImportManager NewInstance(
- ICdmApplicationConfiguration applicationConfiguration) {
+ ICdmRepository applicationConfiguration) {
return new ImportManager(applicationConfiguration);
}
monitor.beginTask("Importing data", IProgressMonitor.UNKNOWN);
IIOService ioService = CdmApplicationState.getIOService();
- ioService.importData(configurator, data, type);
+ ImportResult result = ioService.importData(configurator, data, type);
monitor.done();
CdmStore.getContextManager().notifyContextRefresh();
}
});
-
+ showResult(configurator.getClass().getSimpleName(), display, result);
return Status.OK_STATUS;
}
};
}
+ public void runMoniteredOperation(IImportConfigurator configurator, SOURCE_TYPE type) {
+ byte[] data = new byte[1];
+ try {
+ runMoniteredOperation(configurator, data, type);
+ } catch (Exception e) {
+ MessagingUtils.errorDialog("Error importing input stream",
+ this,
+ e.getMessage(),
+ TaxeditorStorePlugin.PLUGIN_ID,
+ e,
+ true);
+ }
+
+ }
+
public void runMoniteredOperation(IImportConfigurator configurator, File importFile, SOURCE_TYPE type) {
Path path = Paths.get(importFile.toURI());
try {
return SDDImportConfigurator.NewInstance(null, null);
case SpecimenCdmExcel:
return SpecimenCdmExcelImportConfigurator.NewInstance(null, null);
+ case SpecimenSearch:
+ return Abcd206ImportConfigurator.NewInstance(null, null);
+ case Gbif:
+ return DwcaImportConfigurator.NewInstance(null, null);
+ case Excel_Distribution:
+ return ExcelDistributionUpdateConfigurator.NewInstance(null, null, null);
default:
MessagingUtils.notImplementedMessage(this);
throw new IllegalArgumentException("Import not supported yet");
return (SpecimenCdmExcelImportConfigurator) getConfigurator(TYPE.SpecimenCdmExcel);
}
+ public DwcaImportConfigurator DwcaImportConfigurator() {
+ return (DwcaImportConfigurator) getConfigurator(TYPE.Gbif);
+ }
+
+
/**
* {@inheritDoc}
*/
}
+ public Job createIOServiceJob(final GbifImportConfigurator<GbifImportState, InputStream> configurator) {
+ Assert.isNotNull(configurator, "Configuration may not be null");
+ final Display display = Display.getDefault();
+ Job job = new Job("Import: " + " Dwca") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Importing data", IProgressMonitor.UNKNOWN);
+ IIOService ioService = CdmApplicationState.getIOService();
+
+ ImportResult result = ioService.importDataFromStream(configurator);
+ monitor.done();
+
+// display.asyncExec(new Runnable() {
+//
+// @Override
+// public void run() {
+// CdmStore.getContextManager().notifyContextRefresh();
+// }
+// });
+ showResult("Gbif Import", display, result);
+ return Status.OK_STATUS;
+ }
+ };
+
+ return job;
+
+ }
+
+ public Job createIOServiceJob(final Abcd206ImportConfigurator configurator) {
+ Assert.isNotNull(configurator, "Configuration may not be null");
+ final Display display = Display.getDefault();
+ Job job = new Job("Import: " + " Dwca") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Importing data", IProgressMonitor.UNKNOWN);
+ IIOService ioService = CdmApplicationState.getIOService();
+
+ ImportResult result = ioService.importDataFromStream(configurator);
+ monitor.done();
+
+ display.asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ CdmStore.getContextManager().notifyContextRefresh();
+ }
+ });
+ showResult("Abcd Import", display, result);
+ return Status.OK_STATUS;
+ }
+ };
+
+ return job;
+
+ }
+
+ public Job createIOServiceJob(
+ final List<Abcd206ImportConfigurator> abcdConfigurators) {
+ Assert.isNotNull(abcdConfigurators, "Configuration may not be null");
+ final Display display = Display.getDefault();
+ Job job = new Job("Import: " + " Abcd") {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Importing data", IProgressMonitor.UNKNOWN);
+ IIOService ioService = CdmApplicationState.getIOService();
+
+ ImportResult result = ioService.importDataFromStream(abcdConfigurators);
+ monitor.done();
+
+ display.asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ CdmStore.getContextManager().notifyContextRefresh();
+ }
+ });
+ showResult("Abcd Import", display, result);
+
+
+
+ return Status.OK_STATUS;
+ }
+ };
+
+ return job;
+ }
+
+ public Job createIOServiceJob(final ImportConfiguratorBase configurator) {
+ Assert.isNotNull(configurator, "Configuration may not be null");
+ final Display display = Display.getDefault();
+
+ Job job = new Job("Update: " + configurator.getClass().getSimpleName()) {
+
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ monitor.beginTask("Updating data", IProgressMonitor.UNKNOWN);
+ IIOService ioService = CdmApplicationState.getIOService();
+ ImportResult importResult = null;
+ if (configurator instanceof SortIndexUpdaterConfigurator){
+ SortIndexUpdaterConfigurator config = (SortIndexUpdaterConfigurator)configurator;
+ importResult =ioService.updateSortIndex(config);
+ } else if (configurator instanceof CacheUpdaterConfigurator){
+ CacheUpdaterConfigurator config = (CacheUpdaterConfigurator) configurator;
+ importResult = ioService.updateCaches(config);
+ } else if (configurator instanceof ExcelDistributionUpdateConfigurator){
+ ExcelDistributionUpdateConfigurator config = (ExcelDistributionUpdateConfigurator) configurator;
+ importResult =ioService.updateDistributionData(config);
+ }
+
+ monitor.done();
+// display.asyncExec(new Runnable() {
+//
+// @Override
+// public void run() {
+// CdmStore.getContextManager().notifyContextRefresh();
+// }
+// });
+ showResult(configurator.getClass().getSimpleName(), display, importResult);
+
+
+ return Status.OK_STATUS;
+ }
+
+
+ };
+
+ return job;
+
+ }
+
+ /**
+ * @return
+ */
+ public ExcelDistributionUpdateConfigurator ExcelDistributionUpdateConfigurator() {
+ return (ExcelDistributionUpdateConfigurator) getConfigurator(TYPE.Excel_Distribution);
+ }
+
+ /**
+ * @param configurator
+ * @param display
+ * @param importResult
+ */
+ private void showResult(String importName, final Display display,
+ ImportResult importResult) {
+ StringBuffer reportTextTemp = importResult.createReport();
+ final StringBuffer reportText;
+ if (StringUtils.isBlank(reportTextTemp.toString())){
+ reportTextTemp.append("No update result available");
+ //TODO: this is a workaround because the abcd import writes the report in the report part...
+ if (!importResult.getReports().isEmpty()){
+ reportTextTemp = new StringBuffer();
+ if(importResult!=null){
+ List<byte[]> reports = importResult.getReports();
+ for (byte[] bs : reports) {
+ reportTextTemp.append(new String(bs));
+ }
+ }
+ }
+ }
+ reportText = reportTextTemp;
+ display.asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ // display reports with possibility to save
+ ReportTextDialog dialog = new ReportTextDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ dialog.setTitle(importName+" Report");
+ dialog.setReportText(reportText.toString());
+ dialog.open();
+ CdmStore.getContextManager().notifyContextRefresh();
+ }
+ });
+ }
+
+
}