Revision f3e1e1fa
Added by Katja Luther about 7 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/ExportManager.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.io.File; |
13 | 13 |
import java.io.FileOutputStream; |
14 |
import java.util.Map; |
|
15 |
import java.util.Set; |
|
14 | 16 |
|
15 | 17 |
import org.apache.log4j.Logger; |
16 | 18 |
import org.eclipse.core.runtime.Assert; |
... | ... | |
27 | 29 |
import eu.etaxonomy.cdm.io.common.CdmDefaultExport; |
28 | 30 |
import eu.etaxonomy.cdm.io.common.ExportDataWrapper; |
29 | 31 |
import eu.etaxonomy.cdm.io.common.ExportResult; |
32 |
import eu.etaxonomy.cdm.io.common.ExportResultType; |
|
30 | 33 |
import eu.etaxonomy.cdm.io.common.IExportConfigurator; |
31 | 34 |
import eu.etaxonomy.cdm.io.common.IIoConfigurator; |
32 | 35 |
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator; |
36 |
import eu.etaxonomy.cdm.io.outputmodel.OutputModelConfigurator; |
|
33 | 37 |
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator; |
34 | 38 |
import eu.etaxonomy.cdm.io.service.IIOService; |
35 | 39 |
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter; |
... | ... | |
182 | 186 |
ExportResult result = ioService.export(configurator); |
183 | 187 |
ExportDataWrapper data = result.getExportData(); |
184 | 188 |
try{ |
185 |
byte[] exportData = (byte[])data.getExportData(); |
|
186 |
if(exportData != null){ |
|
187 |
FileOutputStream stream = new FileOutputStream(exportFile); |
|
188 |
stream.write(exportData); |
|
189 |
stream.close(); |
|
190 |
} |
|
189 |
if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){ |
|
190 |
byte[] exportData = (byte[])data.getExportData(); |
|
191 |
if(exportData != null){ |
|
192 |
FileOutputStream stream = new FileOutputStream(exportFile); |
|
193 |
stream.write(exportData); |
|
194 |
stream.close(); |
|
195 |
} |
|
196 |
// } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){ |
|
197 |
// Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData(); |
|
198 |
// Set<String> keySet = resultMap.keySet(); |
|
199 |
// for (String key: keySet){ |
|
200 |
// byte[] fileData = resultMap.get(key); |
|
201 |
// File file = new File(urlString) |
|
202 |
// FileOutputStream stream = new FileOutputStream(key); |
|
203 |
// stream.write(fileData); |
|
204 |
// stream.close(); |
|
205 |
// } |
|
206 |
|
|
207 |
}else{ |
|
208 |
logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString()); |
|
209 |
} |
|
191 | 210 |
} catch(Exception e){ |
192 | 211 |
logger.error(e.getStackTrace()); |
193 | 212 |
} |
... | ... | |
249 | 268 |
return (SDDExportConfigurator) getConfigurator(TYPE.Sdd); |
250 | 269 |
} |
251 | 270 |
|
271 |
/** |
|
272 |
* @param configurator |
|
273 |
* @param urlString |
|
274 |
* @return |
|
275 |
*/ |
|
276 |
public Job createIOServiceJob(OutputModelConfigurator configurator, String urlString) { |
|
277 |
Assert.isNotNull(configurator, "Configuration may not be null"); |
|
278 |
|
|
279 |
// final Display display = Display.getCurrent(); |
|
280 |
|
|
281 |
Job job = new Job("Export: " + configurator.getClass().getSimpleName()) { //$NON-NLS-1$ |
|
282 |
@Override |
|
283 |
protected IStatus run(IProgressMonitor monitor) { |
|
284 |
monitor.beginTask("Exporting database. This will take some time.", IProgressMonitor.UNKNOWN); |
|
285 |
try { |
|
286 |
IIOService ioService = CdmApplicationState.getIOService(); |
|
287 |
|
|
288 |
ExportResult result = ioService.export(configurator); |
|
289 |
ExportDataWrapper data = result.getExportData(); |
|
290 |
try{ |
|
291 |
if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){ |
|
292 |
byte[] exportData = (byte[])data.getExportData(); |
|
293 |
if(exportData != null){ |
|
294 |
File file = new File(urlString); |
|
295 |
FileOutputStream stream = new FileOutputStream(file); |
|
296 |
stream.write(exportData); |
|
297 |
stream.close(); |
|
298 |
} |
|
299 |
} else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){ |
|
300 |
Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData(); |
|
301 |
Set<String> keySet = resultMap.keySet(); |
|
302 |
for (String key: keySet){ |
|
303 |
byte[] fileData = resultMap.get(key); |
|
304 |
String fileEnding =""; |
|
305 |
if (configurator instanceof OutputModelConfigurator){ |
|
306 |
fileEnding = ".csv"; |
|
307 |
} |
|
308 |
File file = new File(urlString+File.separator + key + fileEnding); |
|
309 |
FileOutputStream stream = new FileOutputStream(file); |
|
310 |
stream.write(fileData); |
|
311 |
stream.close(); |
|
312 |
} |
|
313 |
|
|
314 |
}else{ |
|
315 |
logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString()); |
|
316 |
} |
|
317 |
} catch(Exception e){ |
|
318 |
logger.error(e.getStackTrace()); |
|
319 |
} |
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
} catch (Exception e) { |
|
325 |
MessagingUtils.errorDialog("Error exporting data", |
|
326 |
this, |
|
327 |
e.getMessage(), |
|
328 |
TaxeditorStorePlugin.PLUGIN_ID, |
|
329 |
e, |
|
330 |
true); |
|
331 |
} |
|
332 |
return Status.OK_STATUS; |
|
333 |
} |
|
334 |
}; |
|
335 |
return job; |
|
336 |
} |
|
337 |
|
|
252 | 338 |
|
253 | 339 |
|
254 | 340 |
} |
Also available in: Unified diff
ref #6314: adaption to changes in exports