2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.berlinModelImport
;
12 import java
.util
.UUID
;
14 import org
.apache
.log4j
.Logger
;
16 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
17 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
18 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
19 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
20 import eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
;
21 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelImportConfigurator
;
22 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
23 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
24 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.DO_REFERENCES
;
25 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.EDITOR
;
26 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
27 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
28 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
29 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
30 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
34 * TODO add the following to a wiki page:
35 * 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
36 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
42 public class EuroMedActivator
{
43 @SuppressWarnings("unused")
44 private static final Logger logger
= Logger
.getLogger(EuroMedActivator
.class);
46 //database validation status (create, update, validate ...)
47 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
48 static final Source berlinModelSource
= BerlinModelSources
.euroMed();
49 // static final Source berlinModelSource = BerlinModelSources.PESI3_euroMed();
51 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
52 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_test_local_mysql_test();
53 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
55 static final boolean includePesiExport
= false;
57 static final int sourceSecId
= 7000000; //500000
58 static final UUID classificationUuid
= UUID
.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
59 static final boolean useSingleClassification
= true;
61 static final UUID featureTreeUuid
= UUID
.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
62 static final Object
[] featureKeyList
= new Integer
[]{1, 31, 4, 98, 41};
64 // set to zero for unlimited nameFacts
65 static final int maximumNumberOfNameFacts
= 0;
67 static final int partitionSize
= 2500;
70 static final CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
73 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
76 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
79 static final boolean ignoreNull
= true;
81 static final boolean switchSpeciesGroup
= true;
83 static boolean useClassification
= true;
85 static boolean isSplitTdwgCodes
= false;
86 static boolean useEmAreaVocabulary
= true;
88 private boolean removeHttpMapsAnchor
= true;
91 static final String infrGenericRankAbbrev
= "[unranked]";
92 static final String infrSpecificRankAbbrev
= "[unranked]";
95 static String taxonTable
= "v_cdm_exp_taxaAll";
96 static String classificationQuery
= " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId
;
97 static String relPTaxonIdQuery
= " SELECT r.RelPTaxonId " +
98 " FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk" +
99 " ORDER BY r.RelPTaxonId "; // AND r.RelQualifierFk =1
100 static String nameIdTable
= " v_cdm_exp_namesAll ";
101 static String referenceIdTable
= " v_cdm_exp_refAll ";
102 static String factFilter
= " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
103 static String occurrenceFilter
= " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
104 static String occurrenceSourceFilter
= " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
105 static String commonNameFilter
= " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
106 static String webMarkerFilter
= " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
107 static String authorTeamFilter
= null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
108 static String authorFilter
= null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
112 // **************** ALL *********************
114 // static final boolean doUser = true;
116 // static final boolean doAuthors = true;
118 // static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
120 // static final boolean doTaxonNames = true;
121 // static final boolean doRelNames = true;
122 // static final boolean doNameStatus = true;
123 // static final boolean doTypes = false; //serious types do not exist in E+M
124 // static final boolean doNameFacts = true;
127 // static final boolean doTaxa = true;
128 // static final boolean doRelTaxa = false;
129 // static final boolean doFacts = true;
130 // static final boolean doOccurences = false;
131 // static final boolean doCommonNames = true;
134 // static final boolean doMarker = true;
137 // **************** SELECTED *********************
139 static final boolean doUser
= false;
141 static final boolean doAuthors
= false;
143 static final DO_REFERENCES doReferences
= DO_REFERENCES
.NONE
;
145 static final boolean doTaxonNames
= false;
146 static final boolean doRelNames
= false;
147 static final boolean doNameStatus
= false;
148 static final boolean doTypes
= false;
149 static final boolean doNameFacts
= false;
152 static final boolean doTaxa
= false;
153 static final boolean doRelTaxa
= false;
154 static final boolean doFacts
= false;
155 static final boolean doOccurences
= true;
156 static final boolean doCommonNames
= false;
159 static final boolean doMarker
= false;
162 public void importEm2CDM (Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
163 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ...");
164 //make BerlinModel Source
166 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
168 config
.setClassificationUuid(classificationUuid
);
169 config
.setSourceSecId(sourceSecId
);
171 config
.setNomenclaturalCode(nomenclaturalCode
);
173 config
.setIgnoreNull(ignoreNull
);
174 config
.setDoAuthors(doAuthors
);
175 config
.setDoReferences(doReferences
);
176 config
.setDoTaxonNames(doTaxonNames
);
177 config
.setDoRelNames(doRelNames
);
178 config
.setDoNameStatus(doNameStatus
);
179 config
.setDoTypes(doTypes
);
180 config
.setDoNameFacts(doNameFacts
);
181 config
.setUseClassification(useClassification
);
182 config
.setSourceRefUuid(BerlinModelTransformer
.uuidSourceRefEuroMed
);
184 config
.setDoTaxa(doTaxa
);
185 config
.setDoRelTaxa(doRelTaxa
);
186 config
.setDoFacts(doFacts
);
187 config
.setDoOccurrence(doOccurences
);
188 config
.setDoCommonNames(doCommonNames
);
190 config
.setDoMarker(doMarker
);
191 config
.setDoUser(doUser
);
192 config
.setEditor(editor
);
193 config
.setDbSchemaValidation(hbm2dll
);
195 // maximum number of name facts to import
196 config
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
198 config
.setInfrGenericRankAbbrev(infrGenericRankAbbrev
);
199 config
.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev
);
200 config
.setRemoveHttpMapsAnchor(removeHttpMapsAnchor
);
203 config
.setTaxonTable(taxonTable
);
204 config
.setClassificationQuery(classificationQuery
);
205 config
.setRelTaxaIdQuery(relPTaxonIdQuery
);
206 config
.setNameIdTable(nameIdTable
);
207 config
.setReferenceIdTable(referenceIdTable
);
208 config
.setAuthorTeamFilter(authorTeamFilter
);
209 config
.setAuthorFilter(authorFilter
);
210 config
.setFactFilter(factFilter
);
211 config
.setCommonNameFilter(commonNameFilter
);
212 config
.setOccurrenceFilter(occurrenceFilter
);
213 config
.setOccurrenceSourceFilter(occurrenceSourceFilter
);
214 config
.setWebMarkerFilter(webMarkerFilter
);
215 config
.setUseSingleClassification(useSingleClassification
);
218 config
.setSplitTdwgCodes(isSplitTdwgCodes
);
219 config
.setUseEmAreaVocabulary(useEmAreaVocabulary
);
221 config
.setCheck(check
);
222 config
.setEditor(editor
);
223 config
.setRecordsPerTransaction(partitionSize
);
225 config
.setSwitchSpeciesGroup(switchSpeciesGroup
);
228 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<BerlinModelImportConfigurator
>();
229 bmImport
.invoke(config
);
231 if (doFacts
&& (config
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || config
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ) ){
232 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
235 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, config
.getFeatureMap(), featureKeyList
);
236 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
237 tree
.getRoot().addChild(imageNode
);
238 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
239 tree
.getRoot().addChild(distributionNode
, 2);
240 FeatureNode commonNameNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
241 tree
.getRoot().addChild(commonNameNode
, 3);
242 app
.getFeatureTreeService().saveOrUpdate(tree
);
245 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
252 public static void main(String
[] args
) {
253 EuroMedActivator importActivator
= new EuroMedActivator();
254 Source source
= berlinModelSource
;
255 ICdmDataSource cdmRepository
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
257 importActivator
.importEm2CDM(source
, cdmRepository
, hbm2dll
);
258 if (includePesiExport
){
259 //not available from here since E+M was moved to app-import
260 // PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
261 // exportActivator.doExport(cdmRepository);