Revision 07b26fc9
Added by Lorna Morris over 11 years ago
.gitattributes | ||
---|---|---|
58 | 58 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/FreshwaterAquaticInsectsUpdateActivator.java -text |
59 | 59 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/LIASActivator.java -text |
60 | 60 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/LIASUpdateActivator.java -text |
61 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/SDDExportActivator.java -text |
|
61 | 62 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/SDDImportActivator.java -text |
62 | 63 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/SDDSources.java -text |
63 | 64 |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/ValRosandraFRIDAKeyActivator.java -text |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/SDDExportActivator.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2009 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 |
package eu.etaxonomy.cdm.app.sdd; |
|
11 |
|
|
12 |
import java.io.File; |
|
13 |
import java.net.MalformedURLException; |
|
14 |
import java.sql.SQLException; |
|
15 |
|
|
16 |
import junit.framework.Assert; |
|
17 |
|
|
18 |
import org.apache.log4j.Logger; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
21 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
22 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
23 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
24 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
|
25 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
|
26 |
import eu.etaxonomy.cdm.io.common.CdmDefaultExport; |
|
27 |
import eu.etaxonomy.cdm.io.common.IExportConfigurator.DO_REFERENCES; |
|
28 |
import eu.etaxonomy.cdm.io.sdd.out.SDDExportConfigurator; |
|
29 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
30 |
|
|
31 |
/** |
|
32 |
* @author l.morris |
|
33 |
* @date 29 Nov 2012 |
|
34 |
* |
|
35 |
*/ |
|
36 |
public class SDDExportActivator { |
|
37 |
|
|
38 |
/* SerializeFrom DB **/ |
|
39 |
private static final String sourceDbName = "cdm"; |
|
40 |
//private static final String destinationFileName = "ViolaFromCDM.xml"; |
|
41 |
//private static final String destinationFolder = "/Developer/exports SDD"; |
|
42 |
//private static final String destinationFolder = "C:/tmp/viola/exports_SDD"; |
|
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 String server = "134.157.190.207"; |
|
51 |
private static final String username = "sa"; |
|
52 |
|
|
53 |
public static ICdmDataSource CDM_DB(String dbname) { |
|
54 |
|
|
55 |
logger.info("Setting DB " + dbname); |
|
56 |
ICdmDataSource datasource = CdmDataSource.NewH2EmbeddedInstance(dbname, username, ""); |
|
57 |
return datasource; |
|
58 |
} |
|
59 |
|
|
60 |
private static ICdmDataSource customDataSource() { |
|
61 |
|
|
62 |
CdmPersistentDataSource loadedDataSource = null; |
|
63 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code); |
|
64 |
|
|
65 |
String dataSourceName = CdmUtils.readInputLine("Database name: "); |
|
66 |
String username = CdmUtils.readInputLine("Username: "); |
|
67 |
String password = CdmUtils.readInputLine("Password: "); |
|
68 |
|
|
69 |
dataSourceName = (dataSourceName.equals("")) ? "cdm_test3" : dataSourceName; |
|
70 |
username = (username.equals("")) ? "ljm" : username; |
|
71 |
|
|
72 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_test3", 3306, "ljm", password, NomenclaturalCode.ICBN); |
|
73 |
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", dataSourceName, 3306, username, password, NomenclaturalCode.ICBN); |
|
74 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_edit_cichorieae", 3306, "ljm", password, NomenclaturalCode.ICBN); |
|
75 |
//ICdmDataSource dataSource = |
|
76 |
CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_edit_cichorieae", 3306, "edit", password, NomenclaturalCode.ICBN); |
|
77 |
boolean connectionAvailable; |
|
78 |
try { |
|
79 |
connectionAvailable = dataSource.testConnection(); |
|
80 |
System.out.println("LORNA connection available " + connectionAvailable); |
|
81 |
Assert.assertTrue("Testdatabase is not available", connectionAvailable); |
|
82 |
|
|
83 |
} catch (ClassNotFoundException e1) { |
|
84 |
// TODO Auto-generated catch block |
|
85 |
e1.printStackTrace(); |
|
86 |
} catch (SQLException e1) { |
|
87 |
// TODO Auto-generated catch block |
|
88 |
e1.printStackTrace(); |
|
89 |
} |
|
90 |
|
|
91 |
CdmPersistentDataSource.save(dataSourceName, dataSource); |
|
92 |
try { |
|
93 |
loadedDataSource = CdmPersistentDataSource.NewInstance(dataSourceName); |
|
94 |
// CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE); |
|
95 |
NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode(); |
|
96 |
|
|
97 |
Assert.assertEquals(NomenclaturalCode.ICBN, loadedCode); |
|
98 |
} catch (DataSourceNotFoundException e) { |
|
99 |
// TODO Auto-generated catch block |
|
100 |
e.printStackTrace(); |
|
101 |
} |
|
102 |
//return loadedDataSource; |
|
103 |
return dataSource; |
|
104 |
} |
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
private static final Logger logger = Logger.getLogger(ViolaExportActivator.class); |
|
109 |
|
|
110 |
//private static final ICdmDataSource sourceDb = ViolaExportActivator.CDM_DB(sourceDbName); |
|
111 |
private static final ICdmDataSource sourceDb = customDataSource(); |
|
112 |
//private static final File destinationFile = new File(destinationFolder + File.separator + destinationFileName); |
|
113 |
|
|
114 |
private static boolean doAgents = true; |
|
115 |
private static boolean doAgentData = true; |
|
116 |
private static boolean doLanguageData = true; |
|
117 |
private static boolean doFeatureData = true; |
|
118 |
private static boolean doDescriptions = true; |
|
119 |
private static boolean doMedia = true; |
|
120 |
private static boolean doOccurrences = true; |
|
121 |
//private static boolean doReferences = true; |
|
122 |
private static final DO_REFERENCES doReferences = DO_REFERENCES.ALL; |
|
123 |
private static boolean doReferencedEntities = true; |
|
124 |
private static boolean doRelationships = false; //causes org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [eu.etaxonomy.cdm.model.taxon.Taxon#24563] in cichoriae |
|
125 |
private static boolean doSynonyms = true; |
|
126 |
private static boolean doTaxonNames = true; |
|
127 |
private static boolean doTaxa = true; |
|
128 |
private static boolean doTerms = true; |
|
129 |
private static boolean doTermVocabularies = true; |
|
130 |
private static boolean doHomotypicalGroups = true;//try export again |
|
131 |
|
|
132 |
private void invokeExport() { |
|
133 |
|
|
134 |
// export data |
|
135 |
//String exporturlStr = "/sdd/SDDImportExportTest.sdd.xml"; |
|
136 |
String exporturlStr = "SDDImportExportTest.sdd.xml"; |
|
137 |
File f = new File(exporturlStr); |
|
138 |
try { |
|
139 |
exporturlStr = f.toURI().toURL().toString(); |
|
140 |
} catch (MalformedURLException e) { |
|
141 |
// TODO Auto-generated catch block |
|
142 |
e.printStackTrace(); |
|
143 |
} |
|
144 |
|
|
145 |
//lorna//SDDExportConfigurator sddExportConfigurator = |
|
146 |
//SDDExportConfigurator.NewInstance(sourceDb, destinationFileName, destinationFolder); |
|
147 |
|
|
148 |
SDDExportConfigurator sddExportConfigurator = |
|
149 |
SDDExportConfigurator.NewInstance(sourceDb, exporturlStr); |
|
150 |
|
|
151 |
|
|
152 |
CdmDefaultExport<SDDExportConfigurator> sddExport = |
|
153 |
new CdmDefaultExport<SDDExportConfigurator>(); |
|
154 |
|
|
155 |
sddExportConfigurator.setSource(sourceDb); |
|
156 |
//lorna//sddExportConfigurator.setDestination(destinationFile); |
|
157 |
sddExportConfigurator.setDbSchemaValidation(DbSchemaValidation.VALIDATE); |
|
158 |
|
|
159 |
sddExportConfigurator.setMaxRows(NUMBER_ROWS_TO_RETRIEVE); |
|
160 |
|
|
161 |
sddExportConfigurator.setDoAuthors(doAgents); |
|
162 |
sddExportConfigurator.setDoAgentData(doAgentData); |
|
163 |
sddExportConfigurator.setDoLanguageData(doLanguageData); |
|
164 |
sddExportConfigurator.setDoFeatureData(doFeatureData); |
|
165 |
sddExportConfigurator.setDoDescriptions(doDescriptions); |
|
166 |
sddExportConfigurator.setDoMedia(doMedia); |
|
167 |
sddExportConfigurator.setDoOccurrence(doOccurrences); |
|
168 |
sddExportConfigurator.setDoReferences(doReferences); |
|
169 |
sddExportConfigurator.setDoReferencedEntities(doReferencedEntities); |
|
170 |
sddExportConfigurator.setDoRelTaxa(doRelationships); |
|
171 |
sddExportConfigurator.setDoSynonyms(doSynonyms); |
|
172 |
sddExportConfigurator.setDoTaxonNames(doTaxonNames); |
|
173 |
sddExportConfigurator.setDoTaxa(doTaxa); |
|
174 |
sddExportConfigurator.setDoTerms(doTerms); |
|
175 |
sddExportConfigurator.setDoTermVocabularies(doTermVocabularies); |
|
176 |
sddExportConfigurator.setDoHomotypicalGroups(doHomotypicalGroups); |
|
177 |
|
|
178 |
// invoke export |
|
179 |
logger.debug("Invoking SDD export"); |
|
180 |
sddExport.invoke(sddExportConfigurator); |
|
181 |
|
|
182 |
} |
|
183 |
|
|
184 |
/** |
|
185 |
* @param args |
|
186 |
*/ |
|
187 |
public static void main(String[] args) { |
|
188 |
|
|
189 |
SDDExportActivator sddex = new SDDExportActivator(); |
|
190 |
|
|
191 |
sddex.invokeExport(); |
|
192 |
|
|
193 |
} |
|
194 |
|
|
195 |
} |
app-import/src/main/java/eu/etaxonomy/cdm/app/sdd/SDDImportActivator.java | ||
---|---|---|
11 | 11 |
|
12 | 12 |
import java.net.URI; |
13 | 13 |
import java.net.URISyntaxException; |
14 |
import java.net.URL; |
|
15 |
import java.sql.SQLException; |
|
16 |
|
|
17 |
import junit.framework.Assert; |
|
14 | 18 |
|
15 | 19 |
import org.apache.log4j.Logger; |
16 | 20 |
|
17 | 21 |
import eu.etaxonomy.cdm.app.common.CdmDestinations; |
22 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
23 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
24 |
import eu.etaxonomy.cdm.database.CdmPersistentDataSource; |
|
25 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
|
18 | 26 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
19 | 27 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
20 | 28 |
import eu.etaxonomy.cdm.io.common.CdmDefaultImport; |
21 | 29 |
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK; |
22 | 30 |
import eu.etaxonomy.cdm.io.sdd.in.SDDImportConfigurator; |
31 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
23 | 32 |
|
24 | 33 |
/** |
25 | 34 |
* @author h.fradin |
35 |
* @author l.morris |
|
26 | 36 |
* @created 24.10.2008 |
27 | 37 |
* @version 1.0 |
28 | 38 |
*/ |
... | ... | |
43 | 53 |
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK; |
44 | 54 |
|
45 | 55 |
|
56 |
private static ICdmDataSource customDataSource() { |
|
57 |
|
|
58 |
CdmPersistentDataSource loadedDataSource = null; |
|
59 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("192.168.2.10", "cdm_test_niels2", 3306, "edit", password, code); |
|
60 |
String dataSourceName = CdmUtils.readInputLine("Database name: "); |
|
61 |
String username = CdmUtils.readInputLine("Username: "); |
|
62 |
String password = CdmUtils.readInputLine("Password: "); |
|
63 |
|
|
64 |
dataSourceName = (dataSourceName.equals("")) ? "cdm_test4" : dataSourceName; |
|
65 |
username = (username.equals("")) ? "ljm" : username; |
|
66 |
|
|
67 |
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", dataSourceName, 3306, username, password, NomenclaturalCode.ICBN); |
|
68 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_edit_cichorieae", 3306, "ljm", password, NomenclaturalCode.ICBN); |
|
69 |
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_edit_cichorieae", 3306, "edit", password, NomenclaturalCode.ICBN); |
|
70 |
boolean connectionAvailable; |
|
71 |
try { |
|
72 |
connectionAvailable = dataSource.testConnection(); |
|
73 |
logger.debug("LORNA connection avaiable " + connectionAvailable); |
|
74 |
Assert.assertTrue("Testdatabase is not available", connectionAvailable); |
|
75 |
|
|
76 |
} catch (ClassNotFoundException e1) { |
|
77 |
// TODO Auto-generated catch block |
|
78 |
e1.printStackTrace(); |
|
79 |
} catch (SQLException e1) { |
|
80 |
// TODO Auto-generated catch block |
|
81 |
e1.printStackTrace(); |
|
82 |
} |
|
83 |
|
|
84 |
CdmPersistentDataSource.save(dataSourceName, dataSource); |
|
85 |
try { |
|
86 |
loadedDataSource = CdmPersistentDataSource.NewInstance(dataSourceName); |
|
87 |
// CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE); |
|
88 |
NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode(); |
|
89 |
|
|
90 |
Assert.assertEquals(NomenclaturalCode.ICBN, loadedCode); |
|
91 |
} catch (DataSourceNotFoundException e) { |
|
92 |
// TODO Auto-generated catch block |
|
93 |
e.printStackTrace(); |
|
94 |
} |
|
95 |
//return loadedDataSource; |
|
96 |
return dataSource; |
|
97 |
} |
|
46 | 98 |
/** |
47 | 99 |
* @param args |
48 | 100 |
*/ |
49 | 101 |
public static void main(String[] args) { |
50 |
String sddSource = SDDSources.SDDImport_local(args[0]+args[1]); |
|
51 |
System.out.println("Start import from SDD("+ sddSource.toString() + ") ..."); |
|
102 |
//String sddSource = SDDSources.SDDImport_local(args[0]+args[1]);
|
|
103 |
//System.out.println("Start import from SDD("+ sddSource.toString() + ") ...");
|
|
52 | 104 |
|
53 | 105 |
//make Source |
54 | 106 |
URI source; |
55 | 107 |
try { |
56 |
source = new URI(sddSource); |
|
108 |
//source = new URI(sddSource); |
|
109 |
//URL url = SDDImportActivator.class.getResource("/eu/etaxonomy/cdm/io/sdd/SDDImportTest-input3.xml"); |
|
110 |
//URL url = SDDImportActivator.class.getResource("/eu/etaxonomy/cdm/app/sdd/SDDImportTest-input3.xml"); //eu.etaxonomy.cdm.app.sdd; |
|
111 |
//URL url = SDDImportActivator.class.getResource("/sdd/SDD-Test-Simple.xml"); |
|
112 |
URL url = SDDImportActivator.class.getResource("/sdd/ant.sdd.xml"); |
|
113 |
//sdd/SDD-Test-Simple.xml |
|
114 |
System.out.println("url"+ url); |
|
115 |
source = url.toURI(); |
|
116 |
//source = new URI("/eu/etaxonomy/cdm/app/sdd/SDDImportTest-input3.xml"); |
|
117 |
System.out.println("Start import from SDD("+ source.toString() + ") ..."); |
|
57 | 118 |
|
58 | 119 |
// ICdmDataSource destination = CdmDestinations.localH2("cdm","sa","C:/Documents and Settings/lis/Mes documents/CDMtest/"); |
59 |
ICdmDataSource destination = CdmDestinations.localH2(args[3],"sa",args[2]); |
|
120 |
//lorna//ICdmDataSource destination = CdmDestinations.localH2(args[3],"sa",args[2]); |
|
121 |
ICdmDataSource destination = customDataSource(); |
|
60 | 122 |
|
61 | 123 |
SDDImportConfigurator sddImportConfigurator = SDDImportConfigurator.NewInstance(source, destination); |
62 | 124 |
|
63 |
sddImportConfigurator.setSourceSecId(sourceSecId); |
|
125 |
///sddImportConfigurator.setSourceSecId(sourceSecId);
|
|
64 | 126 |
|
65 |
sddImportConfigurator.setCheck(check); |
|
66 |
sddImportConfigurator.setDbSchemaValidation(hbm2dll); |
|
127 |
///sddImportConfigurator.setCheck(check);
|
|
128 |
///sddImportConfigurator.setDbSchemaValidation(hbm2dll);
|
|
67 | 129 |
|
68 | 130 |
// invoke import |
69 | 131 |
CdmDefaultImport<SDDImportConfigurator> sddImport = new CdmDefaultImport<SDDImportConfigurator>(); |
Also available in: Unified diff
Updated the SDDImportActivator to use a MySQL datasource. Added an SDDExportActivator to test roundtrip of import and export of SDD into and out of the CDM.