1
|
/**
|
2
|
* Copyright (C) 2008 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.app.jaxb;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.net.URISyntaxException;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.application.CdmApplicationDefaultController;
|
18
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
19
|
import eu.etaxonomy.cdm.app.util.TestDatabase;
|
20
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
21
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
22
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
23
|
import eu.etaxonomy.cdm.io.jaxb.JaxbImportConfigurator;
|
24
|
|
25
|
/**
|
26
|
* @author a.babadshanjan
|
27
|
* @created 25.09.2008
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class JaxbImportActivator {
|
31
|
|
32
|
/* SerializeFrom DB **/
|
33
|
//private static final ICdmDataSource cdmSource = CdmDestinations.localH2Diptera();
|
34
|
private static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
35
|
|
36
|
|
37
|
// Import:
|
38
|
private static String importFileNameString =
|
39
|
//"C:\\workspace\\cdmlib_2.2\\cdmlib-io\\src\\test\\resources\\eu\\etaxonomy\\cdm\\io\\jaxb\\export_test_app_import.xml";
|
40
|
// "file:/C:/export_test_app_import.xml";
|
41
|
"file:/C:/localCopy/Data/kr�hen/201206141338-jaxb_export-cdm.xml";
|
42
|
|
43
|
|
44
|
/** NUMBER_ROWS_TO_RETRIEVE = 0 is the default case to retrieve all rows.
|
45
|
* For testing purposes: If NUMBER_ROWS_TO_RETRIEVE >0 then retrieve
|
46
|
* as many rows as specified for agents, references, etc.
|
47
|
* Only root taxa and no synonyms and relationships are retrieved. */
|
48
|
private static final int NUMBER_ROWS_TO_RETRIEVE = 0;
|
49
|
|
50
|
private static final Logger logger = Logger.getLogger(JaxbImportActivator.class);
|
51
|
|
52
|
|
53
|
public static String chooseFile(String[] args) {
|
54
|
if(args == null)
|
55
|
return null;
|
56
|
for (String dest: args){
|
57
|
if (dest.endsWith(".xml")){
|
58
|
return args[0];
|
59
|
}
|
60
|
}
|
61
|
return null;
|
62
|
}
|
63
|
|
64
|
private void invokeImport(String importFileParamString, ICdmDataSource destination) {
|
65
|
try {
|
66
|
JaxbImportConfigurator jaxbImportConfigurator;
|
67
|
if (importFileParamString !=null && destination != null){
|
68
|
URI importFileParam;
|
69
|
importFileParam = new URI(importFileParamString);
|
70
|
jaxbImportConfigurator = JaxbImportConfigurator.NewInstance(importFileParam, destination);
|
71
|
}else if (destination != null){
|
72
|
URI importFileName = new URI(importFileNameString);
|
73
|
jaxbImportConfigurator = JaxbImportConfigurator.NewInstance(importFileName, destination);
|
74
|
} else if (importFileParamString !=null ){
|
75
|
URI importFileParam = new URI(importFileParamString);
|
76
|
jaxbImportConfigurator = JaxbImportConfigurator.NewInstance(importFileParam, cdmDestination);
|
77
|
} else{
|
78
|
URI importFileName = new URI(importFileNameString);
|
79
|
jaxbImportConfigurator = JaxbImportConfigurator.NewInstance(importFileName, cdmDestination);
|
80
|
}
|
81
|
|
82
|
CdmDefaultImport<JaxbImportConfigurator> jaxbImport =
|
83
|
new CdmDefaultImport<JaxbImportConfigurator>();
|
84
|
|
85
|
|
86
|
// invoke import
|
87
|
logger.debug("Invoking Jaxb import");
|
88
|
|
89
|
jaxbImport.invoke(jaxbImportConfigurator, destination, true);
|
90
|
} catch (URISyntaxException e) {
|
91
|
e.printStackTrace();
|
92
|
}
|
93
|
|
94
|
|
95
|
}
|
96
|
|
97
|
|
98
|
private CdmApplicationDefaultController initDb(ICdmDataSource db) {
|
99
|
|
100
|
// Init source DB
|
101
|
CdmApplicationDefaultController appCtrInit = null;
|
102
|
|
103
|
appCtrInit = TestDatabase.initDb(db, DbSchemaValidation.CREATE, false);
|
104
|
|
105
|
return appCtrInit;
|
106
|
}
|
107
|
|
108
|
|
109
|
// Load test data to DB
|
110
|
private void loadTestData(CdmApplicationDefaultController appCtrInit) {
|
111
|
|
112
|
TestDatabase.loadTestData("", appCtrInit);
|
113
|
}
|
114
|
|
115
|
|
116
|
/**
|
117
|
* @param args
|
118
|
*/
|
119
|
public static void main(String[] args) {
|
120
|
|
121
|
JaxbImportActivator jia = new JaxbImportActivator();
|
122
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
123
|
String file = chooseFile(args)!= null ? chooseFile(args) : importFileNameString;
|
124
|
CdmApplicationDefaultController appCtr = null;
|
125
|
// appCtr = jia.initDb(destination);
|
126
|
|
127
|
jia.invokeImport(file, destination);
|
128
|
}
|
129
|
|
130
|
}
|