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
|
|
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.algaterra.AlgaTerraImportConfigurator;
|
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;
|
31
|
|
32
|
|
33
|
/**
|
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.
|
37
|
*
|
38
|
*
|
39
|
* @author a.mueller
|
40
|
*
|
41
|
*/
|
42
|
public class AlgaTerraActivator {
|
43
|
private static final Logger logger = Logger.getLogger(AlgaTerraActivator.class);
|
44
|
|
45
|
//database validation status (create, update, validate ...)
|
46
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
47
|
static final Source berlinModelSource = BerlinModelSources.AlgaTerra();
|
48
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
49
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_algaterra_preview();
|
50
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
51
|
|
52
|
|
53
|
static final UUID treeUuid = UUID.fromString("1f617402-78dc-4bf1-ac77-d260600a8879");
|
54
|
static final int sourceSecId = 7331;
|
55
|
static final UUID sourceRefUuid = UUID.fromString("7e1a2500-93a5-40c2-ba34-0213d7822379");
|
56
|
|
57
|
static final UUID featureTreeUuid = UUID.fromString("a970168a-36fd-4c7c-931e-87214a965c14");
|
58
|
static final Object[] featureKeyList = new Integer[]{7,201,202,203,204,205,206,207};
|
59
|
|
60
|
//check - import
|
61
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
62
|
|
63
|
private boolean ignoreNull = true;
|
64
|
|
65
|
private boolean includeFlatClassifications = true;
|
66
|
|
67
|
private EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
68
|
|
69
|
//NomeclaturalCode
|
70
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
|
71
|
|
72
|
static String factFilter = " factCategoryFk NOT IN (7, 202 ) ";
|
73
|
|
74
|
|
75
|
// ****************** ALL *****************************************
|
76
|
|
77
|
// //authors
|
78
|
// static final boolean doAuthors = true;
|
79
|
// //references
|
80
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
81
|
// //names
|
82
|
// static final boolean doTaxonNames = true;
|
83
|
// static final boolean doRelNames = true;
|
84
|
// static final boolean doNameStatus = true;
|
85
|
// static final boolean doTypes = true;
|
86
|
//
|
87
|
// //taxa
|
88
|
// static final boolean doTaxa = true;
|
89
|
// static final boolean doRelTaxa = true;
|
90
|
// static final boolean doFacts = true;
|
91
|
//
|
92
|
// //alga terra specific
|
93
|
// static final boolean doSpecimen = true;
|
94
|
// static final boolean doImages = true;
|
95
|
|
96
|
// ************************ NONE **************************************** //
|
97
|
|
98
|
//authors
|
99
|
static final boolean doAuthors = false;
|
100
|
//references
|
101
|
static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
102
|
//names
|
103
|
static final boolean doTaxonNames = false;
|
104
|
static final boolean doRelNames = false;
|
105
|
static final boolean doNameStatus = false;
|
106
|
static final boolean doTypes = true;
|
107
|
static final boolean doNameFacts = false;
|
108
|
|
109
|
//taxa
|
110
|
static final boolean doTaxa = false;
|
111
|
static final boolean doRelTaxa = false;
|
112
|
static final boolean doFacts = false;
|
113
|
|
114
|
//alga terra specific
|
115
|
static final boolean ecoFacts = false;
|
116
|
static final boolean doImages = true;
|
117
|
|
118
|
|
119
|
public void invoke(String[] args){
|
120
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") ...");
|
121
|
logger.debug("Start");
|
122
|
//make BerlinModel Source
|
123
|
Source source = berlinModelSource;
|
124
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
125
|
|
126
|
AlgaTerraImportConfigurator config = AlgaTerraImportConfigurator.NewInstance(source, destination);
|
127
|
|
128
|
config.setClassificationUuid(treeUuid);
|
129
|
config.setSourceSecId(sourceSecId);
|
130
|
config.setNomenclaturalCode(nomenclaturalCode);
|
131
|
|
132
|
config.setDoAuthors(doAuthors);
|
133
|
config.setDoReferences(doReferences);
|
134
|
config.setDoTaxonNames(doTaxonNames);
|
135
|
config.setDoRelNames(doRelNames);
|
136
|
config.setDoNameStatus(doNameStatus);
|
137
|
config.setDoTypes(doTypes);
|
138
|
|
139
|
config.setDoTaxa(doTaxa);
|
140
|
config.setDoRelTaxa(doRelTaxa);
|
141
|
config.setDoFacts(doFacts);
|
142
|
config.setDoEcoFacts(ecoFacts);
|
143
|
config.setDoImages(doImages);
|
144
|
|
145
|
config.setSourceRefUuid(sourceRefUuid);
|
146
|
config.setIgnoreNull(ignoreNull);
|
147
|
|
148
|
config.setIncludeFlatClassifications(includeFlatClassifications);
|
149
|
config.setFactFilter(factFilter);
|
150
|
|
151
|
config.setDbSchemaValidation(hbm2dll);
|
152
|
|
153
|
config.setCheck(check);
|
154
|
config.setEditor(editor);
|
155
|
|
156
|
// invoke import
|
157
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
158
|
bmImport.invoke(config);
|
159
|
|
160
|
if (doFacts && (config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
161
|
ICdmApplicationConfiguration app = bmImport.getCdmAppController();
|
162
|
|
163
|
//make feature tree
|
164
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
165
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
166
|
tree.getRoot().addChild(imageNode);
|
167
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
168
|
tree.getRoot().addChild(distributionNode, 2);
|
169
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
170
|
}
|
171
|
|
172
|
|
173
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
174
|
}
|
175
|
|
176
|
|
177
|
/**
|
178
|
* @param args
|
179
|
*/
|
180
|
public static void main(String[] args) {
|
181
|
AlgaTerraActivator activator = new AlgaTerraActivator();
|
182
|
activator.invoke(args);
|
183
|
}
|
184
|
|
185
|
}
|