1
|
/**
|
2
|
* Copyright (C) 2008 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*/
|
6
|
|
7
|
package eu.etaxonomy.cdm.io.common;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
|
11
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
12
|
import eu.etaxonomy.cdm.io.jaxb.JaxbExportConfigurator;
|
13
|
|
14
|
/**
|
15
|
* @author a.babadshanjan
|
16
|
* @created 17.11.2008
|
17
|
*/
|
18
|
public class CdmDefaultExport<T extends IExportConfigurator> implements ICdmExport<T> {
|
19
|
|
20
|
private static final Logger logger = Logger.getLogger(CdmDefaultExport.class);
|
21
|
|
22
|
public boolean invoke(IExportConfigurator config){
|
23
|
if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_ONLY)){
|
24
|
return doCheck(config);
|
25
|
}else if (config.getCheck().equals(IExportConfigurator.CHECK.CHECK_AND_EXPORT)){
|
26
|
doCheck(config);
|
27
|
return doExport(config);
|
28
|
}else if (config.getCheck().equals(IExportConfigurator.CHECK.EXPORT_WITHOUT_CHECK)){
|
29
|
return doExport(config);
|
30
|
}else{
|
31
|
logger.error("Unknown CHECK type");
|
32
|
return false;
|
33
|
}
|
34
|
}
|
35
|
|
36
|
|
37
|
protected boolean doCheck(IExportConfigurator config){
|
38
|
boolean result = true;
|
39
|
System.out.println("Start checking Source ("+ config.getDestinationNameString() + ") ...");
|
40
|
|
41
|
//check
|
42
|
if (config == null){
|
43
|
logger.warn("CdmExportConfiguration is null");
|
44
|
return false;
|
45
|
}else if (!config.isValid()){
|
46
|
logger.warn("CdmExportConfiguration is not valid");
|
47
|
return false;
|
48
|
}
|
49
|
|
50
|
//do check for each class
|
51
|
for (Class<ICdmIoExport> ioClass: config.getIoClassList()){
|
52
|
ICdmIoExport cdmIo = null;
|
53
|
try {
|
54
|
cdmIo = ioClass.newInstance();
|
55
|
result &= cdmIo.check(config);
|
56
|
} catch (Exception e) {
|
57
|
logger.error(e);
|
58
|
e.printStackTrace();
|
59
|
}
|
60
|
}
|
61
|
|
62
|
//return
|
63
|
System.out.println("End checking Source ("+ config.getDestinationNameString() + ") for Export to CDM");
|
64
|
return result;
|
65
|
|
66
|
}
|
67
|
|
68
|
|
69
|
/**
|
70
|
* Executes the whole
|
71
|
*/
|
72
|
protected boolean doExport(IExportConfigurator config){
|
73
|
CdmApplicationController cdmApp;
|
74
|
boolean result = true;
|
75
|
if (config == null){
|
76
|
logger.warn("Configuration is null");
|
77
|
return false;
|
78
|
}else if (! config.isValid()){
|
79
|
logger.warn("Configuration is not valid");
|
80
|
return false;
|
81
|
}
|
82
|
// cdmApp = config.getCdmAppController();
|
83
|
// For Jaxb import, omit term loading
|
84
|
if (config instanceof JaxbExportConfigurator) {
|
85
|
cdmApp = config.getCdmAppController(true, true);
|
86
|
} else {
|
87
|
cdmApp = config.getCdmAppController(true, false);
|
88
|
}
|
89
|
|
90
|
System.out.println("Start export from Cdm (" + cdmApp.getDatabaseService().getUrl() +
|
91
|
") to Destination (" + config.getDestinationNameString() + ") ...");
|
92
|
|
93
|
//do invoke for each class
|
94
|
// TODO: Replace ICdmIoExport by ICdmIO
|
95
|
for (Class<ICdmIoExport> ioClass: config.getIoClassList()){
|
96
|
ICdmIoExport cdmIo = null;
|
97
|
try {
|
98
|
cdmIo = ioClass.newInstance();
|
99
|
result &= cdmIo.invoke(config);
|
100
|
} catch (Exception e) {
|
101
|
logger.error(e);
|
102
|
e.printStackTrace();
|
103
|
}
|
104
|
}
|
105
|
|
106
|
//return
|
107
|
System.out.println("End export from Cdm (" + cdmApp.getDatabaseService().getUrl() +
|
108
|
") to Destination (" + config.getDestinationNameString() + ") ...");
|
109
|
return true;
|
110
|
}
|
111
|
|
112
|
|
113
|
}
|