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.pesi;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
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.common.CdmDefaultImport;
|
21
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
22
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
23
|
import eu.etaxonomy.cdm.io.common.Source;
|
24
|
import eu.etaxonomy.cdm.io.pesi.erms.ErmsImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
27
|
import eu.etaxonomy.cdm.model.reference.ISourceable;
|
28
|
|
29
|
/**
|
30
|
* @author a.mueller
|
31
|
*/
|
32
|
public class ErmsImportActivator {
|
33
|
|
34
|
private static final Logger logger = Logger.getLogger(ErmsImportActivator.class);
|
35
|
|
36
|
// static final Source ermsSource = PesiSources.PESI3_ERMS();
|
37
|
static final Source ermsSource = PesiSources.PESI2019_ERMS();
|
38
|
|
39
|
// static final ICdmDataSource cdmDestination = CdmDestinations.test_cdm_pesi_erms();
|
40
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_erms();
|
41
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_erms2();
|
42
|
|
43
|
static final Source pesiDestination =
|
44
|
cdmDestination == CdmDestinations.cdm_test_local_mysql_erms()?
|
45
|
PesiDestinations.pesi_test_local_CDM_ERMS2PESI():
|
46
|
PesiDestinations.pesi_test_local_CDM_ERMS2PESI_2() ;
|
47
|
|
48
|
static final boolean includeExport2PESI = false;
|
49
|
|
50
|
static final UUID classificationUuid = UUID.fromString("6fa988a9-10b7-48b0-a370-2586fbc066eb");
|
51
|
static final String classificationName = "ERMS 2019";
|
52
|
static final String sourceRefTitle = "ERMS export for PESI";
|
53
|
|
54
|
//check - import
|
55
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
56
|
static final int partitionSize = 5000;
|
57
|
//ignore null
|
58
|
static final boolean ignoreNull = true;
|
59
|
|
60
|
// ***************** ALL ************************************************//
|
61
|
|
62
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
63
|
// static final boolean doTaxa = true;
|
64
|
// static final boolean doRelTaxa = doTaxa; //should always run with doTaxa because dependent on state from doTaxa
|
65
|
// static final boolean doSourceUse = true;
|
66
|
// static final boolean doCommonNames = true;
|
67
|
// static final boolean doNotes = true;
|
68
|
// static final boolean doDistributions = true;
|
69
|
// static final boolean doLinks = true;
|
70
|
// static final boolean doImages = true;
|
71
|
|
72
|
//******************** NONE ***************************************//
|
73
|
//
|
74
|
static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
75
|
static final boolean doTaxa = false;
|
76
|
static final boolean doRelTaxa = doTaxa; //should always run with doTaxa because depends on state from doTaxa
|
77
|
static final boolean doSourceUse = true;
|
78
|
static final boolean doCommonNames = true;
|
79
|
static final boolean doNotes = true;
|
80
|
static final boolean doDistributions = true;
|
81
|
static final boolean doLinks = false;
|
82
|
static final boolean doImages = true;
|
83
|
|
84
|
private static DbSchemaValidation hbm2dll = (doReferences == DO_REFERENCES.ALL)? DbSchemaValidation.CREATE:DbSchemaValidation.VALIDATE;
|
85
|
|
86
|
private void doImport(Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
|
87
|
System.out.println("Start import from ("+ ermsSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ..." );
|
88
|
|
89
|
//make ERMS Source
|
90
|
|
91
|
ErmsImportConfigurator config = ErmsImportConfigurator.NewInstance(source, destination);
|
92
|
|
93
|
config.setClassificationUuid(classificationUuid);
|
94
|
|
95
|
config.setIgnoreNull(ignoreNull);
|
96
|
config.setDoReferences(doReferences);
|
97
|
|
98
|
config.setDoTaxa(doTaxa);
|
99
|
config.setDoRelTaxa(doRelTaxa);
|
100
|
config.setDoSourceUse(doSourceUse);
|
101
|
config.setDoLinks(doLinks);
|
102
|
config.setDoDistributions(doDistributions);
|
103
|
config.setDoVernaculars(doCommonNames);
|
104
|
config.setDoNotes(doNotes);
|
105
|
config.setDoImages(doImages);
|
106
|
|
107
|
config.setDbSchemaValidation(hbm2dll);
|
108
|
|
109
|
config.setCheck(check);
|
110
|
config.setRecordsPerTransaction(partitionSize);
|
111
|
config.setSourceRefUuid(PesiTransformer.uuidSourceRefErms);
|
112
|
config.setClassificationName(classificationName);
|
113
|
config.setSourceReferenceTitle(sourceRefTitle);
|
114
|
|
115
|
// invoke import
|
116
|
CdmDefaultImport<ErmsImportConfigurator> ermsImport = new CdmDefaultImport<>();
|
117
|
ermsImport.invoke(config);
|
118
|
|
119
|
if (config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ){
|
120
|
ICdmRepository app = ermsImport.getCdmAppController();
|
121
|
ISourceable<?> obj = app.getCommonService().getSourcedObjectByIdInSource(TaxonName.class, "1000027", null);
|
122
|
logger.info(obj);
|
123
|
|
124
|
// //make feature tree
|
125
|
// FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, ermsImportConfigurator.getFeatureMap(), featureKeyList);
|
126
|
// app = ermsImport.getCdmAppController();
|
127
|
// app.getFeatureTreeService().saveOrUpdate(tree);
|
128
|
}
|
129
|
System.out.println("End import from ("+ source.getDatabase() + ") to "+cdmDestination.getDatabase() + "...");
|
130
|
}
|
131
|
|
132
|
public static void main(String[] args) {
|
133
|
ICdmDataSource cdmDB = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
134
|
ErmsImportActivator ermsImport = new ErmsImportActivator();
|
135
|
ermsImport.doImport(ermsSource, cdmDB, hbm2dll);
|
136
|
|
137
|
if (includeExport2PESI){
|
138
|
PesiExportActivatorERMS ermsExport = new PesiExportActivatorERMS();
|
139
|
ermsExport.doTaxa = doTaxa;
|
140
|
ermsExport.doTreeIndex = doTaxa;
|
141
|
ermsExport.doRelTaxa = doRelTaxa;
|
142
|
// ermsExport.doInferredSynonyms = doRelTaxa;
|
143
|
ermsExport.doDescriptions = doImages;
|
144
|
|
145
|
ermsExport.doExport(cdmDB, pesiDestination);
|
146
|
}
|
147
|
System.exit(0);
|
148
|
}
|
149
|
}
|