1 |
335dbebe
|
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.pesi;
|
11 |
|
|
|
12 |
|
|
import java.util.UUID;
|
13 |
|
|
|
14 |
|
|
import org.apache.log4j.Logger;
|
15 |
|
|
|
16 |
|
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
17 |
|
|
import eu.etaxonomy.cdm.app.common.BerlinModelSources;
|
18 |
|
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
19 |
|
|
import eu.etaxonomy.cdm.app.common.TreeCreator;
|
20 |
|
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
21 |
|
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
22 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
23 |
|
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
24 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
25 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
26 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
27 |
|
|
import eu.etaxonomy.cdm.io.common.Source;
|
28 |
9e501d57
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
|
29 |
335dbebe
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30 |
|
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
31 |
|
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
32 |
|
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
33 |
|
|
|
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 EuroMedActivator {
|
45 |
|
|
@SuppressWarnings("unused")
|
46 |
|
|
private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
|
47 |
|
|
|
48 |
|
|
//database validation status (create, update, validate ...)
|
49 |
|
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
50 |
f98b108b
|
Andreas Müller
|
// static final Source berlinModelSource = BerlinModelSources.euroMed();
|
51 |
|
|
static final Source berlinModelSource = BerlinModelSources.PESI3_euroMed();
|
52 |
335dbebe
|
Andreas Müller
|
|
53 |
b54f16a7
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
|
54 |
b9051e41
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
55 |
594f6d9f
|
Andreas Müller
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
56 |
2e738be4
|
Andreas Müller
|
|
57 |
335dbebe
|
Andreas Müller
|
static final int sourceSecId = 7000000; //500000
|
58 |
|
|
static final UUID classificationUuid = UUID.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
|
59 |
3a191b8d
|
Andreas Müller
|
static final boolean useSingleClassification = true;
|
60 |
335dbebe
|
Andreas Müller
|
|
61 |
|
|
static final UUID featureTreeUuid = UUID.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
|
62 |
|
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
63 |
|
|
|
64 |
|
|
// set to zero for unlimited nameFacts
|
65 |
|
|
static final int maximumNumberOfNameFacts = 0;
|
66 |
|
|
|
67 |
ecb6f1f3
|
Andreas Müller
|
static final int partitionSize = 5000;
|
68 |
335dbebe
|
Andreas Müller
|
|
69 |
|
|
//check - import
|
70 |
2e738be4
|
Andreas Müller
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
71 |
335dbebe
|
Andreas Müller
|
|
72 |
|
|
//editor - import
|
73 |
|
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
74 |
|
|
|
75 |
|
|
//NomeclaturalCode
|
76 |
|
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
|
77 |
|
|
|
78 |
|
|
//ignore null
|
79 |
|
|
static final boolean ignoreNull = true;
|
80 |
|
|
|
81 |
be129943
|
Andreas Müller
|
static final boolean switchSpeciesGroup = true;
|
82 |
|
|
|
83 |
335dbebe
|
Andreas Müller
|
static boolean useClassification = true;
|
84 |
a148cf03
|
Andreas Müller
|
|
85 |
594f6d9f
|
Andreas Müller
|
static boolean isSplitTdwgCodes = false;
|
86 |
|
|
|
87 |
b54f16a7
|
Andreas Müller
|
static String taxonTable = "v_cdm_exp_taxaAll";
|
88 |
|
|
static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM _EM_CDM_exp_taxaDirect t INNER JOIN Reference r ON t.PTRefFk = r.RefId ";
|
89 |
0a8cb079
|
Andreas Müller
|
static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " +
|
90 |
b54f16a7
|
Andreas Müller
|
" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk ";
|
91 |
|
|
static String nameIdTable = " v_cdm_exp_namesAll ";
|
92 |
|
|
static String referenceIdTable = " v_cdm_exp_refAll ";
|
93 |
6da94d37
|
Andreas Müller
|
static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll )";
|
94 |
f14a2e43
|
Andreas Müller
|
static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
95 |
d43e56c7
|
Andreas Müller
|
static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
96 |
c2646e55
|
Andreas Müller
|
static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
|
97 |
d43e56c7
|
Andreas Müller
|
static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
|
98 |
b9051e41
|
Andreas Müller
|
static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
|
99 |
|
|
static String authorFilter = null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
|
100 |
9a9aea4c
|
Andreas Müller
|
|
101 |
5e55f5ef
|
Andreas Müller
|
|
102 |
|
|
|
103 |
335dbebe
|
Andreas Müller
|
// **************** ALL *********************
|
104 |
2e738be4
|
Andreas Müller
|
|
105 |
335dbebe
|
Andreas Müller
|
static final boolean doUser = true;
|
106 |
|
|
//authors
|
107 |
|
|
static final boolean doAuthors = true;
|
108 |
|
|
//references
|
109 |
|
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
110 |
|
|
//names
|
111 |
|
|
static final boolean doTaxonNames = true;
|
112 |
|
|
static final boolean doRelNames = true;
|
113 |
|
|
static final boolean doNameStatus = true;
|
114 |
594f6d9f
|
Andreas Müller
|
static final boolean doTypes = false; //serious types do not exist in E+M
|
115 |
335dbebe
|
Andreas Müller
|
static final boolean doNameFacts = true;
|
116 |
|
|
|
117 |
|
|
//taxa
|
118 |
|
|
static final boolean doTaxa = true;
|
119 |
|
|
static final boolean doRelTaxa = true;
|
120 |
|
|
static final boolean doFacts = true;
|
121 |
|
|
static final boolean doOccurences = true;
|
122 |
|
|
static final boolean doCommonNames = true;
|
123 |
|
|
|
124 |
|
|
//etc.
|
125 |
|
|
static final boolean doMarker = true;
|
126 |
|
|
|
127 |
|
|
|
128 |
|
|
// **************** SELECTED *********************
|
129 |
|
|
|
130 |
|
|
// static final boolean doUser = true;
|
131 |
|
|
// //authors
|
132 |
|
|
// static final boolean doAuthors = false;
|
133 |
|
|
// //references
|
134 |
|
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
135 |
|
|
// //names
|
136 |
|
|
// static final boolean doTaxonNames = false;
|
137 |
|
|
// static final boolean doRelNames = false;
|
138 |
|
|
// static final boolean doNameStatus = false;
|
139 |
|
|
// static final boolean doTypes = false;
|
140 |
|
|
// static final boolean doNameFacts = false;
|
141 |
|
|
//
|
142 |
|
|
// //taxa
|
143 |
|
|
// static final boolean doTaxa = false;
|
144 |
|
|
// static final boolean doRelTaxa = false;
|
145 |
|
|
// static final boolean doFacts = false;
|
146 |
|
|
// static final boolean doOccurences = false;
|
147 |
2e738be4
|
Andreas Müller
|
// static final boolean doCommonNames = false;
|
148 |
335dbebe
|
Andreas Müller
|
//
|
149 |
|
|
// //etc.
|
150 |
|
|
// static final boolean doMarker = false;
|
151 |
|
|
|
152 |
|
|
|
153 |
|
|
/**
|
154 |
|
|
* @param args
|
155 |
|
|
*/
|
156 |
|
|
public static void main(String[] args) {
|
157 |
|
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
158 |
|
|
|
159 |
|
|
//make BerlinModel Source
|
160 |
|
|
Source source = berlinModelSource;
|
161 |
|
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
162 |
|
|
|
163 |
9a9aea4c
|
Andreas Müller
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
164 |
335dbebe
|
Andreas Müller
|
|
165 |
9a9aea4c
|
Andreas Müller
|
config.setClassificationUuid(classificationUuid);
|
166 |
|
|
config.setSourceSecId(sourceSecId);
|
167 |
335dbebe
|
Andreas Müller
|
|
168 |
9a9aea4c
|
Andreas Müller
|
config.setNomenclaturalCode(nomenclaturalCode);
|
169 |
|
|
|
170 |
|
|
config.setIgnoreNull(ignoreNull);
|
171 |
|
|
config.setDoAuthors(doAuthors);
|
172 |
|
|
config.setDoReferences(doReferences);
|
173 |
|
|
config.setDoTaxonNames(doTaxonNames);
|
174 |
|
|
config.setDoRelNames(doRelNames);
|
175 |
|
|
config.setDoNameStatus(doNameStatus);
|
176 |
|
|
config.setDoTypes(doTypes);
|
177 |
|
|
config.setDoNameFacts(doNameFacts);
|
178 |
|
|
config.setUseClassification(useClassification);
|
179 |
9e501d57
|
Andreas Müller
|
config.setSourceRefUuid(PesiTransformer.uuidSourceRefEuroMed);
|
180 |
335dbebe
|
Andreas Müller
|
|
181 |
9a9aea4c
|
Andreas Müller
|
config.setDoTaxa(doTaxa);
|
182 |
|
|
config.setDoRelTaxa(doRelTaxa);
|
183 |
|
|
config.setDoFacts(doFacts);
|
184 |
|
|
config.setDoOccurrence(doOccurences);
|
185 |
|
|
config.setDoCommonNames(doCommonNames);
|
186 |
335dbebe
|
Andreas Müller
|
|
187 |
9a9aea4c
|
Andreas Müller
|
config.setDoMarker(doMarker);
|
188 |
|
|
config.setDoUser(doUser);
|
189 |
|
|
config.setEditor(editor);
|
190 |
|
|
config.setDbSchemaValidation(hbm2dll);
|
191 |
335dbebe
|
Andreas Müller
|
|
192 |
|
|
// maximum number of name facts to import
|
193 |
9a9aea4c
|
Andreas Müller
|
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
194 |
335dbebe
|
Andreas Müller
|
|
195 |
73976b9e
|
Andreas Müller
|
// filter
|
196 |
9a9aea4c
|
Andreas Müller
|
config.setTaxonTable(taxonTable);
|
197 |
|
|
config.setClassificationQuery(classificationQuery);
|
198 |
|
|
config.setRelTaxaIdQuery(relPTaxonIdQuery);
|
199 |
c7faa0c3
|
Andreas Müller
|
config.setNameIdTable(nameIdTable);
|
200 |
b54f16a7
|
Andreas Müller
|
config.setReferenceIdTable(referenceIdTable);
|
201 |
ecb6f1f3
|
Andreas Müller
|
config.setAuthorTeamFilter(authorTeamFilter);
|
202 |
|
|
config.setAuthorFilter(authorFilter);
|
203 |
c7faa0c3
|
Andreas Müller
|
config.setFactFilter(factFilter);
|
204 |
c2646e55
|
Andreas Müller
|
config.setCommonNameFilter(commonNameFilter);
|
205 |
d43e56c7
|
Andreas Müller
|
config.setOccurrenceFilter(occurrenceFilter);
|
206 |
|
|
config.setOccurrenceSourceFilter(occurrenceSourceFilter);
|
207 |
|
|
config.setWebMarkerFilter(webMarkerFilter);
|
208 |
f1d50957
|
Andreas Müller
|
config.setUseSingleClassification(useSingleClassification);
|
209 |
9a9aea4c
|
Andreas Müller
|
|
210 |
594f6d9f
|
Andreas Müller
|
//TDWG codes
|
211 |
|
|
config.setSplitTdwgCodes(isSplitTdwgCodes);
|
212 |
|
|
|
213 |
73976b9e
|
Andreas Müller
|
|
214 |
9a9aea4c
|
Andreas Müller
|
config.setCheck(check);
|
215 |
|
|
config.setEditor(editor);
|
216 |
|
|
config.setRecordsPerTransaction(partitionSize);
|
217 |
335dbebe
|
Andreas Müller
|
|
218 |
be129943
|
Andreas Müller
|
config.setSwitchSpeciesGroup(switchSpeciesGroup);
|
219 |
|
|
|
220 |
335dbebe
|
Andreas Müller
|
// invoke import
|
221 |
|
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
222 |
9a9aea4c
|
Andreas Müller
|
bmImport.invoke(config);
|
223 |
335dbebe
|
Andreas Müller
|
|
224 |
9a9aea4c
|
Andreas Müller
|
if (doFacts && config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ){
|
225 |
335dbebe
|
Andreas Müller
|
ICdmApplicationConfiguration app = bmImport.getCdmAppController();
|
226 |
|
|
|
227 |
|
|
//make feature tree
|
228 |
9a9aea4c
|
Andreas Müller
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
229 |
335dbebe
|
Andreas Müller
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
230 |
|
|
tree.getRoot().addChild(imageNode);
|
231 |
|
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
232 |
|
|
tree.getRoot().addChild(distributionNode, 2);
|
233 |
|
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
237 |
|
|
|
238 |
|
|
}
|
239 |
|
|
|
240 |
|
|
}
|