1 |
91138b6c
|
Andreas Müller
|
/**
|
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.wp6.cichorieae;
|
11 |
|
|
|
12 |
|
|
import java.io.File;
|
13 |
|
|
import java.util.Set;
|
14 |
|
|
import java.util.UUID;
|
15 |
|
|
|
16 |
|
|
import org.apache.log4j.Logger;
|
17 |
|
|
import org.springframework.transaction.TransactionStatus;
|
18 |
|
|
|
19 |
15a41eb5
|
Cherian Mathew
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationDefaultConfiguration;
|
20 |
91138b6c
|
Andreas Müller
|
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;
|
21 |
|
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
22 |
|
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23 |
|
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24 |
|
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
25 |
|
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27 |
|
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
28 |
cbe91b81
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.common.Source;
|
29 |
91138b6c
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
30 |
401fe405
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
31 |
cbe91b81
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
32 |
91138b6c
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
33 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
34 |
|
|
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* TODO add the following to a wiki page:
|
38 |
|
|
* 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
|
39 |
|
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
40 |
|
|
*
|
41 |
|
|
*
|
42 |
|
|
* @author a.mueller
|
43 |
|
|
*
|
44 |
|
|
*/
|
45 |
|
|
public class TaraxacumActivator {
|
46 |
|
|
private static final Logger logger = Logger.getLogger(TaraxacumActivator.class);
|
47 |
|
|
|
48 |
|
|
//database validation status (create, update, validate ...)
|
49 |
|
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.UPDATE;
|
50 |
|
|
static final Source berlinModelSource = BerlinModelSources.EDIT_Taraxacum();
|
51 |
|
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Cichorieae();
|
52 |
|
|
|
53 |
|
|
static final UUID treeUuid = UUID.fromString("019c4b4d-736b-4d2e-883c-e3244167080a");
|
54 |
|
|
// static final UUID treeUuid = UUID.fromString("00db28a7-50e1-4abc-86ec-b2a8ce870de9");
|
55 |
|
|
// static final UUID treeUuid = UUID.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");
|
56 |
|
|
static final int sourceSecId = 7800000;
|
57 |
|
|
|
58 |
|
|
static final UUID featureTreeUuid = UUID.fromString("ab007336-d853-4f2f-a490-7c8232eafe7b");
|
59 |
|
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
60 |
|
|
|
61 |
|
|
//TODO update for Taraxacum
|
62 |
|
|
static final String mediaUrlString = "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";
|
63 |
|
|
//Mac
|
64 |
|
|
//static final File mediaPath = new File("/Volumes/protolog/protolog/");
|
65 |
|
|
//Windows
|
66 |
|
|
//static final File mediaPath = new File("\\\\media\\editwp6\\protolog");
|
67 |
|
|
// set to zero for unlimited nameFacts
|
68 |
|
|
static final int maximumNumberOfNameFacts = 0;
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
//check - import
|
72 |
|
|
//static final CHECK check = CHECK.CHECK_ONLY;
|
73 |
|
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
74 |
|
|
|
75 |
|
|
//NomeclaturalCode
|
76 |
bb38665e
|
Andreas Müller
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
77 |
91138b6c
|
Andreas Müller
|
|
78 |
|
|
//ignore null
|
79 |
|
|
static final boolean ignoreNull = true;
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
// **************** ALL *********************
|
83 |
|
|
//authors
|
84 |
|
|
static final boolean doAuthors = true;
|
85 |
|
|
//references
|
86 |
|
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
87 |
|
|
//names
|
88 |
|
|
static final boolean doTaxonNames = true;
|
89 |
|
|
static final boolean doRelNames = true;
|
90 |
|
|
static final boolean doNameStatus = true;
|
91 |
|
|
static final boolean doTypes = true;
|
92 |
|
|
static final boolean doNameFacts = true;
|
93 |
|
|
|
94 |
|
|
//taxa
|
95 |
|
|
static final boolean doTaxa = true;
|
96 |
|
|
static final boolean doRelTaxa = true;
|
97 |
|
|
static final boolean doFacts = true;
|
98 |
|
|
static final boolean doOccurences = true;
|
99 |
|
|
static final boolean doCommonNames = true;
|
100 |
|
|
|
101 |
|
|
|
102 |
|
|
// **************** SELECTED *********************
|
103 |
|
|
//
|
104 |
|
|
// //authors
|
105 |
|
|
// static final boolean doAuthors = false;
|
106 |
|
|
// //references
|
107 |
|
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
108 |
|
|
// //names
|
109 |
|
|
// static final boolean doTaxonNames = false;
|
110 |
|
|
// static final boolean doRelNames = false;
|
111 |
|
|
// static final boolean doNameStatus = false;
|
112 |
|
|
// static final boolean doTypes = false;
|
113 |
|
|
// static final boolean doNameFacts = false;
|
114 |
|
|
//
|
115 |
|
|
// //taxa
|
116 |
|
|
// static final boolean doTaxa = false;
|
117 |
|
|
// static final boolean doRelTaxa = false;
|
118 |
|
|
// static final boolean doFacts = false;
|
119 |
|
|
// static final boolean doOccurences = false;
|
120 |
|
|
|
121 |
|
|
/**
|
122 |
|
|
* @param args
|
123 |
|
|
*/
|
124 |
|
|
public boolean doImport(ICdmDataSource destination, DbSchemaValidation hbm2dll) {
|
125 |
|
|
boolean success = true;
|
126 |
|
|
logger.info("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
127 |
|
|
|
128 |
|
|
//make BerlinModel Source
|
129 |
|
|
Source source = berlinModelSource;
|
130 |
|
|
|
131 |
|
|
BerlinModelImportConfigurator bmImportConfigurator = BerlinModelImportConfigurator.NewInstance(source, destination);
|
132 |
|
|
|
133 |
401fe405
|
Andreas Müller
|
bmImportConfigurator.setClassificationUuid(treeUuid);
|
134 |
91138b6c
|
Andreas Müller
|
// bmImportConfigurator.setSecUuid(secUuid);
|
135 |
|
|
bmImportConfigurator.setSourceSecId(sourceSecId);
|
136 |
|
|
|
137 |
|
|
bmImportConfigurator.setNomenclaturalCode(nomenclaturalCode);
|
138 |
|
|
|
139 |
|
|
bmImportConfigurator.setIgnoreNull(ignoreNull);
|
140 |
|
|
bmImportConfigurator.setDoAuthors(doAuthors);
|
141 |
|
|
bmImportConfigurator.setDoReferences(doReferences);
|
142 |
|
|
bmImportConfigurator.setDoTaxonNames(doTaxonNames);
|
143 |
|
|
bmImportConfigurator.setDoRelNames(doRelNames);
|
144 |
|
|
bmImportConfigurator.setDoNameStatus(doNameStatus);
|
145 |
|
|
bmImportConfigurator.setDoTypes(doTypes);
|
146 |
|
|
bmImportConfigurator.setDoNameFacts(doNameFacts);
|
147 |
|
|
|
148 |
|
|
bmImportConfigurator.setDoTaxa(doTaxa);
|
149 |
|
|
bmImportConfigurator.setDoRelTaxa(doRelTaxa);
|
150 |
|
|
bmImportConfigurator.setDoFacts(doFacts);
|
151 |
|
|
bmImportConfigurator.setDoOccurrence(doOccurences);
|
152 |
|
|
bmImportConfigurator.setDoCommonNames(doCommonNames);
|
153 |
|
|
|
154 |
|
|
bmImportConfigurator.setDbSchemaValidation(hbm2dll);
|
155 |
|
|
|
156 |
|
|
|
157 |
|
|
// mediaResourceLocations
|
158 |
|
|
File mediaPath = CichorieaeActivator.protologuePath;
|
159 |
|
|
if ( mediaPath.exists() && mediaPath.isDirectory()){
|
160 |
|
|
bmImportConfigurator.setMediaUrl(mediaUrlString);
|
161 |
|
|
bmImportConfigurator.setMediaPath(mediaPath);
|
162 |
|
|
}else{
|
163 |
|
|
logger.warn("Could not configure mediaResourceLocations");
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
// maximum number of name facts to import
|
167 |
|
|
bmImportConfigurator.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
bmImportConfigurator.setCheck(check);
|
171 |
|
|
|
172 |
|
|
// invoke import
|
173 |
|
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
174 |
|
|
success &= bmImport.invoke(bmImportConfigurator);
|
175 |
|
|
|
176 |
|
|
if (bmImportConfigurator.getCheck().equals(CHECK.CHECK_AND_IMPORT) || bmImportConfigurator.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ){
|
177 |
15a41eb5
|
Cherian Mathew
|
ICdmApplicationDefaultConfiguration app = bmImport.getCdmAppController();
|
178 |
91138b6c
|
Andreas Müller
|
TransactionStatus tx = app.startTransaction();
|
179 |
|
|
//make feature tree
|
180 |
|
|
// FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, bmImportConfigurator.getFeatureMap(), featureKeyList);
|
181 |
|
|
// FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
182 |
|
|
// tree.getRoot().addChild(imageNode);
|
183 |
|
|
// FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
184 |
|
|
// FeatureNode featureNode = tree.getRoot();
|
185 |
|
|
// tree.getRoot().addChild(distributionNode, featureNode.getChildCount() + 1);
|
186 |
|
|
// app.getFeatureTreeService().saveOrUpdate(tree);
|
187 |
|
|
mergeIntoCichorieae(app);
|
188 |
|
|
app.commitTransaction(tx);
|
189 |
|
|
}
|
190 |
|
|
|
191 |
|
|
logger.info("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
192 |
|
|
return success;
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
|
196 |
15a41eb5
|
Cherian Mathew
|
public boolean mergeIntoCichorieae(ICdmApplicationDefaultConfiguration app){
|
197 |
91138b6c
|
Andreas Müller
|
boolean success = true;
|
198 |
|
|
// String taraxTaraxacumUuidStr = "9a7bced0-fa1a-432e-9cca-57b62219cde6";
|
199 |
|
|
String taraxTaraxacumUuidStr = "b86f1156-091c-494d-a9c9-c84d71058f98";
|
200 |
|
|
UUID taraxTaraxacumUUID = UUID.fromString(taraxTaraxacumUuidStr);
|
201 |
|
|
|
202 |
|
|
String cichTaraxacumUuidStr = "c946ac62-b6c6-493b-8ed9-278fa38b931a";
|
203 |
|
|
UUID cichTaraxacumUUID = UUID.fromString(cichTaraxacumUuidStr);
|
204 |
|
|
|
205 |
|
|
Taxon taraxacumInCichTaxon = (Taxon)app.getTaxonService().find(cichTaraxacumUUID);
|
206 |
|
|
if (taraxacumInCichTaxon != null) {
|
207 |
|
|
logger.info("Merge Taraxacum");
|
208 |
|
|
Set<TaxonNode> taxonNodesInCich = taraxacumInCichTaxon.getTaxonNodes();
|
209 |
|
|
TaxonNode taxonNodeInCich = null;
|
210 |
|
|
TaxonNode parentNodeInCich = null;
|
211 |
|
|
Taxon parentInCich = null;
|
212 |
|
|
TaxonNode taxonNodeInTarax = null;
|
213 |
|
|
|
214 |
|
|
if (taxonNodesInCich == null || taxonNodesInCich.isEmpty()) {
|
215 |
|
|
logger.error("No taxon nodes found for Taraxacum in cichorieae database");
|
216 |
|
|
success = false;
|
217 |
|
|
} else {
|
218 |
|
|
logger.info(taxonNodesInCich.size()+ " taxon node(s) found for Taraxacum in Cich DB");
|
219 |
|
|
taxonNodeInCich = taxonNodesInCich.iterator().next();
|
220 |
|
|
parentNodeInCich = (TaxonNode) taxonNodeInCich.getParent();
|
221 |
|
|
parentInCich = parentNodeInCich.getTaxon();
|
222 |
|
|
}
|
223 |
|
|
|
224 |
|
|
Taxon taraxacumInTaraxTaxon = (Taxon)app.getTaxonService().find(taraxTaraxacumUUID);
|
225 |
|
|
|
226 |
|
|
Set<TaxonNode> taxonNodesInTarax = taraxacumInTaraxTaxon.getTaxonNodes();
|
227 |
|
|
|
228 |
401fe405
|
Andreas Müller
|
Classification treeInTaraxacum = null;
|
229 |
91138b6c
|
Andreas Müller
|
if (taxonNodesInTarax == null || taxonNodesInTarax.isEmpty()) {
|
230 |
|
|
logger.warn("No taxon nodes found for Taraxacum in taraxacum database");
|
231 |
|
|
success = false;
|
232 |
|
|
}else{
|
233 |
|
|
taxonNodeInTarax = taxonNodesInTarax.iterator().next();
|
234 |
401fe405
|
Andreas Müller
|
treeInTaraxacum = taxonNodeInTarax.getClassification();
|
235 |
91138b6c
|
Andreas Müller
|
}
|
236 |
|
|
|
237 |
|
|
//TODO reference
|
238 |
401fe405
|
Andreas Müller
|
Reference citation = null;
|
239 |
91138b6c
|
Andreas Müller
|
String microcitation = null;
|
240 |
|
|
|
241 |
bb38665e
|
Andreas Müller
|
taxonNodeInTarax = parentNodeInCich.addChildNode(taxonNodeInTarax, citation, microcitation);
|
242 |
401fe405
|
Andreas Müller
|
//parentNodeInCich.getClassification().addParentChild(parentInCich, taraxacumInTaraxTaxon, null, null);
|
243 |
91138b6c
|
Andreas Müller
|
|
244 |
|
|
parentNodeInCich.deleteChildNode(taxonNodeInCich);
|
245 |
|
|
|
246 |
|
|
app.getTaxonService().save(parentInCich);
|
247 |
6f35b3fb
|
p.kelbert
|
try{
|
248 |
|
|
app.getTaxonService().delete(taraxacumInCichTaxon);
|
249 |
|
|
}catch(Exception e){ //TODO debug to repair Jenkins
|
250 |
|
|
e.printStackTrace();
|
251 |
|
|
return false;
|
252 |
|
|
}
|
253 |
|
|
|
254 |
91138b6c
|
Andreas Müller
|
try {
|
255 |
401fe405
|
Andreas Müller
|
// app.getClassificationService().delete(treeInTaraxacum); //throws exception
|
256 |
91138b6c
|
Andreas Müller
|
} catch (Exception e) {
|
257 |
|
|
e.printStackTrace();
|
258 |
|
|
return false;
|
259 |
|
|
}
|
260 |
|
|
}else{
|
261 |
|
|
logger.warn("Taraxacum in cichorieae not found");
|
262 |
|
|
success = false;
|
263 |
|
|
}
|
264 |
|
|
return success;
|
265 |
|
|
}
|
266 |
|
|
|
267 |
|
|
public static void main(String[] args) {
|
268 |
|
|
TaraxacumActivator ta = new TaraxacumActivator();
|
269 |
|
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
270 |
|
|
|
271 |
|
|
ta.doImport(destination, hbm2dll);
|
272 |
|
|
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
}
|