1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.io;
|
12
|
|
13
|
import java.lang.reflect.InvocationTargetException;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.eclipse.core.runtime.Assert;
|
17
|
import org.eclipse.core.runtime.IProgressMonitor;
|
18
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
19
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
22
|
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
|
23
|
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
|
24
|
import eu.etaxonomy.cdm.io.common.IExportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.common.IIoConfigurator;
|
26
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.sdd.SDDExportConfigurator;
|
28
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
29
|
|
30
|
/**
|
31
|
* @author n.hoffmann
|
32
|
* @created Sep 11, 2009
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class ExportHandler extends AbstractIOHandler{
|
36
|
private static final Logger logger = Logger
|
37
|
.getLogger(ExportHandler.class);
|
38
|
|
39
|
/**
|
40
|
*
|
41
|
* @param applicationController
|
42
|
*/
|
43
|
private ExportHandler(CdmApplicationController applicationController){
|
44
|
super(applicationController);
|
45
|
}
|
46
|
|
47
|
/**
|
48
|
*
|
49
|
* @param applicationController
|
50
|
* @return
|
51
|
*/
|
52
|
public static ExportHandler NewInstance(CdmApplicationController applicationController){
|
53
|
return new ExportHandler(applicationController);
|
54
|
}
|
55
|
|
56
|
/**
|
57
|
* Starts the export process
|
58
|
*
|
59
|
* @param configurator
|
60
|
*/
|
61
|
public void run(final IExportConfigurator configurator){
|
62
|
ProgressMonitorDialog dialog = new ProgressMonitorDialog(StoreUtil.getShell());
|
63
|
|
64
|
try {
|
65
|
dialog.run(false, true, new IRunnableWithProgress() {
|
66
|
|
67
|
/*
|
68
|
* (non-Javadoc)
|
69
|
* @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
|
70
|
*/
|
71
|
public void run(IProgressMonitor monitor)
|
72
|
throws InvocationTargetException, InterruptedException {
|
73
|
doExport(monitor, configurator);
|
74
|
}
|
75
|
});
|
76
|
}catch (InvocationTargetException e) {
|
77
|
logger.error(e);
|
78
|
throw new RuntimeException(e);
|
79
|
} catch (InterruptedException e) {
|
80
|
logger.error(e);
|
81
|
throw new RuntimeException(e);
|
82
|
}
|
83
|
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
*
|
88
|
* @param monitor
|
89
|
* @param configurator
|
90
|
*/
|
91
|
private void doExport(IProgressMonitor monitor, IExportConfigurator configurator){
|
92
|
|
93
|
Assert.isNotNull(configurator, "Configuration may not be null");
|
94
|
|
95
|
monitor.beginTask("Exporting database. This will take some time.", 100);
|
96
|
monitor.worked(10);
|
97
|
|
98
|
// terminate any open transactions
|
99
|
IConversationEnabled activePart = (IConversationEnabled) StoreUtil.getActivePage().getActivePart();
|
100
|
activePart.getConversationHolder().commit(false);
|
101
|
monitor.worked(10);
|
102
|
|
103
|
CdmDefaultExport<IExportConfigurator> exporter = new CdmDefaultExport<IExportConfigurator>();
|
104
|
|
105
|
exporter.setCdmAppController(applicationController);
|
106
|
monitor.worked(10);
|
107
|
|
108
|
try{
|
109
|
exporter.invoke(configurator);
|
110
|
monitor.worked(60);
|
111
|
}catch(RuntimeException e){
|
112
|
StoreUtil.errorDialog("Error exporting data", "An error occured while" +
|
113
|
"exporting to destination '" + configurator.getDestinationNameString() + "'.\n" +
|
114
|
"Please check error log for details.");
|
115
|
logger.error("Error exporting data", e);
|
116
|
}
|
117
|
|
118
|
// restarting transaction and committing it to trigger change listener
|
119
|
// TODO verify correct behaviour
|
120
|
activePart.getConversationHolder().startTransaction();
|
121
|
activePart.getConversationHolder().commit();
|
122
|
monitor.worked(10);
|
123
|
}
|
124
|
|
125
|
/**
|
126
|
* @param jaxb
|
127
|
* @return
|
128
|
*/
|
129
|
private IIoConfigurator getConfigurator(TYPE type) {
|
130
|
Assert.isNotNull(type, "Type should not be null");
|
131
|
|
132
|
switch (type){
|
133
|
case Jaxb:
|
134
|
return JaxbExportConfigurator.NewInstance(null, null);
|
135
|
case Sdd:
|
136
|
return SDDExportConfigurator.NewInstance(null, null, null);
|
137
|
default:
|
138
|
StoreUtil.notImplementedMessage();
|
139
|
throw new IllegalArgumentException("Export not supported yet");
|
140
|
}
|
141
|
}
|
142
|
|
143
|
/**
|
144
|
*
|
145
|
* @return
|
146
|
*/
|
147
|
public final JaxbExportConfigurator JaxbConfigurator() { return (JaxbExportConfigurator) getConfigurator(TYPE.Jaxb); }
|
148
|
|
149
|
public final SDDExportConfigurator SddConfigurator() { return (SDDExportConfigurator) getConfigurator(TYPE.Sdd); }
|
150
|
|
151
|
}
|