1 |
91138b6c
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
50818ab7
|
Katja Luther
|
* European Distributed Institute of Taxonomy
|
4 |
91138b6c
|
Andreas Müller
|
* http://www.e-taxonomy.eu
|
5 |
50818ab7
|
Katja Luther
|
*
|
6 |
91138b6c
|
Andreas Müller
|
* 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 |
8072bd02
|
Andreas Müller
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
17 |
91138b6c
|
Andreas Müller
|
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.in.BerlinModelImportConfigurator;
|
21 |
|
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
22 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
23 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
24 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
25 |
50818ab7
|
Katja Luther
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
26 |
d55d93f6
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.common.Source;
|
27 |
91138b6c
|
Andreas Müller
|
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 |
50818ab7
|
Katja Luther
|
* 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 base under another operation systen
|
36 |
91138b6c
|
Andreas Müller
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
37 |
50818ab7
|
Katja Luther
|
*
|
38 |
|
|
*
|
39 |
91138b6c
|
Andreas Müller
|
* @author a.mueller
|
40 |
|
|
*
|
41 |
|
|
*/
|
42 |
|
|
public class CampanulaceaeActivator {
|
43 |
|
|
private static final Logger logger = Logger.getLogger(CampanulaceaeActivator.class);
|
44 |
|
|
|
45 |
|
|
//database validation status (create, update, validate ...)
|
46 |
|
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
47 |
|
|
static final Source berlinModelSource = BerlinModelSources.Campanulaceae();
|
48 |
|
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_campanulaceae_production();
|
49 |
|
|
|
50 |
|
|
static final UUID secUuid = UUID.fromString("ed7dd0ea-fcdd-405d-9fe1-52652aa06119");
|
51 |
401fe405
|
Andreas Müller
|
static final UUID classificationUuid = UUID.fromString("e305ddac-7200-4293-aa5d-d3426133ed9f");
|
52 |
91138b6c
|
Andreas Müller
|
static final int sourceSecId = 100000;
|
53 |
50818ab7
|
Katja Luther
|
|
54 |
91138b6c
|
Andreas Müller
|
static final UUID featureTreeUuid = UUID.fromString("231809ce-ad9e-4a50-8a48-668bd336cb7e");
|
55 |
50818ab7
|
Katja Luther
|
static final Object[] featureKeyList = new Integer[]{};
|
56 |
|
|
|
57 |
|
|
|
58 |
91138b6c
|
Andreas Müller
|
// set to zero for unlimited nameFacts
|
59 |
|
|
static final int maximumNumberOfNameFacts = 0;
|
60 |
|
|
static final int recordsPerTransaction = 2000;
|
61 |
50818ab7
|
Katja Luther
|
|
62 |
91138b6c
|
Andreas Müller
|
//check - import
|
63 |
|
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
64 |
|
|
|
65 |
|
|
//editor - import
|
66 |
|
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
67 |
50818ab7
|
Katja Luther
|
|
68 |
bc2e58de
|
Andreas Müller
|
//NomenclaturalCode
|
69 |
bb38665e
|
Andreas Müller
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
70 |
91138b6c
|
Andreas Müller
|
|
71 |
|
|
//ignore null
|
72 |
|
|
static final boolean ignoreNull = true;
|
73 |
50818ab7
|
Katja Luther
|
|
74 |
401fe405
|
Andreas Müller
|
static boolean useClassification = true;
|
75 |
91138b6c
|
Andreas Müller
|
|
76 |
50818ab7
|
Katja Luther
|
static boolean includesEmCode = false;
|
77 |
91138b6c
|
Andreas Müller
|
|
78 |
50818ab7
|
Katja Luther
|
|
79 |
|
|
// **************** ALL *********************
|
80 |
91138b6c
|
Andreas Müller
|
|
81 |
|
|
static final boolean doUser = true;
|
82 |
|
|
//authors
|
83 |
|
|
static final boolean doAuthors = true;
|
84 |
|
|
//references
|
85 |
|
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
86 |
|
|
//names
|
87 |
|
|
static final boolean doTaxonNames = true;
|
88 |
|
|
static final boolean doRelNames = true;
|
89 |
|
|
static final boolean doNameStatus = true;
|
90 |
|
|
static final boolean doTypes = true;
|
91 |
|
|
static final boolean doNameFacts = true;
|
92 |
50818ab7
|
Katja Luther
|
|
93 |
91138b6c
|
Andreas Müller
|
//taxa
|
94 |
|
|
static final boolean doTaxa = true;
|
95 |
|
|
static final boolean doRelTaxa = true;
|
96 |
|
|
static final boolean doFacts = false; //no facts exist campanulaceae
|
97 |
|
|
static final boolean doOccurences = true;
|
98 |
|
|
static final boolean doCommonNames = false; //no common names exist in campanulaceae
|
99 |
|
|
|
100 |
|
|
//etc.
|
101 |
|
|
static final boolean doMarker = true;
|
102 |
|
|
|
103 |
50818ab7
|
Katja Luther
|
|
104 |
91138b6c
|
Andreas Müller
|
// **************** SELECTED *********************
|
105 |
|
|
//
|
106 |
|
|
// static final boolean doUser = false;
|
107 |
|
|
// //authors
|
108 |
|
|
// static final boolean doAuthors = false;
|
109 |
|
|
// //references
|
110 |
|
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
111 |
|
|
// //names
|
112 |
|
|
// static final boolean doTaxonNames = false;
|
113 |
|
|
// static final boolean doRelNames = false;
|
114 |
|
|
// static final boolean doNameStatus = false;
|
115 |
|
|
// static final boolean doTypes = false;
|
116 |
|
|
// static final boolean doNameFacts = false;
|
117 |
50818ab7
|
Katja Luther
|
//
|
118 |
|
|
// //taxa
|
119 |
91138b6c
|
Andreas Müller
|
// static final boolean doTaxa = false;
|
120 |
|
|
// static final boolean doRelTaxa = false;
|
121 |
|
|
// static final boolean doCommonNames = false;
|
122 |
|
|
// static final boolean doFacts = false;
|
123 |
|
|
// static final boolean doOccurences = false;
|
124 |
50818ab7
|
Katja Luther
|
//
|
125 |
91138b6c
|
Andreas Müller
|
// //etc.
|
126 |
|
|
// static final boolean doMarker = false;
|
127 |
50818ab7
|
Katja Luther
|
|
128 |
|
|
|
129 |
|
|
private ImportResult doInvoke(ICdmDataSource destination){
|
130 |
|
|
ImportResult success ;
|
131 |
91138b6c
|
Andreas Müller
|
Source source = berlinModelSource;
|
132 |
50818ab7
|
Katja Luther
|
|
133 |
91138b6c
|
Andreas Müller
|
BerlinModelImportConfigurator bmImportConfigurator = BerlinModelImportConfigurator.NewInstance(source, destination);
|
134 |
50818ab7
|
Katja Luther
|
|
135 |
401fe405
|
Andreas Müller
|
bmImportConfigurator.setClassificationUuid(classificationUuid);
|
136 |
91138b6c
|
Andreas Müller
|
bmImportConfigurator.setSourceSecId(sourceSecId);
|
137 |
50818ab7
|
Katja Luther
|
|
138 |
91138b6c
|
Andreas Müller
|
bmImportConfigurator.setNomenclaturalCode(nomenclaturalCode);
|
139 |
|
|
|
140 |
|
|
bmImportConfigurator.setIgnoreNull(ignoreNull);
|
141 |
|
|
bmImportConfigurator.setDoAuthors(doAuthors);
|
142 |
|
|
bmImportConfigurator.setDoReferences(doReferences);
|
143 |
|
|
bmImportConfigurator.setDoTaxonNames(doTaxonNames);
|
144 |
|
|
bmImportConfigurator.setDoRelNames(doRelNames);
|
145 |
|
|
bmImportConfigurator.setDoNameStatus(doNameStatus);
|
146 |
|
|
bmImportConfigurator.setDoTypes(doTypes);
|
147 |
|
|
bmImportConfigurator.setDoNameFacts(doNameFacts);
|
148 |
401fe405
|
Andreas Müller
|
bmImportConfigurator.setUseClassification(useClassification);
|
149 |
50818ab7
|
Katja Luther
|
|
150 |
91138b6c
|
Andreas Müller
|
bmImportConfigurator.setDoTaxa(doTaxa);
|
151 |
|
|
bmImportConfigurator.setDoRelTaxa(doRelTaxa);
|
152 |
|
|
bmImportConfigurator.setDoFacts(doFacts);
|
153 |
|
|
bmImportConfigurator.setDoOccurrence(doOccurences);
|
154 |
|
|
bmImportConfigurator.setDoCommonNames(doCommonNames);
|
155 |
50818ab7
|
Katja Luther
|
|
156 |
91138b6c
|
Andreas Müller
|
bmImportConfigurator.setDoMarker(doMarker);
|
157 |
|
|
bmImportConfigurator.setDoUser(doUser);
|
158 |
|
|
bmImportConfigurator.setEditor(editor);
|
159 |
|
|
bmImportConfigurator.setDbSchemaValidation(hbm2dll);
|
160 |
|
|
bmImportConfigurator.setRecordsPerTransaction(recordsPerTransaction);
|
161 |
50818ab7
|
Katja Luther
|
|
162 |
553bddfe
|
Andreas Müller
|
bmImportConfigurator.setIncludesEmCode(includesEmCode);
|
163 |
91138b6c
|
Andreas Müller
|
|
164 |
|
|
// maximum number of name facts to import
|
165 |
|
|
bmImportConfigurator.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
166 |
50818ab7
|
Katja Luther
|
|
167 |
|
|
|
168 |
91138b6c
|
Andreas Müller
|
bmImportConfigurator.setCheck(check);
|
169 |
|
|
bmImportConfigurator.setEditor(editor);
|
170 |
50818ab7
|
Katja Luther
|
|
171 |
91138b6c
|
Andreas Müller
|
// invoke import
|
172 |
|
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
173 |
50818ab7
|
Katja Luther
|
success = bmImport.invoke(bmImportConfigurator);
|
174 |
|
|
|
175 |
91138b6c
|
Andreas Müller
|
if (doFacts && (bmImportConfigurator.getCheck().equals(CHECK.CHECK_AND_IMPORT) || bmImportConfigurator.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
176 |
8072bd02
|
Andreas Müller
|
ICdmRepository app = bmImport.getCdmAppController();
|
177 |
50818ab7
|
Katja Luther
|
|
178 |
91138b6c
|
Andreas Müller
|
//make feature tree
|
179 |
|
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, bmImportConfigurator.getFeatureMap(), featureKeyList);
|
180 |
|
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
181 |
50818ab7
|
Katja Luther
|
tree.getRoot().addChild(distributionNode, 1);
|
182 |
91138b6c
|
Andreas Müller
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
183 |
|
|
}
|
184 |
50818ab7
|
Katja Luther
|
|
185 |
91138b6c
|
Andreas Müller
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
186 |
|
|
|
187 |
|
|
|
188 |
|
|
logger.warn("!!!! NOTE: RefDetail notes and RelPTaxon notes are not imported automatically. Please check for these notes and import them manually.");
|
189 |
50818ab7
|
Katja Luther
|
|
190 |
91138b6c
|
Andreas Müller
|
return success;
|
191 |
50818ab7
|
Katja Luther
|
|
192 |
91138b6c
|
Andreas Müller
|
}
|
193 |
50818ab7
|
Katja Luther
|
|
194 |
91138b6c
|
Andreas Müller
|
/**
|
195 |
|
|
* @param args
|
196 |
|
|
*/
|
197 |
|
|
public static void main(String[] args) {
|
198 |
|
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
199 |
50818ab7
|
Katja Luther
|
|
200 |
91138b6c
|
Andreas Müller
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + destination.getDatabase() + " ...");
|
201 |
|
|
CampanulaceaeActivator me = new CampanulaceaeActivator();
|
202 |
|
|
me.doInvoke(destination);
|
203 |
50818ab7
|
Katja Luther
|
|
204 |
91138b6c
|
Andreas Müller
|
}
|
205 |
|
|
|
206 |
|
|
}
|