17 |
17 |
import java.io.OutputStreamWriter;
|
18 |
18 |
import java.io.Writer;
|
19 |
19 |
import java.text.SimpleDateFormat;
|
|
20 |
import java.util.ArrayList;
|
20 |
21 |
import java.util.Calendar;
|
21 |
22 |
import java.util.List;
|
22 |
23 |
import java.util.Map;
|
23 |
24 |
import java.util.Set;
|
|
25 |
import java.util.UUID;
|
24 |
26 |
import java.util.zip.ZipEntry;
|
25 |
27 |
import java.util.zip.ZipOutputStream;
|
26 |
28 |
|
... | ... | |
37 |
39 |
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
|
38 |
40 |
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
39 |
41 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
|
42 |
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
|
40 |
43 |
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
|
41 |
44 |
import eu.etaxonomy.cdm.io.common.ExportDataWrapper;
|
42 |
45 |
import eu.etaxonomy.cdm.io.common.ExportResult;
|
43 |
46 |
import eu.etaxonomy.cdm.io.common.ExportResultType;
|
44 |
47 |
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
|
48 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
45 |
49 |
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
46 |
|
|
|
50 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.SOURCE_TYPE;
|
|
51 |
import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
|
47 |
52 |
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
48 |
53 |
import eu.etaxonomy.cdm.io.cdmLight.CdmLightExportConfigurator;
|
49 |
54 |
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator;
|
50 |
55 |
import eu.etaxonomy.cdm.io.service.IIOService;
|
|
56 |
import eu.etaxonomy.taxeditor.model.AbstractUtility;
|
51 |
57 |
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
|
52 |
58 |
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
|
59 |
|
|
60 |
import eu.etaxonomy.taxeditor.operation.FeedbackGenerator;
|
|
61 |
import eu.etaxonomy.taxeditor.operation.IFeedbackGenerator;
|
|
62 |
import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled;
|
|
63 |
import eu.etaxonomy.taxeditor.store.CdmStore;
|
53 |
64 |
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
54 |
65 |
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
|
55 |
66 |
|
... | ... | |
62 |
73 |
* @created Sep 11, 2009
|
63 |
74 |
* @version 1.0
|
64 |
75 |
*/
|
65 |
|
public class ExportManager extends AbstractIOManager<IExportConfigurator> {
|
|
76 |
public class ExportManager extends AbstractIOManager<IExportConfigurator> implements IPostMoniteredOperationEnabled {
|
66 |
77 |
|
67 |
78 |
private final String successMessage = "The export was successfull";
|
68 |
79 |
|
... | ... | |
197 |
208 |
monitor.beginTask("Exporting database. This will take some time.", IProgressMonitor.UNKNOWN);
|
198 |
209 |
try {
|
199 |
210 |
IIOService ioService = CdmApplicationState.getIOService();
|
200 |
|
|
201 |
|
ExportResult result = ioService.export(configurator);
|
|
211 |
UUID uuid = ioService.monitExportData(configurator);
|
|
212 |
IRemotingProgressMonitor remotingMonitor;
|
|
213 |
List<IFeedbackGenerator> feedBackGeneratorList = new ArrayList<IFeedbackGenerator>();
|
|
214 |
try {
|
|
215 |
remotingMonitor = CdmStore.getProgressMonitorClientManager().pollMonitor("Export Data",
|
|
216 |
uuid,
|
|
217 |
1000,
|
|
218 |
ExportManager.this,
|
|
219 |
feedBackGeneratorList,
|
|
220 |
monitor);
|
|
221 |
|
|
222 |
} catch (Exception ex) {
|
|
223 |
return new Status(Status.ERROR, TaxeditorStorePlugin.PLUGIN_ID, "Operation Interrupted", ex);
|
|
224 |
}
|
|
225 |
|
|
226 |
ExportResult result = (ExportResult)remotingMonitor.getResult();
|
202 |
227 |
ExportDataWrapper data = result.getExportData();
|
203 |
228 |
try{
|
204 |
229 |
if (result.getExportData().getType().equals(ExportResultType.BYTE_ARRAY)){
|
... | ... | |
207 |
232 |
FileOutputStream stream = new FileOutputStream(exportFile);
|
208 |
233 |
stream.write(exportData);
|
209 |
234 |
stream.close();
|
|
235 |
}
|
|
236 |
} else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
|
|
237 |
Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
|
|
238 |
Set<String> keySet = resultMap.keySet();
|
|
239 |
SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
|
|
240 |
Calendar cal = Calendar.getInstance();
|
|
241 |
String fileEnding = ".zip";
|
|
242 |
if (configurator instanceof DwcaTaxExportConfigurator){
|
|
243 |
DwcaTaxExportConfigurator dwcaConfig = (DwcaTaxExportConfigurator)configurator;
|
|
244 |
|
|
245 |
File file = new File(dwcaConfig.getDestination().toURI());
|
|
246 |
FileOutputStream stream = new FileOutputStream(file);
|
|
247 |
ZipOutputStream zos = new ZipOutputStream(stream);
|
|
248 |
for (String key: keySet){
|
|
249 |
byte[] fileData = resultMap.get(key);
|
|
250 |
ZipEntry entry = new ZipEntry( key + fileEnding);
|
|
251 |
zos.putNextEntry(entry);
|
|
252 |
zos.write(fileData);
|
|
253 |
zos.closeEntry();
|
|
254 |
}
|
|
255 |
zos.close();
|
210 |
256 |
}
|
211 |
|
// } else if (result.getExportData().getType().equals(ExportResultType.MAP_BYTE_ARRAY)){
|
212 |
|
// Map<String, byte[]> resultMap = (Map<String, byte[]>)data.getExportData();
|
213 |
|
// Set<String> keySet = resultMap.keySet();
|
214 |
|
// for (String key: keySet){
|
215 |
|
// byte[] fileData = resultMap.get(key);
|
216 |
|
// File file = new File(urlString)
|
217 |
|
// FileOutputStream stream = new FileOutputStream(key);
|
218 |
|
// stream.write(fileData);
|
219 |
|
// stream.close();
|
220 |
|
// }
|
221 |
|
|
222 |
|
}else{
|
|
257 |
} else{
|
223 |
258 |
logger.error("This kind of result data is not supported yet." + result.getExportData().getType().toString());
|
224 |
259 |
}
|
|
260 |
|
225 |
261 |
} catch(Exception e){
|
226 |
262 |
logger.error(e.getStackTrace());
|
227 |
263 |
}
|
... | ... | |
368 |
404 |
return job;
|
369 |
405 |
}
|
370 |
406 |
|
|
407 |
public void runMoniteredOperation(final IExportConfigurator configurator) {
|
|
408 |
IIOService ioService = CdmApplicationState.getIOService();
|
|
409 |
final UUID uuid = ioService.monitExportData(configurator);
|
|
410 |
Display.getDefault().asyncExec(new Runnable() {
|
|
411 |
@Override
|
|
412 |
public void run() {
|
|
413 |
AbstractUtility.executeMoniteredOperation("Export: " + configurator.getClass().getSimpleName(),
|
|
414 |
uuid,
|
|
415 |
1000,
|
|
416 |
false,
|
|
417 |
ExportManager.this,
|
|
418 |
null);
|
|
419 |
}
|
|
420 |
});
|
|
421 |
|
|
422 |
}
|
371 |
423 |
|
|
424 |
@Override
|
|
425 |
public void postOperation(IRemotingProgressMonitor monitor) {
|
|
426 |
Display.getDefault().asyncExec(new Runnable() {
|
|
427 |
|
|
428 |
@Override
|
|
429 |
public void run() {
|
|
430 |
CdmStore.getContextManager().notifyContextRefresh();
|
|
431 |
}
|
|
432 |
});
|
|
433 |
|
|
434 |
}
|
372 |
435 |
|
373 |
436 |
}
|
ref #6801: byte array as result was not handled