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
;
15 import org
.springframework
.transaction
.TransactionStatus
;
17 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
18 import eu
.etaxonomy
.cdm
.app
.common
.CdmDestinations
;
19 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
20 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
21 import eu
.etaxonomy
.cdm
.io
.berlinModel
.BerlinModelTransformer
;
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 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
32 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
33 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
35 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
39 * TODO add the following to a wiki page:
40 * 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
41 * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
47 public class EuroMedActivator
{
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
.getLogger(EuroMedActivator
.class);
51 //database validation status (create, update, validate ...)
52 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.VALIDATE
;
53 static final Source berlinModelSource
= BerlinModelSources
.euroMed_BGBM42();
54 // static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
56 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed();
58 static final ICdmDataSource cdmDestination
= CdmDestinations
.cdm_pesi_euromed();
59 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_euromed3();
60 // static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
62 static final boolean includePesiExport
= false;
64 static final int sourceSecId
= 7000000; //500000
65 static final UUID classificationUuid
= UUID
.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
66 static final boolean useSingleClassification
= true;
67 static final String classificationName
= "Euro+Med 2014";
68 static final UUID featureTreeUuid
= UUID
.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
69 static final Object
[] featureKeyList
= new Integer
[]{1, 31, 4, 98, 41};
71 // set to zero for unlimited nameFacts
72 static final int maximumNumberOfNameFacts
= 0;
74 static final int partitionSize
= 2500;
77 static final CHECK check
= CHECK
.CHECK_AND_IMPORT
;
80 static final EDITOR editor
= EDITOR
.EDITOR_AS_EDITOR
;
83 static final NomenclaturalCode nomenclaturalCode
= NomenclaturalCode
.ICNAFP
;
86 static final boolean ignoreNull
= true;
88 static final boolean switchSpeciesGroup
= true;
90 static boolean useClassification
= true;
92 static boolean isSplitTdwgCodes
= false;
93 static boolean useEmAreaVocabulary
= true;
95 private boolean removeHttpMapsAnchor
= true;
98 static final String infrGenericRankAbbrev
= "[unranked]";
99 static final String infrSpecificRankAbbrev
= "[unranked]";
102 static String taxonTable
= "v_cdm_exp_taxaAll";
103 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
;
104 static String relPTaxonIdQuery
= " SELECT r.RelPTaxonId " +
105 " FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk" +
106 " WHERE r.RelPTaxonID NOT IN (1883791,1883800,1883823,1883852,1883853,1883864,1883896,1883921,1883943,1883944,1883955,1883972,1884008,1884030,1884031,1884035) " + //Unpublished Kew taxa which are not imported anymore
107 " "; // AND r.RelQualifierFk =1
108 static String nameIdTable
= " v_cdm_exp_namesAll ";
109 static String referenceIdTable
= " v_cdm_exp_refAll ";
110 static String refDetailFilter
= " RefDetailID IN (SELECT RefDetailID FROM v_cdm_exp_RefDetail) ";
111 static String factFilter
= " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
112 static String occurrenceFilter
= " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
113 static String occurrenceSourceFilter
= " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
114 static String commonNameFilter
= " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
115 static String webMarkerFilter
= " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
116 static String authorTeamFilter
= null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
117 static String authorFilter
= null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
121 // **************** ALL *********************
123 boolean invers
= !(hbm2dll
== DbSchemaValidation
.CREATE
);
125 static final boolean doUser
= true;
127 static final boolean doAuthors
= true;
129 static final DO_REFERENCES doReferences
= DO_REFERENCES
.ALL
;
131 static final boolean doTaxonNames
= true;
132 static final boolean doRelNames
= true;
133 static final boolean doNameStatus
= true;
134 static final boolean doTypes
= false; //serious types do not exist in E+M
135 static final boolean doNameFacts
= true;
138 static final boolean doTaxa
= true;
139 static final boolean doRelTaxa
= false;
140 static final boolean doFacts
= true;
141 static final boolean doOccurences
= true;
142 static final boolean doCommonNames
= true;
145 static final boolean doMarker
= true;
148 public void importEm2CDM (Source source
, ICdmDataSource destination
, DbSchemaValidation hbm2dll
){
149 System
.out
.println("Start import from BerlinModel("+ berlinModelSource
.getDatabase() + ") to " + cdmDestination
.getDatabase() + " ...");
150 //make BerlinModel Source
152 BerlinModelImportConfigurator config
= BerlinModelImportConfigurator
.NewInstance(source
, destination
);
154 config
.setClassificationName(classificationName
);
156 config
.setClassificationUuid(classificationUuid
);
157 config
.setSourceSecId(sourceSecId
);
158 config
.setNomenclaturalCode(nomenclaturalCode
);
159 config
.setIgnoreNull(ignoreNull
);
161 config
.setDoAuthors(doAuthors ^ invers
);
162 config
.setDoReferences(invers ? doReferences
.invers() : doReferences
);
163 config
.setDoTaxonNames(doTaxonNames ^ invers
);
164 config
.setDoRelNames(doRelNames ^ invers
);
165 config
.setDoNameStatus(doNameStatus ^ invers
);
166 config
.setDoTypes(doTypes
); //always false
167 config
.setDoNameFacts(doNameFacts ^ invers
);
168 config
.setDoTaxa(doTaxa ^ invers
);
169 config
.setDoRelTaxa(doRelTaxa ^ invers
);
170 config
.setDoFacts(doFacts ^ invers
);
171 config
.setDoOccurrence(doOccurences ^ invers
);
172 config
.setDoCommonNames(doCommonNames ^ invers
);
174 config
.setDoMarker(doMarker ^ invers
);
175 config
.setDoUser(doUser ^ invers
);
177 config
.setUseClassification(useClassification
);
178 config
.setSourceRefUuid(BerlinModelTransformer
.uuidSourceRefEuroMed
);
179 config
.setEditor(editor
);
180 config
.setDbSchemaValidation(hbm2dll
);
182 // maximum number of name facts to import
183 config
.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts
);
185 config
.setInfrGenericRankAbbrev(infrGenericRankAbbrev
);
186 config
.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev
);
187 config
.setRemoveHttpMapsAnchor(removeHttpMapsAnchor
);
190 config
.setTaxonTable(taxonTable
);
191 config
.setClassificationQuery(classificationQuery
);
192 config
.setRelTaxaIdQuery(relPTaxonIdQuery
);
193 config
.setNameIdTable(nameIdTable
);
194 config
.setReferenceIdTable(referenceIdTable
);
195 config
.setAuthorTeamFilter(authorTeamFilter
);
196 config
.setAuthorFilter(authorFilter
);
197 config
.setFactFilter(factFilter
);
198 config
.setRefDetailFilter(refDetailFilter
);
199 config
.setCommonNameFilter(commonNameFilter
);
200 config
.setOccurrenceFilter(occurrenceFilter
);
201 config
.setOccurrenceSourceFilter(occurrenceSourceFilter
);
202 config
.setWebMarkerFilter(webMarkerFilter
);
203 config
.setUseSingleClassification(useSingleClassification
);
206 config
.setSplitTdwgCodes(isSplitTdwgCodes
);
207 config
.setUseEmAreaVocabulary(useEmAreaVocabulary
);
209 config
.setCheck(check
);
210 config
.setEditor(editor
);
211 config
.setRecordsPerTransaction(partitionSize
);
213 config
.setSwitchSpeciesGroup(switchSpeciesGroup
);
216 CdmDefaultImport
<BerlinModelImportConfigurator
> bmImport
= new CdmDefaultImport
<BerlinModelImportConfigurator
>();
217 bmImport
.invoke(config
);
219 if (config
.isDoTaxonNames() && (config
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || config
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ) ){
220 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
221 TransactionStatus tx
= app
.startTransaction();
223 Rank sectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
224 Representation repr
= sectBot
.getRepresentation(Language
.ENGLISH());
225 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
226 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
227 sectBot
.setTitleCache(null, false); //to definetely update the titleCache also
228 app
.getTermService().saveOrUpdate(sectBot
);
230 Rank subSectBot
= (Rank
)app
.getTermService().find(Rank
.SECTION_BOTANY().getUuid());
231 repr
= subSectBot
.getRepresentation(Language
.ENGLISH());
232 repr
.setAbbreviatedLabel(repr
.getAbbreviatedLabel().replace("(bot.)", "").trim());
233 repr
.setLabel(repr
.getLabel().replace("(Botany)", "").trim());
234 subSectBot
.setTitleCache(null, false); //to definetely update the titleCache also
235 app
.getTermService().saveOrUpdate(subSectBot
);
236 app
.commitTransaction(tx
);
237 } catch (Exception e
) {
242 if (config
.isDoFacts() && (config
.getCheck().equals(CHECK
.CHECK_AND_IMPORT
) || config
.getCheck().equals(CHECK
.IMPORT_WITHOUT_CHECK
) ) ){
243 ICdmApplicationConfiguration app
= bmImport
.getCdmAppController();
244 TransactionStatus tx
= app
.startTransaction();
247 FeatureTree tree
= TreeCreator
.flatTree(featureTreeUuid
, config
.getFeatureMap(), featureKeyList
);
248 FeatureNode imageNode
= FeatureNode
.NewInstance(Feature
.IMAGE());
249 tree
.getRoot().addChild(imageNode
);
250 FeatureNode distributionNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
251 tree
.getRoot().addChild(distributionNode
, 1);
252 FeatureNode commonNameNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
253 tree
.getRoot().addChild(commonNameNode
, 2);
254 app
.getFeatureTreeService().saveOrUpdate(tree
);
256 //Change common name label
257 DefinedTermBase
<?
> commonNameFeature
= app
.getTermService().find(Feature
.COMMON_NAME().getUuid());
258 commonNameFeature
.setLabel("Common Names", Language
.ENGLISH());
259 commonNameFeature
.setTitleCache(null, false); //to definetely update the titleCache also
260 app
.getTermService().saveOrUpdate(commonNameFeature
);
261 app
.commitTransaction(tx
);
264 if (config
.isDoRelTaxa()){
268 System
.out
.println("End import from BerlinModel ("+ source
.getDatabase() + ")...");
275 public static void main(String
[] args
) {
276 EuroMedActivator importActivator
= new EuroMedActivator();
277 Source source
= berlinModelSource
;
278 ICdmDataSource cdmRepository
= CdmDestinations
.chooseDestination(args
) != null ? CdmDestinations
.chooseDestination(args
) : cdmDestination
;
280 importActivator
.importEm2CDM(source
, cdmRepository
, hbm2dll
);
281 if (includePesiExport
){
282 //not available from here since E+M was moved to app-import
283 // PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
284 // exportActivator.doExport(cdmRepository);