1 |
6a915f5e
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 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.vibrant;
|
11 |
|
|
|
12 |
512f31a5
|
Andreas Müller
|
import java.lang.reflect.Method;
|
13 |
|
|
import java.sql.ResultSet;
|
14 |
|
|
import java.sql.SQLException;
|
15 |
6a915f5e
|
Andreas Müller
|
import java.util.UUID;
|
16 |
|
|
|
17 |
|
|
import org.apache.log4j.Logger;
|
18 |
|
|
|
19 |
5f289246
|
Andreas Müller
|
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;
|
20 |
6a915f5e
|
Andreas Müller
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
21 |
|
|
import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
|
22 |
|
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23 |
|
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
25 |
|
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
28 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
29 |
|
|
import eu.etaxonomy.cdm.io.common.Source;
|
30 |
512f31a5
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.ExtensionType;
|
31 |
6a915f5e
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
32 |
512f31a5
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
33 |
6a915f5e
|
Andreas Müller
|
|
34 |
|
|
|
35 |
|
|
/**
|
36 |
|
|
* TODO add the following to a wiki page:
|
37 |
|
|
* HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
|
38 |
|
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
39 |
|
|
*
|
40 |
|
|
*
|
41 |
|
|
* @author a.mueller
|
42 |
|
|
*
|
43 |
|
|
*/
|
44 |
|
|
public class MclActivator {
|
45 |
|
|
private static final Logger logger = Logger.getLogger(MclActivator.class);
|
46 |
|
|
|
47 |
|
|
//database validation status (create, update, validate ...)
|
48 |
|
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
49 |
|
|
static final Source berlinModelSource = BerlinModelSources.mcl();
|
50 |
|
|
|
51 |
512f31a5
|
Andreas Müller
|
static final ICdmDataSource cdmDestination = VibrantActivator.cdm_test_local_vibrant();
|
52 |
6a915f5e
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
53 |
|
|
|
54 |
|
|
static final boolean useSingleClassification = true;
|
55 |
|
|
static final int sourceSecId = 1272;
|
56 |
|
|
static final UUID classificationUuid = UUID.fromString("ba6efd26-5b45-4ce6-915d-4f9576e0bf0a");
|
57 |
|
|
|
58 |
|
|
static final UUID sourceRefUuid = UUID.fromString("ca8b25d6-e251-4d2b-8b45-142e1e6448f7");
|
59 |
|
|
|
60 |
|
|
// set to zero for unlimited nameFacts
|
61 |
|
|
static final int maximumNumberOfNameFacts = 0;
|
62 |
|
|
|
63 |
|
|
static final int partitionSize = 5000;
|
64 |
|
|
|
65 |
|
|
//check - import
|
66 |
|
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
67 |
|
|
|
68 |
|
|
//editor - import
|
69 |
|
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
70 |
|
|
|
71 |
|
|
//NomeclaturalCode
|
72 |
|
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
|
73 |
|
|
|
74 |
|
|
//ignore null
|
75 |
|
|
static final boolean ignoreNull = true;
|
76 |
|
|
|
77 |
|
|
static boolean useClassification = true;
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
// **************** ALL *********************
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
//authors
|
84 |
|
|
static final boolean doAuthors = true;
|
85 |
|
|
//references
|
86 |
|
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
87 |
|
|
//names
|
88 |
|
|
static final boolean doTaxonNames = true;
|
89 |
|
|
static final boolean doRelNames = true;
|
90 |
|
|
static final boolean doNameStatus = true;
|
91 |
|
|
|
92 |
|
|
//taxa
|
93 |
|
|
static final boolean doTaxa = true;
|
94 |
|
|
static final boolean doRelTaxa = true;
|
95 |
|
|
static final boolean doFacts = true;
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
// **************** SELECTED *********************
|
100 |
|
|
|
101 |
|
|
// //authors
|
102 |
|
|
// static final boolean doAuthors = false;
|
103 |
|
|
// //references
|
104 |
|
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
105 |
|
|
// //names
|
106 |
|
|
// static final boolean doTaxonNames = false;
|
107 |
|
|
// static final boolean doRelNames = false;
|
108 |
|
|
// static final boolean doNameStatus = false;
|
109 |
|
|
//
|
110 |
|
|
// //taxa
|
111 |
|
|
// static final boolean doTaxa = false;
|
112 |
|
|
// static final boolean doRelTaxa = true;
|
113 |
|
|
// static final boolean doFacts = false;
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
// **********Always IGNORE:***********************************************
|
118 |
|
|
|
119 |
|
|
//etc.
|
120 |
|
|
static final boolean doUser = false;
|
121 |
|
|
static final boolean doTypes = false; //not available in MCL
|
122 |
|
|
static final boolean doNameFacts = false; //not available in MCL
|
123 |
|
|
static final boolean doOccurences = false; //not available in MCL
|
124 |
|
|
static final boolean doCommonNames = false; //not available in MCL
|
125 |
|
|
static final boolean doMarker = false; //not available in MCL
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
public void importMcl (Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
|
129 |
|
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
130 |
|
|
//make BerlinModel Source
|
131 |
|
|
|
132 |
|
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
133 |
|
|
|
134 |
512f31a5
|
Andreas Müller
|
try {
|
135 |
1f73c25d
|
Andreas Müller
|
Method makeUrlMethod = this.getClass().getDeclaredMethod("makeUrlForTaxon", TaxonBase.class, ResultSet.class);
|
136 |
512f31a5
|
Andreas Müller
|
config.setMakeUrlForTaxon(makeUrlMethod);
|
137 |
|
|
} catch (Exception e) {
|
138 |
|
|
e.printStackTrace();
|
139 |
|
|
return;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
|
143 |
6a915f5e
|
Andreas Müller
|
config.setClassificationUuid(classificationUuid);
|
144 |
|
|
config.setSourceSecId(sourceSecId);
|
145 |
|
|
|
146 |
|
|
config.setNomenclaturalCode(nomenclaturalCode);
|
147 |
|
|
|
148 |
|
|
config.setIgnoreNull(ignoreNull);
|
149 |
|
|
config.setDoAuthors(doAuthors);
|
150 |
|
|
config.setDoReferences(doReferences);
|
151 |
|
|
config.setDoTaxonNames(doTaxonNames);
|
152 |
|
|
config.setDoRelNames(doRelNames);
|
153 |
|
|
config.setDoNameStatus(doNameStatus);
|
154 |
|
|
config.setDoTypes(doTypes);
|
155 |
|
|
config.setDoNameFacts(doNameFacts);
|
156 |
|
|
config.setUseClassification(useClassification);
|
157 |
|
|
config.setSourceRefUuid(sourceRefUuid);
|
158 |
|
|
|
159 |
|
|
config.setDoTaxa(doTaxa);
|
160 |
|
|
config.setDoRelTaxa(doRelTaxa);
|
161 |
|
|
config.setDoFacts(doFacts);
|
162 |
|
|
config.setDoOccurrence(doOccurences);
|
163 |
|
|
config.setDoCommonNames(doCommonNames);
|
164 |
|
|
|
165 |
|
|
config.setDoMarker(doMarker);
|
166 |
|
|
config.setDoUser(doUser);
|
167 |
|
|
config.setEditor(editor);
|
168 |
|
|
config.setDbSchemaValidation(hbm2dll);
|
169 |
|
|
|
170 |
|
|
// maximum number of name facts to import
|
171 |
|
|
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
172 |
|
|
|
173 |
|
|
config.setUseSingleClassification(useSingleClassification);
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
config.setCheck(check);
|
177 |
|
|
config.setEditor(editor);
|
178 |
|
|
config.setRecordsPerTransaction(partitionSize);
|
179 |
|
|
|
180 |
|
|
|
181 |
|
|
// invoke import
|
182 |
|
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
183 |
|
|
bmImport.invoke(config);
|
184 |
|
|
|
185 |
|
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
186 |
|
|
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
/**
|
190 |
|
|
* @param args
|
191 |
|
|
*/
|
192 |
|
|
public static void main(String[] args) {
|
193 |
|
|
MclActivator importActivator = new MclActivator();
|
194 |
|
|
Source source = berlinModelSource;
|
195 |
|
|
ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
196 |
|
|
|
197 |
|
|
importActivator.importMcl(source, cdmRepository, hbm2dll);
|
198 |
|
|
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
public static ICdmDataSource cdm_test_local_mcl(){
|
202 |
|
|
DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
|
203 |
|
|
String cdmServer = "127.0.0.1";
|
204 |
|
|
String cdmDB = "mcl";
|
205 |
|
|
String cdmUserName = "root";
|
206 |
|
|
return CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
|
207 |
|
|
}
|
208 |
512f31a5
|
Andreas Müller
|
|
209 |
|
|
private static final String URLbase = "http://ww2.bgbm.org/mcl/PTaxonDetail.asp?";
|
210 |
|
|
public static Method makeUrlForTaxon(TaxonBase<?> taxon, ResultSet rs){
|
211 |
|
|
Method result = null;
|
212 |
|
|
ExtensionType urlExtensionType = ExtensionType.URL();
|
213 |
|
|
int nameFk;
|
214 |
|
|
try {
|
215 |
|
|
nameFk = rs.getInt("PTNameFk");
|
216 |
|
|
int refFkInt = rs.getInt("PTRefFk");
|
217 |
|
|
if (nameFk != 0 && refFkInt != 0){
|
218 |
|
|
String url = String.format(URLbase + "NameId=%s&PTRefFk=%s",nameFk, refFkInt);
|
219 |
|
|
taxon.addExtension(url, urlExtensionType);
|
220 |
|
|
}else{
|
221 |
|
|
logger.warn("NameFk or refFkInt is 0. Can't create url");
|
222 |
|
|
}
|
223 |
|
|
} catch (SQLException e) {
|
224 |
|
|
logger.warn("Exception when trying to access result set for url creation.");
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
return result;
|
228 |
|
|
}
|
229 |
6a915f5e
|
Andreas Müller
|
|
230 |
|
|
}
|