1
|
/**
|
2
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.cdm.io.greece;
|
10
|
|
11
|
import java.net.URI;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.HashMap;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.stereotype.Component;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
23
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
24
|
import eu.etaxonomy.cdm.ext.geo.GeoServiceArea;
|
25
|
import eu.etaxonomy.cdm.ext.geo.GeoServiceAreaAnnotatedMapping;
|
26
|
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
|
27
|
import eu.etaxonomy.cdm.model.common.Language;
|
28
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
29
|
import eu.etaxonomy.cdm.model.common.TermType;
|
30
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
31
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
32
|
import eu.etaxonomy.cdm.model.description.Feature;
|
33
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
34
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
35
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
36
|
import eu.etaxonomy.cdm.model.description.State;
|
37
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
39
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
40
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
41
|
import eu.etaxonomy.cdm.model.name.Rank;
|
42
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
43
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
44
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
45
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
46
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
47
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
48
|
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
|
49
|
|
50
|
/**
|
51
|
* @author a.mueller
|
52
|
* @date 14.12.2016
|
53
|
*
|
54
|
*/
|
55
|
|
56
|
@Component
|
57
|
public class FloraHellenicaTaxonImport<CONFIG extends FloraHellenicaImportConfigurator>
|
58
|
extends FloraHellenicaImportBase<CONFIG>{
|
59
|
|
60
|
private static final long serialVersionUID = -6291948918967763381L;
|
61
|
private static final Logger logger = Logger.getLogger(FloraHellenicaTaxonImport.class);
|
62
|
|
63
|
private static final String LIFE_FORM = "Life-form";
|
64
|
private static final String STATUS = "Status";
|
65
|
private static final String CHOROLOGICAL_CATEGOGY = "Chorological categogy";
|
66
|
|
67
|
|
68
|
private static UUID rootUuid = UUID.fromString("aa667b0b-b417-470e-a9b0-ef9409a3431e");
|
69
|
private static UUID plantaeUuid = UUID.fromString("4f151932-ab97-4d81-b88e-46fe82cd3e88");
|
70
|
|
71
|
private OrderedTermVocabulary<NamedArea> areasVoc;
|
72
|
private NamedArea greece;
|
73
|
private OrderedTermVocabulary<State> lifeformVoc;
|
74
|
private OrderedTermVocabulary<State> habitatVoc;
|
75
|
private Map<String, State> lifeformMap = new HashMap<>();
|
76
|
|
77
|
private OrderedTermVocabulary<PresenceAbsenceTerm> statusVoc;
|
78
|
private PresenceAbsenceTerm rangeRestricted;
|
79
|
private PresenceAbsenceTerm doubtfullyRangeRestricted;
|
80
|
|
81
|
|
82
|
private OrderedTermVocabulary<State> chorologicalVoc;
|
83
|
private Map<String, State> chorologyMap = new HashMap<>();
|
84
|
|
85
|
|
86
|
private static List<String> expectedKeys= Arrays.asList(new String[]{
|
87
|
"Unique ID","Group","Family","Genus","Species","Species Author","Subspecies","Subspecies Author",
|
88
|
"IoI","NPi","SPi","Pe","StE","EC","NC","NE","NAe","WAe","Kik","KK","EAe",
|
89
|
STATUS,CHOROLOGICAL_CATEGOGY,LIFE_FORM,"A","C","G","H","M","P","R","W", "Taxon"
|
90
|
});
|
91
|
|
92
|
private String lastGenus;
|
93
|
private String lastSpecies;
|
94
|
private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
|
95
|
|
96
|
@Override
|
97
|
protected String getWorksheetName() {
|
98
|
return "valid taxa names";
|
99
|
}
|
100
|
|
101
|
/**
|
102
|
* {@inheritDoc}
|
103
|
*/
|
104
|
@Override
|
105
|
protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
|
106
|
initAreaVocabulary(state);
|
107
|
initLifeformVocabulary(state);
|
108
|
initHabitatVocabulary(state);
|
109
|
initChorologicalVocabulary(state);
|
110
|
initStatusVocabulary(state);
|
111
|
makeFeatureTree(state);
|
112
|
|
113
|
String line = state.getCurrentLine() + ": ";
|
114
|
HashMap<String, String> record = state.getOriginalRecord();
|
115
|
|
116
|
Set<String> keys = record.keySet();
|
117
|
for (String key: keys) {
|
118
|
if (! expectedKeys.contains(key)){
|
119
|
logger.warn(line + "Unexpected Key: " + key);
|
120
|
}
|
121
|
}
|
122
|
|
123
|
String noStr = getValue(record, "Unique ID");
|
124
|
Taxon taxon = makeTaxon(state, line, record, noStr);
|
125
|
|
126
|
//Distribution
|
127
|
TaxonDescription desc = getTaxonDescription(taxon);
|
128
|
makeDistribution(state, line, noStr, desc);
|
129
|
|
130
|
makeChorologicalCategory(state, line, noStr, desc);
|
131
|
|
132
|
//lifeform
|
133
|
makeLifeform(state, line, noStr, desc);
|
134
|
|
135
|
//habitat
|
136
|
makeHabitat(state, line, noStr, desc);
|
137
|
|
138
|
state.putTaxon(noStr, taxon);
|
139
|
}
|
140
|
|
141
|
boolean hasFeatureTree = false;
|
142
|
/**
|
143
|
* @param state
|
144
|
*/
|
145
|
private void makeFeatureTree(SimpleExcelTaxonImportState<CONFIG> state) {
|
146
|
if (hasFeatureTree ){
|
147
|
return;
|
148
|
}
|
149
|
if (getFeatureTreeService().find(state.getConfig().getUuidFeatureTree()) != null){
|
150
|
hasFeatureTree = true;
|
151
|
return;
|
152
|
}
|
153
|
FeatureTree result = FeatureTree.NewInstance(state.getConfig().getUuidFeatureTree());
|
154
|
result.setTitleCache(state.getConfig().getFeatureTreeTitle(), true);
|
155
|
FeatureNode root = result.getRoot();
|
156
|
FeatureNode newNode;
|
157
|
|
158
|
ITermService service = getTermService();
|
159
|
Feature newFeature = (Feature)service.find(Feature.DISTRIBUTION().getUuid());
|
160
|
newNode = FeatureNode.NewInstance(newFeature);
|
161
|
root.addChild(newNode);
|
162
|
|
163
|
newFeature = (Feature)service.find(FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature);
|
164
|
newNode = FeatureNode.NewInstance(newFeature);
|
165
|
root.addChild(newNode);
|
166
|
|
167
|
newFeature = (Feature)service.find(Feature.LIFEFORM().getUuid());
|
168
|
newNode = FeatureNode.NewInstance(newFeature);
|
169
|
root.addChild(newNode);
|
170
|
|
171
|
newFeature = (Feature)service.find(Feature.HABITAT().getUuid());
|
172
|
newNode = FeatureNode.NewInstance(newFeature);
|
173
|
root.addChild(newNode);
|
174
|
|
175
|
|
176
|
newFeature = (Feature)service.find(Feature.NOTES().getUuid());
|
177
|
newNode = FeatureNode.NewInstance(newFeature);
|
178
|
root.addChild(newNode);
|
179
|
|
180
|
getFeatureTreeService().saveOrUpdate(result);
|
181
|
hasFeatureTree = true;
|
182
|
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* @param state
|
187
|
* @param line
|
188
|
* @param noStr
|
189
|
* @param desc
|
190
|
*/
|
191
|
private void makeChorologicalCategory(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
|
192
|
TaxonDescription desc) {
|
193
|
|
194
|
HashMap<String, String> record = state.getOriginalRecord();
|
195
|
String valueStr = getValue(record, CHOROLOGICAL_CATEGOGY);
|
196
|
|
197
|
String value = valueStr;
|
198
|
if (value == null){
|
199
|
return;
|
200
|
}
|
201
|
Feature choroFeature = getFeature(state, FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature,
|
202
|
"Chorology", "The Chorological Category", "Choro", null);
|
203
|
CategoricalData catData = CategoricalData.NewInstance(choroFeature);
|
204
|
catData.setOrderRelevant(true);
|
205
|
|
206
|
String[] splits = value.split(" & ");
|
207
|
replaceDirection(splits, line);
|
208
|
for (String split: splits){
|
209
|
String[] splitsA = split.split("/");
|
210
|
for (String splitA : splitsA){
|
211
|
String[] splitsB = splitA.split(", ");
|
212
|
for (String splitB : splitsB){
|
213
|
splitB = normalizeChorology(splitB);
|
214
|
State choroTerm = chorologyMap.get(splitB);
|
215
|
if (choroTerm == null){
|
216
|
logger.warn(line + "Some chorology could not be recognized in: " + value + "; Term was: " +splitB);
|
217
|
}else{
|
218
|
catData.addStateData(choroTerm);
|
219
|
}
|
220
|
}
|
221
|
}
|
222
|
}
|
223
|
if (catData.getStateData().size() > 1){
|
224
|
catData.setOrderRelevant(true);
|
225
|
}
|
226
|
|
227
|
desc.addElement(catData);
|
228
|
}
|
229
|
|
230
|
/**
|
231
|
* @param splitB
|
232
|
* @return
|
233
|
*/
|
234
|
private String normalizeChorology(String choroStr) {
|
235
|
choroStr = choroStr.trim()
|
236
|
.replace("BK", "Bk")
|
237
|
.replace("Austral.", "Austr.")
|
238
|
.replace("trop.As.", "trop. As.");
|
239
|
if (choroStr.startsWith("[") && !choroStr.endsWith("]")){
|
240
|
choroStr += "]";
|
241
|
}else if (!choroStr.startsWith("[") && choroStr.endsWith("]")){
|
242
|
choroStr = "[" + choroStr;
|
243
|
}
|
244
|
return choroStr;
|
245
|
}
|
246
|
|
247
|
/**
|
248
|
* @param splits
|
249
|
* @param line
|
250
|
*/
|
251
|
private void replaceDirection(String[] splits, String line) {
|
252
|
if (splits.length > 1){
|
253
|
String[] divs = splits[1].split("-");
|
254
|
if (divs.length == 2){
|
255
|
splits[0] = splits[0] + "-" + divs[1];
|
256
|
}else{
|
257
|
logger.warn(line + "Splits[1] has not expected format: " + splits[1]);
|
258
|
}
|
259
|
}
|
260
|
}
|
261
|
|
262
|
/**
|
263
|
* @param state
|
264
|
* @param line
|
265
|
* @param noStr
|
266
|
* @param desc
|
267
|
*/
|
268
|
private void makeLifeform(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
|
269
|
TaxonDescription desc) {
|
270
|
HashMap<String, String> record = state.getOriginalRecord();
|
271
|
String value = getValue(record, LIFE_FORM);
|
272
|
String[] splits = value.split("\\s+");
|
273
|
if (splits.length > 2){
|
274
|
logger.warn("Unexpected length of lifeform: " + value + " line: " + line );
|
275
|
}
|
276
|
CategoricalData catData = CategoricalData.NewInstance(Feature.LIFEFORM());
|
277
|
for (String split : splits){
|
278
|
State lifeform = lifeformMap.get(split);
|
279
|
if (lifeform == null){
|
280
|
logger.warn(line + "Unexpected lifeform: " + value);
|
281
|
}else{
|
282
|
catData.addStateData(lifeform);
|
283
|
}
|
284
|
}
|
285
|
desc.addElement(catData);
|
286
|
|
287
|
}
|
288
|
|
289
|
/**
|
290
|
* @param state
|
291
|
* @param line
|
292
|
* @param noStr
|
293
|
* @param desc
|
294
|
*/
|
295
|
private void makeHabitat(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
|
296
|
TaxonDescription desc) {
|
297
|
CategoricalData catData = CategoricalData.NewInstance(Feature.HABITAT());
|
298
|
handleHabitat(state, catData, "A", FloraHellenicaTransformer.uuidHabitatA, line, noStr);
|
299
|
handleHabitat(state, catData, "C", FloraHellenicaTransformer.uuidHabitatC, line, noStr);
|
300
|
handleHabitat(state, catData, "G", FloraHellenicaTransformer.uuidHabitatG, line, noStr);
|
301
|
handleHabitat(state, catData, "H", FloraHellenicaTransformer.uuidHabitatH, line, noStr);
|
302
|
handleHabitat(state, catData, "M", FloraHellenicaTransformer.uuidHabitatM, line, noStr);
|
303
|
handleHabitat(state, catData, "P", FloraHellenicaTransformer.uuidHabitatP, line, noStr);
|
304
|
handleHabitat(state, catData, "R", FloraHellenicaTransformer.uuidHabitatR, line, noStr);
|
305
|
handleHabitat(state, catData, "W", FloraHellenicaTransformer.uuidHabitatW, line, noStr);
|
306
|
desc.addElement(catData);
|
307
|
}
|
308
|
|
309
|
/**
|
310
|
* @param state
|
311
|
* @param catData
|
312
|
* @param string
|
313
|
* @param uuidhabitata
|
314
|
* @param line
|
315
|
* @param noStr
|
316
|
*/
|
317
|
private void handleHabitat(SimpleExcelTaxonImportState<CONFIG> state, CategoricalData catData, String label,
|
318
|
UUID uuidHabitat, String line, String noStr) {
|
319
|
HashMap<String, String> record = state.getOriginalRecord();
|
320
|
String value = getValue(record, "" + label);
|
321
|
if (value == null){
|
322
|
//do nothing
|
323
|
}else if (value.matches("[ACGHMPRW]")){
|
324
|
State habitatState = this.getStateTerm(state, uuidHabitat, null, null, null, habitatVoc);
|
325
|
catData.addStateData(habitatState);
|
326
|
}else{
|
327
|
logger.warn(line + "Unrecognized habitat state '" + value + "' for " + label);
|
328
|
}
|
329
|
}
|
330
|
|
331
|
/**
|
332
|
* @param state
|
333
|
* @param line
|
334
|
* @param noStr
|
335
|
* @param desc
|
336
|
*/
|
337
|
private void makeDistribution(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
|
338
|
TaxonDescription desc) {
|
339
|
//TODO status Greece
|
340
|
handleStatus(state, desc, STATUS, FloraHellenicaTransformer.uuidAreaGreece, line, noStr);
|
341
|
|
342
|
handleDistribution(state, desc, "IoI", FloraHellenicaTransformer.uuidAreaIoI, line, noStr);
|
343
|
handleDistribution(state, desc, "NPi", FloraHellenicaTransformer.uuidAreaNPi, line, noStr);
|
344
|
handleDistribution(state, desc, "SPi", FloraHellenicaTransformer.uuidAreaSPi, line, noStr);
|
345
|
handleDistribution(state, desc, "Pe", FloraHellenicaTransformer.uuidAreaPe, line, noStr);
|
346
|
handleDistribution(state, desc, "StE", FloraHellenicaTransformer.uuidAreaStE, line, noStr);
|
347
|
handleDistribution(state, desc, "EC", FloraHellenicaTransformer.uuidAreaEC, line, noStr);
|
348
|
handleDistribution(state, desc, "NC", FloraHellenicaTransformer.uuidAreaNC, line, noStr);
|
349
|
handleDistribution(state, desc, "NE", FloraHellenicaTransformer.uuidAreaNE, line, noStr);
|
350
|
handleDistribution(state, desc, "NAe", FloraHellenicaTransformer.uuidAreaNAe, line, noStr);
|
351
|
handleDistribution(state, desc, "WAe", FloraHellenicaTransformer.uuidAreaWAe, line, noStr);
|
352
|
handleDistribution(state, desc, "Kik", FloraHellenicaTransformer.uuidAreaKik, line, noStr);
|
353
|
handleDistribution(state, desc, "KK", FloraHellenicaTransformer.uuidAreaKK, line, noStr);
|
354
|
handleDistribution(state, desc, "EAe", FloraHellenicaTransformer.uuidAreaEAe, line, noStr);
|
355
|
}
|
356
|
|
357
|
/**
|
358
|
* @param state
|
359
|
* @param line
|
360
|
* @param record
|
361
|
* @param noStr
|
362
|
* @return
|
363
|
*/
|
364
|
private Taxon makeTaxon(SimpleExcelTaxonImportState<CONFIG> state, String line, HashMap<String, String> record,
|
365
|
String noStr) {
|
366
|
|
367
|
TaxonNode familyTaxon = getFamilyTaxon(record, state);
|
368
|
if (familyTaxon == null){
|
369
|
logger.warn(line + "Family not created: " + record.get("Family"));
|
370
|
}
|
371
|
|
372
|
String genusStr = getValue(record, "Genus");
|
373
|
String speciesStr = getValue(record, "Species");
|
374
|
String speciesAuthorStr = getValue(record, "Species Author");
|
375
|
String subSpeciesStr = getValue(record, "Subspecies");
|
376
|
String subSpeciesAuthorStr = getValue(record, "Subspecies Author");
|
377
|
boolean isSubSpecies = isNotBlank(subSpeciesStr);
|
378
|
boolean isAutonym = isSubSpecies && speciesStr.equals(subSpeciesStr);
|
379
|
if (isSubSpecies && ! isAutonym && isBlank(subSpeciesAuthorStr)){
|
380
|
logger.warn(line + "Non-Autonym subspecies has no auhtor");
|
381
|
}else if (isSubSpecies && isAutonym && isNotBlank(subSpeciesAuthorStr)){
|
382
|
logger.warn(line + "Autonym subspecies has subspecies auhtor");
|
383
|
}
|
384
|
|
385
|
String[] nameParts;
|
386
|
if (!isSubSpecies){
|
387
|
nameParts = new String[]{genusStr, speciesStr, speciesAuthorStr};
|
388
|
}else if (!isAutonym){
|
389
|
nameParts = new String[]{genusStr, speciesStr, "subsp. " + subSpeciesStr, subSpeciesAuthorStr};
|
390
|
}else{
|
391
|
nameParts = new String[]{genusStr, speciesStr, speciesAuthorStr, "subsp. " + subSpeciesStr};
|
392
|
}
|
393
|
|
394
|
String nameStr = CdmUtils.concat(" ", nameParts);
|
395
|
Rank rank = isSubSpecies ? Rank.SUBSPECIES() : Rank.SPECIES();
|
396
|
BotanicalName name = (BotanicalName)parser.parseFullName(nameStr, state.getConfig().getNomenclaturalCode(), rank);
|
397
|
if (name.isProtectedTitleCache()){
|
398
|
logger.warn(line + "Name could not be parsed: " + nameStr);
|
399
|
}
|
400
|
Taxon taxon = Taxon.NewInstance(name, getSecReference(state));
|
401
|
taxon.addImportSource(noStr, getWorksheetName(), getSourceCitation(state), null);
|
402
|
// String parentStr = isSubSpecies ? makeSpeciesKey(genusStr, speciesStr, speciesAuthorStr) : genusStr;
|
403
|
String parentStr = genusStr;
|
404
|
boolean genusAsBefore = genusStr.equals(lastGenus);
|
405
|
boolean speciesAsBefore = speciesStr.equals(lastSpecies);
|
406
|
TaxonNode parent = getParent(state, parentStr);
|
407
|
if (parent != null){
|
408
|
// if (!isSubSpecies && genusAsBefore || isSubSpecies && speciesAsBefore){
|
409
|
if (genusAsBefore ){
|
410
|
//everything as expected
|
411
|
TaxonNode newNode = parent.addChildTaxon(taxon, getSecReference(state), null);
|
412
|
getTaxonNodeService().save(newNode);
|
413
|
}else{
|
414
|
logger.warn(line + "Unexpected non-missing parent");
|
415
|
}
|
416
|
}else{
|
417
|
// if (isSubSpecies){
|
418
|
// logger.warn(line + "Subspecies should always have an existing parent");
|
419
|
// }else
|
420
|
if (genusAsBefore){
|
421
|
logger.warn(line + "Unexpected missing genus parent");
|
422
|
}else{
|
423
|
parent = makeGenusNode(state, record, genusStr);
|
424
|
TaxonNode newNode = parent.addChildTaxon(taxon, getSecReference(state), null);
|
425
|
getTaxonNodeService().save(newNode);
|
426
|
}
|
427
|
}
|
428
|
if (!isSubSpecies){
|
429
|
state.putHigherTaxon(makeSpeciesKey(genusStr, speciesStr, speciesAuthorStr), taxon);
|
430
|
}
|
431
|
|
432
|
// this.lastFamily = familyStr
|
433
|
this.lastGenus = genusStr;
|
434
|
this.lastSpecies = speciesStr;
|
435
|
return taxon;
|
436
|
}
|
437
|
|
438
|
/**
|
439
|
* @param genusStr
|
440
|
* @param speciesStr
|
441
|
* @param speciesAuthorStr
|
442
|
* @return
|
443
|
*/
|
444
|
private String makeSpeciesKey(String genusStr, String speciesStr, String speciesAuthorStr) {
|
445
|
return CdmUtils.concat(" ", new String[]{genusStr, speciesStr, speciesAuthorStr});
|
446
|
}
|
447
|
|
448
|
/**
|
449
|
* @param state
|
450
|
* @param record
|
451
|
* @param genusStr
|
452
|
* @return
|
453
|
*/
|
454
|
private TaxonNode makeGenusNode(SimpleExcelTaxonImportState<CONFIG> state,
|
455
|
HashMap<String, String> record, String genusStr) {
|
456
|
BotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
|
457
|
name.setGenusOrUninomial(genusStr);
|
458
|
Taxon genus = Taxon.NewInstance(name, getSecReference(state));
|
459
|
TaxonNode family = getFamilyTaxon(record, state);
|
460
|
TaxonNode genusNode = family.addChildTaxon(genus, getSecReference(state), null);
|
461
|
state.putHigherTaxon(genusStr, genus);
|
462
|
genus.addSource(makeOriginalSource(state));
|
463
|
getTaxonNodeService().save(genusNode);
|
464
|
return genusNode;
|
465
|
}
|
466
|
|
467
|
/**
|
468
|
* @param state
|
469
|
* @param parentStr
|
470
|
* @return
|
471
|
*/
|
472
|
private TaxonNode getParent(SimpleExcelTaxonImportState<CONFIG> state, String parentStr) {
|
473
|
Taxon taxon = state.getHigherTaxon(parentStr);
|
474
|
|
475
|
return taxon == null ? null : taxon.getTaxonNodes().iterator().next();
|
476
|
}
|
477
|
|
478
|
/**
|
479
|
* @param record
|
480
|
* @param state
|
481
|
* @return
|
482
|
*/
|
483
|
private TaxonNode getFamilyTaxon(HashMap<String, String> record, SimpleExcelTaxonImportState<CONFIG> state) {
|
484
|
String familyStr = getValue(record, "Family");
|
485
|
if (familyStr == null){
|
486
|
return null;
|
487
|
}
|
488
|
familyStr = familyStr.trim();
|
489
|
|
490
|
Taxon family = state.getHigherTaxon(familyStr);
|
491
|
TaxonNode familyNode;
|
492
|
if (family != null){
|
493
|
familyNode = family.getTaxonNodes().iterator().next();
|
494
|
}else{
|
495
|
BotanicalName name = makeFamilyName(state, familyStr);
|
496
|
Reference sec = getSecReference(state);
|
497
|
family = Taxon.NewInstance(name, sec);
|
498
|
|
499
|
ITaxonTreeNode groupNode = getGroupTaxon(record, state);
|
500
|
familyNode = groupNode.addChildTaxon(family, sec, null);
|
501
|
state.putHigherTaxon(familyStr, family);
|
502
|
getTaxonNodeService().save(familyNode);
|
503
|
}
|
504
|
|
505
|
return familyNode;
|
506
|
}
|
507
|
|
508
|
/**
|
509
|
* @param record
|
510
|
* @param state
|
511
|
* @return
|
512
|
*/
|
513
|
private TaxonNode getGroupTaxon(HashMap<String, String> record, SimpleExcelTaxonImportState<CONFIG> state) {
|
514
|
String groupStr = getValue(record, "Group");
|
515
|
if (groupStr == null){
|
516
|
return null;
|
517
|
}
|
518
|
groupStr = groupStr.trim();
|
519
|
|
520
|
Taxon group = state.getHigherTaxon(groupStr);
|
521
|
TaxonNode groupNode;
|
522
|
if (group != null){
|
523
|
groupNode = group.getTaxonNodes().iterator().next();
|
524
|
}else{
|
525
|
BotanicalName name = makeFamilyName(state, groupStr);
|
526
|
Reference sec = getSecReference(state);
|
527
|
group = Taxon.NewInstance(name, sec);
|
528
|
ITaxonTreeNode rootNode = getClassification(state);
|
529
|
groupNode = rootNode.addChildTaxon(group, sec, null);
|
530
|
state.putHigherTaxon(groupStr, group);
|
531
|
getTaxonNodeService().save(groupNode);
|
532
|
}
|
533
|
|
534
|
return groupNode;
|
535
|
}
|
536
|
|
537
|
private TaxonNode rootNode;
|
538
|
private TaxonNode getClassification(SimpleExcelTaxonImportState<CONFIG> state) {
|
539
|
if (rootNode == null){
|
540
|
Reference sec = getSecReference(state);
|
541
|
String classificationName = state.getConfig().getClassificationName();
|
542
|
Language language = Language.DEFAULT();
|
543
|
Classification classification = Classification.NewInstance(classificationName, sec, language);
|
544
|
classification.setUuid(state.getConfig().getClassificationUuid());
|
545
|
classification.getRootNode().setUuid(rootUuid);
|
546
|
|
547
|
BotanicalName plantaeName = TaxonNameFactory.NewBotanicalInstance(Rank.KINGDOM());
|
548
|
plantaeName.setGenusOrUninomial("Plantae");
|
549
|
Taxon plantae = Taxon.NewInstance(plantaeName, sec);
|
550
|
TaxonNode plantaeNode = classification.addChildTaxon(plantae, null, null);
|
551
|
plantaeNode.setUuid(plantaeUuid);
|
552
|
getClassificationService().save(classification);
|
553
|
|
554
|
rootNode = plantaeNode;
|
555
|
}
|
556
|
return rootNode;
|
557
|
}
|
558
|
|
559
|
/**
|
560
|
* @param desc
|
561
|
* @param string
|
562
|
* @param uuidUserDefinedAnnotationTypeVocabulary
|
563
|
*/
|
564
|
private void handleDistribution(SimpleExcelTaxonImportState<CONFIG> state,
|
565
|
TaxonDescription desc, String key, UUID uuid, String line, String id) {
|
566
|
HashMap<String, String> record = state.getOriginalRecord();
|
567
|
String value = getValue(record, key);
|
568
|
if (value == null || value.matches("[x\\.\\?]")){
|
569
|
NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
|
570
|
Distribution dist;
|
571
|
if (".".equals(value)){
|
572
|
logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
|
573
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
|
574
|
}else if (value == null){
|
575
|
//TODO is absent wanted
|
576
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
|
577
|
}else if ("x".equals(value)){
|
578
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT());
|
579
|
}else if ("?".equals(value)){
|
580
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT_DOUBTFULLY());
|
581
|
}else {
|
582
|
logger.warn(line + "Not matching status. THis should not happpen '" + value + "' for " + key);
|
583
|
return;
|
584
|
}
|
585
|
desc.addElement(dist);
|
586
|
dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
|
587
|
}else {
|
588
|
logger.warn(line + "Unrecognized distribution status '" + value + "' for " + key);
|
589
|
}
|
590
|
}
|
591
|
|
592
|
private void handleStatus(SimpleExcelTaxonImportState<CONFIG> state,
|
593
|
TaxonDescription desc, String key, UUID uuid, String line, String id) {
|
594
|
HashMap<String, String> record = state.getOriginalRecord();
|
595
|
String value = getValue(record, key);
|
596
|
NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
|
597
|
Distribution dist;
|
598
|
if (value == null || ".".equals(value) ){
|
599
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.NATIVE());
|
600
|
if (".".equals(value)){
|
601
|
logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
|
602
|
}
|
603
|
}else if ("Range-restricted".equals(value)){
|
604
|
dist = Distribution.NewInstance(area, rangeRestricted);
|
605
|
}else if ("?Range-restricted".equals(value)){
|
606
|
dist = Distribution.NewInstance(area, doubtfullyRangeRestricted);
|
607
|
}else if ("Xenophyte".equals(value)){
|
608
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED());
|
609
|
}else if ("?Xenophyte".equals(value)){
|
610
|
dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED());
|
611
|
}else {
|
612
|
logger.warn(line + "Not matching status. This should not happpen '" + value + "' for " + key);
|
613
|
return;
|
614
|
}
|
615
|
desc.addElement(dist);
|
616
|
dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
|
617
|
}
|
618
|
|
619
|
@SuppressWarnings("unchecked")
|
620
|
private void initAreaVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
|
621
|
if (areasVoc == null){
|
622
|
areasVoc = (OrderedTermVocabulary<NamedArea>)this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
|
623
|
if (areasVoc == null){
|
624
|
createAreasVoc(state);
|
625
|
}
|
626
|
}
|
627
|
}
|
628
|
|
629
|
|
630
|
/**
|
631
|
* @param state
|
632
|
*/
|
633
|
private void initChorologicalVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
|
634
|
if (chorologicalVoc == null){
|
635
|
UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologicalVoc;
|
636
|
chorologicalVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
|
637
|
if (chorologicalVoc == null){
|
638
|
createChorologicalVoc(state, uuid);
|
639
|
}
|
640
|
}
|
641
|
|
642
|
}
|
643
|
|
644
|
|
645
|
@SuppressWarnings("unchecked")
|
646
|
private void initLifeformVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
|
647
|
if (lifeformVoc == null){
|
648
|
UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc;
|
649
|
lifeformVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
|
650
|
if (lifeformVoc == null){
|
651
|
createLifeformVoc(state, uuid);
|
652
|
}
|
653
|
}
|
654
|
}
|
655
|
|
656
|
/**
|
657
|
* @param state
|
658
|
* @param vocUuid
|
659
|
*/
|
660
|
private void createLifeformVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
|
661
|
//voc
|
662
|
URI termSourceUri = null;
|
663
|
String label = "Checklist of Greece Lifeforms";
|
664
|
String description = "Lifeforms as used in the Checklist of Greece";
|
665
|
lifeformVoc = OrderedTermVocabulary.NewInstance(TermType.State,
|
666
|
description, label, null, termSourceUri);
|
667
|
lifeformVoc.setUuid(vocUuid);
|
668
|
|
669
|
addLifeform(state, "A", "Aquatics", FloraHellenicaTransformer.uuidLifeformA);
|
670
|
addLifeform(state, "C", "Chamaephytes", FloraHellenicaTransformer.uuidLifeformC);
|
671
|
addLifeform(state, "G", "Geophytes (Cryptophytes)", FloraHellenicaTransformer.uuidLifeformG);
|
672
|
addLifeform(state, "H", "Hemicryptophytes", FloraHellenicaTransformer.uuidLifeformH);
|
673
|
addLifeform(state, "P", "Phanerophytes", FloraHellenicaTransformer.uuidLifeformP);
|
674
|
addLifeform(state, "T", "Therophytes", FloraHellenicaTransformer.uuidLifeformT);
|
675
|
this.getVocabularyService().save(lifeformVoc);
|
676
|
return;
|
677
|
}
|
678
|
|
679
|
|
680
|
/**
|
681
|
* @param state
|
682
|
* @param uuid
|
683
|
*/
|
684
|
private void createChorologicalVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
|
685
|
//voc
|
686
|
URI termSourceUri = null;
|
687
|
String label = "Checklist of Greece Chorological Categories";
|
688
|
String description = "Chorological Categories as used in the Checklist of Greece";
|
689
|
chorologicalVoc = OrderedTermVocabulary.NewInstance(TermType.State,
|
690
|
description, label, null, termSourceUri);
|
691
|
chorologicalVoc.setUuid(vocUuid);
|
692
|
|
693
|
addChorological(state, "*", "Greek endemic", "Greek endemics (incl. single-island and single-mountain endemics)", FloraHellenicaTransformer.uuidChorologicalStar);
|
694
|
addChorological(state, "Bk", "Balkan", "Taxa restricted to Balkan countries, occasionally extending to adjacent parts of SE Europe", FloraHellenicaTransformer.uuidChorologicalBk);
|
695
|
addChorological(state, "BI", "Balkan-Italy", "Taxa restricted to Balkan countries and Italy (amphi-Adreatic)", FloraHellenicaTransformer.uuidChorologicalBI);
|
696
|
addChorological(state, "BA", "Balkan-Anatolia", "Taxa restricted to Balkan countries and to Asia minor (Anatolia), occasionally extending to S Ukraine (Crimea), adjacent Caucasian countries (Georgia, Armenia) or N Iraq", FloraHellenicaTransformer.uuidChorologicalBA);
|
697
|
addChorological(state, "BC", "Balkan-Central Europe", "Taxa distributed in the Balkans, Carpathians, Alps and adjacent areas (mainly in the mountains)", FloraHellenicaTransformer.uuidChorologicalBC);
|
698
|
addChorological(state, "EM", "East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorologicalEM);
|
699
|
addChorological(state, "Me", "Mediterranean", "Taxa with a circum-Mediterranean distribution including Portugal, occasionally extending to the Caucasus area and N Iran", FloraHellenicaTransformer.uuidChorologicalMe);
|
700
|
addChorological(state, "MA", "Mediterranean-Atlantic", "Taxa restricted to maritime W Europe and the Mediterranean", FloraHellenicaTransformer.uuidChorologicalMA);
|
701
|
addChorological(state, "ME", "Mediterranean-European", "Taxa restricted to the Mediterranean and temperate Europe, occasionally extending to NW Africa and the Caucasus area", FloraHellenicaTransformer.uuidChorologicalME);
|
702
|
addChorological(state, "MS", "Mediterranean-SW Asian", "Taxa distributed in one or more Mediterranean countries and extending to SW and C Asia", FloraHellenicaTransformer.uuidChorologicalMS);
|
703
|
addChorological(state, "EA", "European-SW Asian", "Eruopean taxa (occasionally reachin N Africa) with a distribution extending to SW Asia, occasionally reaching C Asia", FloraHellenicaTransformer.uuidChorologicalEA);
|
704
|
addChorological(state, "ES", "Euro-Siberian", "Taxa with main distribution in temperate Eurasia (occasionally reaching the Caucasus area)", FloraHellenicaTransformer.uuidChorologicalES);
|
705
|
addChorological(state, "Eu", "European", "Taxa with a distribution all over Europe. In S European countries this category in fact represents the C European element", FloraHellenicaTransformer.uuidChorologicalEu);
|
706
|
addChorological(state, "Pt", "Paleotemperate", "Taxa of extratropical Eurasia including the Himalaya and E Asia, not (or at most marginally) extending to North America", FloraHellenicaTransformer.uuidChorologicalPt);
|
707
|
addChorological(state, "Ct", "Circumtemperate", "Taxa of both extratropical Eurasia and North America", FloraHellenicaTransformer.uuidChorologicalCt);
|
708
|
addChorological(state, "IT", "Irano-Turanian", "Taxa with main distribution in arid SW and C Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalIT);
|
709
|
addChorological(state, "SS", "Saharo-Sindian", "Taxa with main distribution in arid N Africa and SQ Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalSS);
|
710
|
addChorological(state, "ST", "Subtropical-tropical", "Taxa widespread in the warmer regions of both hemispheres", FloraHellenicaTransformer.uuidChorologicalST);
|
711
|
addChorological(state, "Bo", "(Circum-)Boreal", "Taxa with main distribution in N and high-montane Eurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalBo);
|
712
|
addChorological(state, "AA", "Arctic-Alpine", "Taxa with main distribution beyound the N and aove the high-montane timerlines o fEurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalAA);
|
713
|
addChorological(state, "Co", "Cosmopolitan", "Taxa distributed in all continents, i.e. beyond the N hemisphere. This category may be given in brackets after the known or supposed native distribution in cases of taxa that have been spread worldwide by humans", FloraHellenicaTransformer.uuidChorologicalCo);
|
714
|
|
715
|
addChorological(state, "[trop.]", "[tropical]", "", FloraHellenicaTransformer.uuidChorologicaltrop);
|
716
|
addChorological(state, "[subtrop.]", "[subtropical]", "", FloraHellenicaTransformer.uuidChorologicalsubtrop);
|
717
|
addChorological(state, "[paleotrop.]", "[paleotropical]", "", FloraHellenicaTransformer.uuidChorologicalpaleotrop);
|
718
|
addChorological(state, "[neotrop.]", "[neotropical]", "", FloraHellenicaTransformer.uuidChorologicalneotrop);
|
719
|
addChorological(state, "[pantrop.]", "[pantropical]", "", FloraHellenicaTransformer.uuidChorologicalpantrop);
|
720
|
addChorological(state, "[N-Am.]", "[North American]", "", FloraHellenicaTransformer.uuidChorologicalN_Am);
|
721
|
addChorological(state, "[S-Am.]", "[South American]", "", FloraHellenicaTransformer.uuidChorologicalS_Am);
|
722
|
addChorological(state, "[E-As.]", "[East Asian]", "", FloraHellenicaTransformer.uuidChorologicalE_As);
|
723
|
addChorological(state, "[SE-As.", "[South East Asian]", "", FloraHellenicaTransformer.uuidChorologicalSE_As);
|
724
|
addChorological(state, "[S-Afr.]", "[South African]", "", FloraHellenicaTransformer.uuidChorologicalS_Afr);
|
725
|
addChorological(state, "[Arab.]", "[Arabian]", "", FloraHellenicaTransformer.uuidChorologicalArab);
|
726
|
addChorological(state, "[Arab. NE-Afr.]", "[Arabian and North East African]", "", FloraHellenicaTransformer.uuidChorologicalArab_NE_Afr);
|
727
|
addChorological(state, "[Caucas.]", "[Caucasian]", "", FloraHellenicaTransformer.uuidChorologicalCaucas);
|
728
|
addChorological(state, "[Pontic]", "[Pontic]", "", FloraHellenicaTransformer.uuidChorologicalPontic);
|
729
|
addChorological(state, "[Europ.]", "[European]", "", FloraHellenicaTransformer.uuidChorologicalEurop);
|
730
|
addChorological(state, "[Austr.]", "[Australian]", "", FloraHellenicaTransformer.uuidChorologicalAustral);
|
731
|
|
732
|
addChorological(state, "[W-Med.]", "[West Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalW_Med);
|
733
|
addChorological(state, "[C-Med.]", "[Central Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalC_Med);
|
734
|
addChorological(state, "[W-Eur.]", "[West European]", "", FloraHellenicaTransformer.uuidChorologicalW_Eur);
|
735
|
addChorological(state, "[S-Eur.]", "[South European]", "", FloraHellenicaTransformer.uuidChorologicalS_Eur);
|
736
|
addChorological(state, "[C-Am.]", "[Central American]", "", FloraHellenicaTransformer.uuidChorologicalC_Am);
|
737
|
addChorological(state, "[C-As.]", "[Central Asian]", "", FloraHellenicaTransformer.uuidChorologicalC_As);
|
738
|
addChorological(state, "[SW-As.]", "[South West Asian]", "", FloraHellenicaTransformer.uuidChorologicalSW_As);
|
739
|
addChorological(state, "[unknown]", "[unknown]", "", FloraHellenicaTransformer.uuidChorologicalUnknown);
|
740
|
addChorological(state, "[N-Afr.]", "[North African]", "", FloraHellenicaTransformer.uuidChorologicalN_Afr);
|
741
|
addChorological(state, "[Am.]", "[American]", "", FloraHellenicaTransformer.uuidChorologicalAm);
|
742
|
addChorological(state, "[paleosubtrop.]", "[paleosubtropical]", "", FloraHellenicaTransformer.uuidChorologicalPaleosubtrop);
|
743
|
addChorological(state, "[SW-Eur.]", "[South West European]", "", FloraHellenicaTransformer.uuidChorologicalSW_Eur);
|
744
|
|
745
|
addChorological(state, "[S-As.]", "[South Asian]", "", FloraHellenicaTransformer.uuidChorologicalS_As);
|
746
|
addChorological(state, "[NE-Afr.]", "[North East African]", "", FloraHellenicaTransformer.uuidChorologicalNE_Afr);
|
747
|
addChorological(state, "[NW-Afr.]", "[North West African]", "", FloraHellenicaTransformer.uuidChorologicalNW_Afr);
|
748
|
addChorological(state, "[trop. Afr.]", "[tropical African]", "", FloraHellenicaTransformer.uuidChorologicalTrop_Afr);
|
749
|
addChorological(state, "[Afr.]", "[Arican]", "", FloraHellenicaTransformer.uuidChorologicalAfr);
|
750
|
addChorological(state, "[As.]", "[Asian]", "", FloraHellenicaTransformer.uuidChorologicalAs);
|
751
|
addChorological(state, "[W-As.]", "[West Asian]", "", FloraHellenicaTransformer.uuidChorologicalW_As);
|
752
|
addChorological(state, "[C-Eur.]", "[Central European]", "", FloraHellenicaTransformer.uuidChorologicalC_Eur);
|
753
|
addChorological(state, "[E-Afr.]", "[East African]", "", FloraHellenicaTransformer.uuidChorologicalE_Afr);
|
754
|
addChorological(state, "[W-Austr.]", "[West Australian]", "", FloraHellenicaTransformer.uuidChorologicalW_Austr);
|
755
|
addChorological(state, "[trop. As.]", "[tropical Asian]", "", FloraHellenicaTransformer.uuidChorologicaltrop_As);
|
756
|
|
757
|
addChorological(state, "[Co]", "[Cosmopolitan]", "Taxa distributed in all continents, i.e. beyond the N hemisphere. This category may be given in brackets after the known or supposed native distribution in cases of taxa that have been spread worldwide by humans", FloraHellenicaTransformer.uuidChorological__Co_);
|
758
|
|
759
|
this.getVocabularyService().save(chorologicalVoc);
|
760
|
return;
|
761
|
|
762
|
}
|
763
|
|
764
|
|
765
|
/**
|
766
|
* @param state
|
767
|
* @param string
|
768
|
* @param string2
|
769
|
* @param string3
|
770
|
* @param uuidchorologicalstar
|
771
|
*/
|
772
|
private void addChorological(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label,
|
773
|
String desc, UUID uuidChorological) {
|
774
|
desc = isBlank(desc)? label : desc;
|
775
|
State chorologyTerm = addState(state, abbrevLabel, label, desc, uuidChorological, chorologicalVoc);
|
776
|
chorologyMap.put(abbrevLabel, chorologyTerm);
|
777
|
}
|
778
|
|
779
|
/**
|
780
|
* @param state
|
781
|
* @param string
|
782
|
* @param uuidlifeformt
|
783
|
*/
|
784
|
private void addLifeform(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label, UUID uuidlifeform) {
|
785
|
State lifeForm = addState(state, abbrevLabel, label, label, uuidlifeform, lifeformVoc);
|
786
|
lifeformMap.put(abbrevLabel, lifeForm);
|
787
|
}
|
788
|
|
789
|
private State addState(SimpleExcelTaxonImportState<CONFIG> state,
|
790
|
String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
|
791
|
State newState = State.NewInstance(
|
792
|
description, stateLabel, abbrev);
|
793
|
newState.setUuid(uuid);
|
794
|
newState.setIdInVocabulary(abbrev);
|
795
|
voc.addTerm(newState);
|
796
|
return newState;
|
797
|
}
|
798
|
|
799
|
private PresenceAbsenceTerm addStatus(SimpleExcelTaxonImportState<CONFIG> state,
|
800
|
String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<PresenceAbsenceTerm> voc) {
|
801
|
PresenceAbsenceTerm newStatus = PresenceAbsenceTerm.NewPresenceInstance(
|
802
|
description, stateLabel, abbrev);
|
803
|
newStatus.setUuid(uuid);
|
804
|
newStatus.setIdInVocabulary(abbrev);
|
805
|
newStatus.setSymbol(abbrev);
|
806
|
voc.addTerm(newStatus);
|
807
|
return newStatus;
|
808
|
}
|
809
|
|
810
|
private void initHabitatVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
|
811
|
if (habitatVoc == null){
|
812
|
UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc;
|
813
|
habitatVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
|
814
|
if (habitatVoc == null){
|
815
|
createHabitatVoc(state, uuid);
|
816
|
}
|
817
|
}
|
818
|
}
|
819
|
|
820
|
private void initStatusVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
|
821
|
if (statusVoc == null){
|
822
|
UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaStatusVoc;
|
823
|
statusVoc = (OrderedTermVocabulary<PresenceAbsenceTerm>)this.getVocabularyService().find(uuid);
|
824
|
if (statusVoc == null){
|
825
|
createStatusVoc(state, uuid);
|
826
|
}
|
827
|
}
|
828
|
}
|
829
|
|
830
|
/**
|
831
|
* @param state
|
832
|
*/
|
833
|
private void createStatusVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
|
834
|
//voc
|
835
|
URI termSourceUri = null;
|
836
|
String label = "Checklist of Greece Status";
|
837
|
String description = "Status as used in the Checklist of Greece";
|
838
|
statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm,
|
839
|
description, label, null, termSourceUri);
|
840
|
statusVoc.setUuid(vocUuid);
|
841
|
|
842
|
rangeRestricted = addStatus(state, "RR", "Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestricted, statusVoc);
|
843
|
doubtfullyRangeRestricted = addStatus(state, "?RR", "?Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestrictedDoubtfully, statusVoc);
|
844
|
|
845
|
this.getVocabularyService().save(statusVoc);
|
846
|
return;
|
847
|
}
|
848
|
|
849
|
|
850
|
/**
|
851
|
* @param state
|
852
|
*/
|
853
|
private void createHabitatVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
|
854
|
//voc
|
855
|
URI termSourceUri = null;
|
856
|
String label = "Checklist of Greece Habitats";
|
857
|
String description = "Habitats as used in the Checklist of Greece";
|
858
|
habitatVoc = OrderedTermVocabulary.NewInstance(TermType.State,
|
859
|
description, label, null, termSourceUri);
|
860
|
habitatVoc.setUuid(vocUuid);
|
861
|
|
862
|
addHabitat(state, "A", "Freshwater habitats", "Freshwater habitats (Aquatic habitats, springs and fens, reedbeds and damp tall herb vegetation, seasonally flooded depressions, damp and seepage meadows, streambanks, river and lake shores)", FloraHellenicaTransformer.uuidHabitatA);
|
863
|
addHabitat(state, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
|
864
|
addHabitat(state, "G", "Temperate and submediterranean Grasslands", "Temperate and submediterranean Grasslands (lowland to montane dry and mesic meadows and pastures, rock outcrops and stony ground, grassy non-ruderal verges and forest edges)", FloraHellenicaTransformer.uuidHabitatG);
|
865
|
addHabitat(state, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
|
866
|
addHabitat(state, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
|
867
|
addHabitat(state, "P", "Xeric Mediterranean Phrygana and grasslands", "Xeric Mediterranean Phrygana and grasslands (Mediterranean dwarf shrub formations, annual-rich pastures and lowland screes)", FloraHellenicaTransformer.uuidHabitatP);
|
868
|
addHabitat(state, "R", "Agricultural and Ruderal habitats", "Agricultural and Ruderal habitats (fields, gardens and plantations, roadsides and trampled sites, frequently disturbed and pioneer habitats)", FloraHellenicaTransformer.uuidHabitatR);
|
869
|
addHabitat(state, "W", "Woodlands and scrub", "Woodlands and scrub (broadleaved and coniferous forest, riparian and mountain forest and scrub, hedges, shady woodland margins)", FloraHellenicaTransformer.uuidHabitatW);
|
870
|
|
871
|
this.getVocabularyService().save(habitatVoc);
|
872
|
return;
|
873
|
}
|
874
|
|
875
|
/**
|
876
|
* @param state
|
877
|
* @param string
|
878
|
* @param uuidlifeformt
|
879
|
*/
|
880
|
private void addHabitat(SimpleExcelTaxonImportState<CONFIG> state, String abbrev, String label, String desc, UUID uuidHabitat) {
|
881
|
addState(state, abbrev, label, desc, uuidHabitat, habitatVoc);
|
882
|
}
|
883
|
|
884
|
/**
|
885
|
* @param state
|
886
|
* @return
|
887
|
*/
|
888
|
@SuppressWarnings("unchecked")
|
889
|
private void createAreasVoc(SimpleExcelTaxonImportState<CONFIG> state) {
|
890
|
//voc
|
891
|
URI termSourceUri = null;
|
892
|
String label = "Checklist of Greece Areas";
|
893
|
String description = "Areas as used in the Checklist of Greece";
|
894
|
areasVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea,
|
895
|
description, label, null, termSourceUri);
|
896
|
areasVoc.setUuid(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
|
897
|
// Representation rep = Representation.NewInstance("Estados Méxicanos", "Estados Méxicanos", null, Language.SPANISH_CASTILIAN());
|
898
|
// areasVoc.addRepresentation(rep);
|
899
|
|
900
|
//greece country
|
901
|
String countryLabel = "Greece";
|
902
|
greece = NamedArea.NewInstance(countryLabel, countryLabel, "GR");
|
903
|
greece.setUuid(FloraHellenicaTransformer.uuidAreaGreece);
|
904
|
greece.setIdInVocabulary("GR");
|
905
|
greece.setSymbol("GR");
|
906
|
areasVoc.addTerm(greece);
|
907
|
//FIXME
|
908
|
// addMapping(greece, xx "mex_adm0", "iso", "MEX");
|
909
|
|
910
|
addArea(state, "IoI", "Ionian Islands", FloraHellenicaTransformer.uuidAreaIoI);
|
911
|
addArea(state, "NPi", "North Pindos", FloraHellenicaTransformer.uuidAreaNPi);
|
912
|
addArea(state, "SPi", "South Pindos", FloraHellenicaTransformer.uuidAreaSPi);
|
913
|
addArea(state, "Pe", "Peloponnisos", FloraHellenicaTransformer.uuidAreaPe);
|
914
|
addArea(state, "StE", "Sterea Ellas", FloraHellenicaTransformer.uuidAreaStE);
|
915
|
addArea(state, "EC", "East Central Greece", FloraHellenicaTransformer.uuidAreaEC);
|
916
|
addArea(state, "NC", "North Central Greece", FloraHellenicaTransformer.uuidAreaNC);
|
917
|
addArea(state, "NE", "North-East Greece", FloraHellenicaTransformer.uuidAreaNE);
|
918
|
addArea(state, "NAe", "North Aegean islands", FloraHellenicaTransformer.uuidAreaNAe);
|
919
|
addArea(state, "WAe", "West Aegean islands", FloraHellenicaTransformer.uuidAreaWAe);
|
920
|
addArea(state, "Kik", "Kiklades", FloraHellenicaTransformer.uuidAreaKik);
|
921
|
addArea(state, "KK", "Kriti and Karpathos", FloraHellenicaTransformer.uuidAreaKK);
|
922
|
addArea(state, "EAe", "East Aegean islands", FloraHellenicaTransformer.uuidAreaEAe);
|
923
|
|
924
|
this.getVocabularyService().save(areasVoc);
|
925
|
return;
|
926
|
}
|
927
|
|
928
|
private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid) {
|
929
|
addArea(state, abbrevLabel, areaLabel, uuid, areaLabel); //short cut if label and mapping label are equal
|
930
|
}
|
931
|
|
932
|
private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
|
933
|
UUID uuid, String mappingLabel) {
|
934
|
addArea(state, abbrevLabel, areaLabel, uuid, mappingLabel, null); //short cut if label and mapping label are equal
|
935
|
}
|
936
|
|
937
|
|
938
|
/**
|
939
|
* @param state
|
940
|
* @param string
|
941
|
* @param uuidaguascalientes
|
942
|
*/
|
943
|
private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel, UUID uuid, String mappingLabel, Integer id1) {
|
944
|
NamedArea newArea = NamedArea.NewInstance(
|
945
|
areaLabel, areaLabel, abbrevLabel);
|
946
|
newArea.setIdInVocabulary(abbrevLabel);
|
947
|
newArea.setUuid(uuid);
|
948
|
newArea.setPartOf(greece);
|
949
|
newArea.setLevel(null);
|
950
|
newArea.setType(NamedAreaType.NATURAL_AREA());
|
951
|
areasVoc.addTerm(newArea);
|
952
|
//FIXME
|
953
|
if (id1 != null){
|
954
|
addMapping(newArea, "mex_adm1", "id_1", String.valueOf(id1));
|
955
|
}else if (mappingLabel != null){
|
956
|
addMapping(newArea, "mex_adm1", "name_1", mappingLabel);
|
957
|
}
|
958
|
}
|
959
|
|
960
|
private void addMapping(NamedArea area, String mapping_layer, String mapping_field, String abbrev) {
|
961
|
GeoServiceAreaAnnotatedMapping mapping = (GeoServiceAreaAnnotatedMapping)this.getBean("geoServiceAreaAnnotatedMapping");
|
962
|
GeoServiceArea geoServiceArea = new GeoServiceArea();
|
963
|
geoServiceArea.add(mapping_layer, mapping_field, abbrev);
|
964
|
mapping.set(area, geoServiceArea);
|
965
|
}
|
966
|
|
967
|
}
|