Revision abc846c0
Added by Andreas Müller almost 9 years ago
app-import/src/main/java/eu/etaxonomy/cdm/app/berlinModelImport/EuroMedActivator.java | ||
---|---|---|
1 |
/** |
|
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.berlinModelImport; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.springframework.transaction.TransactionStatus; |
|
16 |
|
|
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; |
|
36 |
|
|
37 |
|
|
38 |
/** |
|
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. |
|
42 |
* |
|
43 |
* |
|
44 |
* @author a.mueller |
|
45 |
* |
|
46 |
*/ |
|
47 |
public class EuroMedActivator { |
|
48 |
@SuppressWarnings("unused") |
|
49 |
private static final Logger logger = Logger.getLogger(EuroMedActivator.class); |
|
50 |
|
|
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(); |
|
55 |
|
|
56 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed(); |
|
57 |
|
|
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(); |
|
61 |
|
|
62 |
static final boolean includePesiExport = false; |
|
63 |
|
|
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}; |
|
70 |
|
|
71 |
// set to zero for unlimited nameFacts |
|
72 |
static final int maximumNumberOfNameFacts = 0; |
|
73 |
|
|
74 |
static final int partitionSize = 2500; |
|
75 |
|
|
76 |
//check - import |
|
77 |
static final CHECK check = CHECK.CHECK_AND_IMPORT; |
|
78 |
|
|
79 |
//editor - import |
|
80 |
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR; |
|
81 |
|
|
82 |
//NomenclaturalCode |
|
83 |
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP; |
|
84 |
|
|
85 |
//ignore null |
|
86 |
static final boolean ignoreNull = true; |
|
87 |
|
|
88 |
static final boolean switchSpeciesGroup = true; |
|
89 |
|
|
90 |
static boolean useClassification = true; |
|
91 |
|
|
92 |
static boolean isSplitTdwgCodes = false; |
|
93 |
static boolean useEmAreaVocabulary = true; |
|
94 |
|
|
95 |
private boolean removeHttpMapsAnchor = true; |
|
96 |
|
|
97 |
|
|
98 |
static final String infrGenericRankAbbrev = "[unranked]"; |
|
99 |
static final String infrSpecificRankAbbrev = "[unranked]"; |
|
100 |
|
|
101 |
|
|
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) "; |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
// **************** ALL ********************* |
|
122 |
|
|
123 |
boolean invers = !(hbm2dll == DbSchemaValidation.CREATE); |
|
124 |
|
|
125 |
static final boolean doUser = true; |
|
126 |
// //authors |
|
127 |
static final boolean doAuthors = true; |
|
128 |
//references |
|
129 |
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL; |
|
130 |
//names |
|
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; |
|
136 |
|
|
137 |
//taxa |
|
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; |
|
143 |
|
|
144 |
//etc. |
|
145 |
static final boolean doMarker = true; |
|
146 |
|
|
147 |
|
|
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 |
|
151 |
|
|
152 |
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination); |
|
153 |
|
|
154 |
config.setClassificationName(classificationName); |
|
155 |
|
|
156 |
config.setClassificationUuid(classificationUuid); |
|
157 |
config.setSourceSecId(sourceSecId); |
|
158 |
config.setNomenclaturalCode(nomenclaturalCode); |
|
159 |
config.setIgnoreNull(ignoreNull); |
|
160 |
|
|
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); |
|
173 |
|
|
174 |
config.setDoMarker(doMarker ^ invers); |
|
175 |
config.setDoUser(doUser ^ invers); |
|
176 |
|
|
177 |
config.setUseClassification(useClassification); |
|
178 |
config.setSourceRefUuid(BerlinModelTransformer.uuidSourceRefEuroMed); |
|
179 |
config.setEditor(editor); |
|
180 |
config.setDbSchemaValidation(hbm2dll); |
|
181 |
|
|
182 |
// maximum number of name facts to import |
|
183 |
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts); |
|
184 |
|
|
185 |
config.setInfrGenericRankAbbrev(infrGenericRankAbbrev); |
|
186 |
config.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev); |
|
187 |
config.setRemoveHttpMapsAnchor(removeHttpMapsAnchor); |
|
188 |
|
|
189 |
// filter |
|
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); |
|
204 |
|
|
205 |
//TDWG codes |
|
206 |
config.setSplitTdwgCodes(isSplitTdwgCodes); |
|
207 |
config.setUseEmAreaVocabulary(useEmAreaVocabulary); |
|
208 |
|
|
209 |
config.setCheck(check); |
|
210 |
config.setEditor(editor); |
|
211 |
config.setRecordsPerTransaction(partitionSize); |
|
212 |
|
|
213 |
config.setSwitchSpeciesGroup(switchSpeciesGroup); |
|
214 |
|
|
215 |
// invoke import |
|
216 |
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>(); |
|
217 |
bmImport.invoke(config); |
|
218 |
|
|
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(); |
|
222 |
try { |
|
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); |
|
229 |
|
|
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) { |
|
238 |
e.printStackTrace(); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
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(); |
|
245 |
|
|
246 |
//make feature tree |
|
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); |
|
255 |
|
|
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); |
|
262 |
} |
|
263 |
|
|
264 |
if (config.isDoRelTaxa()){ |
|
265 |
|
|
266 |
} |
|
267 |
|
|
268 |
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")..."); |
|
269 |
|
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* @param args |
|
274 |
*/ |
|
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; |
|
279 |
|
|
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); |
|
285 |
} |
|
286 |
|
|
287 |
} |
|
288 |
|
|
289 |
} |
|
1 |
/** |
|
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.berlinModelImport; |
|
11 |
|
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.springframework.transaction.TransactionStatus; |
|
16 |
|
|
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; |
|
36 |
|
|
37 |
|
|
38 |
/** |
|
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. |
|
42 |
* |
|
43 |
* |
|
44 |
* @author a.mueller |
|
45 |
* |
|
46 |
*/ |
|
47 |
public class EuroMedActivator { |
|
48 |
@SuppressWarnings("unused") |
|
49 |
private static final Logger logger = Logger.getLogger(EuroMedActivator.class); |
|
50 |
|
|
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(); |
|
55 |
|
|
56 |
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_euroMed(); |
|
57 |
|
|
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(); |
|
61 |
|
|
62 |
static final boolean includePesiExport = false; |
|
63 |
|
|
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}; |
|
70 |
|
|
71 |
// set to zero for unlimited nameFacts |
|
72 |
static final int maximumNumberOfNameFacts = 0; |
|
73 |
|
|
74 |
static final int partitionSize = 2500; |
|
75 |
|
|
76 |
//check - import |
|
77 |
static final CHECK check = CHECK.CHECK_AND_IMPORT; |
|
78 |
|
|
79 |
//editor - import |
|
80 |
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR; |
|
81 |
|
|
82 |
//NomenclaturalCode |
|
83 |
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP; |
|
84 |
|
|
85 |
//ignore null |
|
86 |
static final boolean ignoreNull = true; |
|
87 |
|
|
88 |
static final boolean switchSpeciesGroup = true; |
|
89 |
|
|
90 |
static boolean useClassification = true; |
|
91 |
|
|
92 |
static boolean isSplitTdwgCodes = false; |
|
93 |
static boolean useEmAreaVocabulary = true; |
|
94 |
|
|
95 |
private final boolean removeHttpMapsAnchor = true; |
|
96 |
|
|
97 |
|
|
98 |
static final String infrGenericRankAbbrev = "[unranked]"; |
|
99 |
static final String infrSpecificRankAbbrev = "[unranked]"; |
|
100 |
|
|
101 |
|
|
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) "; |
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
// **************** ALL ********************* |
|
122 |
|
|
123 |
boolean invers = !(hbm2dll == DbSchemaValidation.CREATE); |
|
124 |
|
|
125 |
static final boolean doUser = true; |
|
126 |
// //authors |
|
127 |
static final boolean doAuthors = true; |
|
128 |
//references |
|
129 |
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL; |
|
130 |
//names |
|
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; |
|
136 |
|
|
137 |
//taxa |
|
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; |
|
143 |
|
|
144 |
//etc. |
|
145 |
static final boolean doMarker = true; |
|
146 |
|
|
147 |
|
|
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 |
|
151 |
|
|
152 |
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination); |
|
153 |
|
|
154 |
config.setClassificationName(classificationName); |
|
155 |
|
|
156 |
config.setClassificationUuid(classificationUuid); |
|
157 |
config.setSourceSecId(sourceSecId); |
|
158 |
config.setNomenclaturalCode(nomenclaturalCode); |
|
159 |
config.setIgnoreNull(ignoreNull); |
|
160 |
|
|
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); |
|
173 |
|
|
174 |
config.setDoMarker(doMarker ^ invers); |
|
175 |
config.setDoUser(doUser ^ invers); |
|
176 |
|
|
177 |
config.setUseClassification(useClassification); |
|
178 |
config.setSourceRefUuid(BerlinModelTransformer.uuidSourceRefEuroMed); |
|
179 |
config.setEditor(editor); |
|
180 |
config.setDbSchemaValidation(hbm2dll); |
|
181 |
|
|
182 |
// maximum number of name facts to import |
|
183 |
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts); |
|
184 |
|
|
185 |
config.setInfrGenericRankAbbrev(infrGenericRankAbbrev); |
|
186 |
config.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev); |
|
187 |
config.setRemoveHttpMapsAnchor(removeHttpMapsAnchor); |
|
188 |
|
|
189 |
// filter |
|
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); |
|
204 |
|
|
205 |
//TDWG codes |
|
206 |
config.setSplitTdwgCodes(isSplitTdwgCodes); |
|
207 |
config.setUseEmAreaVocabulary(useEmAreaVocabulary); |
|
208 |
|
|
209 |
config.setCheck(check); |
|
210 |
config.setEditor(editor); |
|
211 |
config.setRecordsPerTransaction(partitionSize); |
|
212 |
|
|
213 |
config.setSwitchSpeciesGroup(switchSpeciesGroup); |
|
214 |
|
|
215 |
// invoke import |
|
216 |
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>(); |
|
217 |
bmImport.invoke(config); |
|
218 |
|
|
219 |
//Rename Ranks (still needed?) |
|
220 |
if (config.isDoTaxonNames() && (config.getCheck().isImport() ) ){ |
|
221 |
ICdmApplicationConfiguration app = bmImport.getCdmAppController(); |
|
222 |
TransactionStatus tx = app.startTransaction(); |
|
223 |
try { |
|
224 |
Rank sectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid()); |
|
225 |
Representation repr = sectBot.getRepresentation(Language.ENGLISH()); |
|
226 |
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim()); |
|
227 |
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim()); |
|
228 |
sectBot.setTitleCache(null, false); //to definetely update the titleCache also |
|
229 |
app.getTermService().saveOrUpdate(sectBot); |
|
230 |
|
|
231 |
Rank subSectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid()); |
|
232 |
repr = subSectBot.getRepresentation(Language.ENGLISH()); |
|
233 |
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim()); |
|
234 |
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim()); |
|
235 |
subSectBot.setTitleCache(null, false); //to definetely update the titleCache also |
|
236 |
app.getTermService().saveOrUpdate(subSectBot); |
|
237 |
app.commitTransaction(tx); |
|
238 |
} catch (Exception e) { |
|
239 |
e.printStackTrace(); |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
//create feature tree |
|
244 |
if (config.isDoFacts() && (config.getCheck().isImport() ) ){ |
|
245 |
ICdmApplicationConfiguration app = bmImport.getCdmAppController(); |
|
246 |
TransactionStatus tx = app.startTransaction(); |
|
247 |
|
|
248 |
//make feature tree |
|
249 |
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList); |
|
250 |
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE()); |
|
251 |
tree.getRoot().addChild(imageNode); |
|
252 |
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION()); |
|
253 |
tree.getRoot().addChild(distributionNode, 1); |
|
254 |
FeatureNode commonNameNode = FeatureNode.NewInstance(Feature.COMMON_NAME()); |
|
255 |
tree.getRoot().addChild(commonNameNode, 2); |
|
256 |
app.getFeatureTreeService().saveOrUpdate(tree); |
|
257 |
|
|
258 |
app.commitTransaction(tx); |
|
259 |
|
|
260 |
|
|
261 |
} |
|
262 |
|
|
263 |
//Change common name label |
|
264 |
if (config.isDoFacts() && (config.getCheck().isImport() ) ){ |
|
265 |
ICdmApplicationConfiguration app = bmImport.getCdmAppController(); |
|
266 |
TransactionStatus tx = app.startTransaction(); |
|
267 |
|
|
268 |
DefinedTermBase<?> commonNameFeature = app.getTermService().find(Feature.COMMON_NAME().getUuid()); |
|
269 |
commonNameFeature.setLabel("Common Names", Language.ENGLISH()); |
|
270 |
commonNameFeature.setTitleCache(null, false); //to definitely update the titleCache also |
|
271 |
app.getTermService().saveOrUpdate(commonNameFeature); |
|
272 |
|
|
273 |
app.commitTransaction(tx); |
|
274 |
} |
|
275 |
|
|
276 |
if (config.isDoRelTaxa()){ |
|
277 |
//?? |
|
278 |
} |
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")..."); |
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
/** |
|
287 |
* @param args |
|
288 |
*/ |
|
289 |
public static void main(String[] args) { |
|
290 |
EuroMedActivator importActivator = new EuroMedActivator(); |
|
291 |
Source source = berlinModelSource; |
|
292 |
ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination; |
|
293 |
|
|
294 |
importActivator.importEm2CDM(source, cdmRepository, hbm2dll); |
|
295 |
if (includePesiExport){ |
|
296 |
//not available from here since E+M was moved to app-import |
|
297 |
// PesiExportActivatorEM exportActivator = new PesiExportActivatorEM(); |
|
298 |
// exportActivator.doExport(cdmRepository); |
|
299 |
} |
|
300 |
|
|
301 |
} |
|
302 |
|
|
303 |
} |
Also available in: Unified diff
Cleanup Euro+Med Activator