1 |
07b26fc9
|
l.morris
|
// $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 |
bb38665e
|
Andreas Müller
|
ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", dataSourceName, 3306, username, password, NomenclaturalCode.ICNAFP);
|
74 |
07b26fc9
|
l.morris
|
//ICdmDataSource dataSource = CdmDataSource.NewMySqlInstance("127.0.0.1", "cdm_edit_cichorieae", 3306, "ljm", password, NomenclaturalCode.ICBN);
|
75 |
|
|
//ICdmDataSource dataSource =
|
76 |
bb38665e
|
Andreas Müller
|
CdmDataSource.NewMySqlInstance("160.45.63.201", "cdm_edit_cichorieae", 3306, "edit", password, NomenclaturalCode.ICNAFP);
|
77 |
07b26fc9
|
l.morris
|
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 |
993072c0
|
Cherian Mathew
|
// CdmApplicationController.NewInstance(loadedDataSource, DbSchemaValidation.CREATE);
|
95 |
07b26fc9
|
l.morris
|
NomenclaturalCode loadedCode = loadedDataSource.getNomenclaturalCode();
|
96 |
|
|
|
97 |
bb38665e
|
Andreas Müller
|
Assert.assertEquals(NomenclaturalCode.ICNAFP, loadedCode);
|
98 |
07b26fc9
|
l.morris
|
} 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 |
|
|
}
|