Project

General

Profile

Download (47.3 KB) Statistics
| Branch: | Revision:
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
import org.springframework.transaction.TransactionStatus;
22

    
23
import eu.etaxonomy.cdm.api.service.ITermService;
24
import eu.etaxonomy.cdm.common.CdmUtils;
25
import eu.etaxonomy.cdm.ext.geo.GeoServiceArea;
26
import eu.etaxonomy.cdm.ext.geo.GeoServiceAreaAnnotatedMapping;
27
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
28
import eu.etaxonomy.cdm.model.common.Language;
29
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
30
import eu.etaxonomy.cdm.model.common.TermType;
31
import eu.etaxonomy.cdm.model.description.CategoricalData;
32
import eu.etaxonomy.cdm.model.description.Distribution;
33
import eu.etaxonomy.cdm.model.description.Feature;
34
import eu.etaxonomy.cdm.model.description.FeatureNode;
35
import eu.etaxonomy.cdm.model.description.FeatureTree;
36
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
37
import eu.etaxonomy.cdm.model.description.State;
38
import eu.etaxonomy.cdm.model.description.TaxonDescription;
39
import eu.etaxonomy.cdm.model.location.NamedArea;
40
import eu.etaxonomy.cdm.model.location.NamedAreaType;
41
import eu.etaxonomy.cdm.model.name.BotanicalName;
42
import eu.etaxonomy.cdm.model.name.Rank;
43
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
44
import eu.etaxonomy.cdm.model.reference.Reference;
45
import eu.etaxonomy.cdm.model.taxon.Classification;
46
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
47
import eu.etaxonomy.cdm.model.taxon.Taxon;
48
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
49
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
50

    
51
/**
52
 * @author a.mueller
53
 * @date 14.12.2016
54
 *
55
 */
56

    
57
@Component
58
public class FloraHellenicaTaxonImport<CONFIG extends FloraHellenicaImportConfigurator>
59
            extends FloraHellenicaImportBase<CONFIG>{
60

    
61
    private static final long serialVersionUID = -6291948918967763381L;
62
    private static final Logger logger = Logger.getLogger(FloraHellenicaTaxonImport.class);
63

    
64
    private static final String LIFE_FORM = "Life-form";
65
    private static final String STATUS = "Status";
66
    private static final String CHOROLOGICAL_CATEGOGY = "Chorological categogy";
67

    
68

    
69
    private static UUID rootUuid = UUID.fromString("aa667b0b-b417-470e-a9b0-ef9409a3431e");
70
    private static UUID plantaeUuid = UUID.fromString("4f151932-ab97-4d81-b88e-46fe82cd3e88");
71

    
72
    private OrderedTermVocabulary<NamedArea> areasVoc;
73
    private NamedArea greece;
74
    private OrderedTermVocabulary<State> lifeformVoc;
75
    private OrderedTermVocabulary<State> habitatVoc;
76
    private Map<String, State> lifeformMap = new HashMap<>();
77

    
78
    private OrderedTermVocabulary<PresenceAbsenceTerm> statusVoc;
79
    private PresenceAbsenceTerm rangeRestricted;
80
    private PresenceAbsenceTerm doubtfullyRangeRestricted;
81

    
82

    
83
    private OrderedTermVocabulary<State> chorologicalVoc;
84
    private Map<String, State> chorologyMap = new HashMap<>();
85

    
86

    
87
   private  static List<String> expectedKeys= Arrays.asList(new String[]{
88
            "Unique ID","uuid","Group","Family","Genus","Species","Species Author","Subspecies","Subspecies Author",
89
            "IoI","NPi","SPi","Pe","StE","EC","NC","NE","NAe","WAe","Kik","KK","EAe",
90
            STATUS,CHOROLOGICAL_CATEGOGY,LIFE_FORM,"A","C","G","H","M","P","R","W", "Taxon"
91
    });
92

    
93
    private String lastGenus;
94
    private String lastSpecies;
95
    private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
96

    
97
    @Override
98
    protected String getWorksheetName() {
99
        return "valid taxa names";
100
    }
101

    
102

    
103
    private boolean isFirst = true;
104
    private TransactionStatus tx = null;
105
    /**
106
     * {@inheritDoc}
107
     */
108
    @Override
109
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
110
        if (isFirst){
111
            tx = this.startTransaction();
112
            isFirst = false;
113
        }
114
        initAreaVocabulary(state);
115
        initLifeformVocabulary(state);
116
        initHabitatVocabulary(state);
117
        initChorologicalVocabulary(state);
118
        initStatusVocabulary(state);
119
        makeFeatureTree(state);
120

    
121
        String line = state.getCurrentLine() + ": ";
122
        HashMap<String, String> record = state.getOriginalRecord();
123

    
124
        Set<String> keys = record.keySet();
125
        for (String key: keys) {
126
            if (! expectedKeys.contains(key)){
127
                logger.warn(line + "Unexpected Key: " + key);
128
            }
129
        }
130

    
131
        String noStr = getValue(record, "Unique ID");
132
        Taxon taxon = makeTaxon(state, line, record, noStr);
133

    
134
        //Distribution
135
        TaxonDescription desc = getTaxonDescription(taxon);
136
        makeDistribution(state, line, noStr, desc);
137

    
138
        makeChorologicalCategory(state, line, noStr, desc);
139

    
140
        //lifeform
141
        makeLifeform(state, line, noStr, desc);
142

    
143
        //habitat
144
        makeHabitat(state, line, noStr, desc);
145

    
146
        state.putTaxon(noStr, taxon);
147
    }
148

    
149

    
150
    @Override
151
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
152
        if (tx != null){
153
            this.commitTransaction(tx);
154
            tx = null;
155
        }
156
    }
157

    
158

    
159
    boolean hasFeatureTree = false;
160
    /**
161
     * @param state
162
     */
163
    private void makeFeatureTree(SimpleExcelTaxonImportState<CONFIG> state) {
164
        if (hasFeatureTree  ){
165
            return;
166
        }
167
        if (getFeatureTreeService().find(state.getConfig().getUuidFeatureTree()) != null){
168
            hasFeatureTree = true;
169
            return;
170
        }
171
        FeatureTree result = FeatureTree.NewInstance(state.getConfig().getUuidFeatureTree());
172
        result.setTitleCache(state.getConfig().getFeatureTreeTitle(), true);
173
        FeatureNode root = result.getRoot();
174
        FeatureNode newNode;
175

    
176
        ITermService service = getTermService();
177
        Feature newFeature = (Feature)service.find(Feature.DISTRIBUTION().getUuid());
178
        newNode = FeatureNode.NewInstance(newFeature);
179
        root.addChild(newNode);
180

    
181
        newFeature = (Feature)service.find(FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature);
182
        newNode = FeatureNode.NewInstance(newFeature);
183
        root.addChild(newNode);
184

    
185
        newFeature = (Feature)service.find(Feature.LIFEFORM().getUuid());
186
        newNode = FeatureNode.NewInstance(newFeature);
187
        root.addChild(newNode);
188

    
189
        newFeature = (Feature)service.find(Feature.HABITAT().getUuid());
190
        newNode = FeatureNode.NewInstance(newFeature);
191
        root.addChild(newNode);
192

    
193

    
194
        newFeature = (Feature)service.find(Feature.NOTES().getUuid());
195
        newNode = FeatureNode.NewInstance(newFeature);
196
        root.addChild(newNode);
197

    
198
        getFeatureTreeService().saveOrUpdate(result);
199
        hasFeatureTree = true;
200

    
201
    }
202

    
203
    /**
204
     * @param state
205
     * @param line
206
     * @param noStr
207
     * @param desc
208
     */
209
    private void makeChorologicalCategory(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
210
            TaxonDescription desc) {
211

    
212
        HashMap<String, String> record = state.getOriginalRecord();
213
        String valueStr = getValue(record, CHOROLOGICAL_CATEGOGY);
214

    
215
        String value = valueStr;
216
        if (value == null){
217
            return;
218
        }
219
        Feature choroFeature = getFeature(state, FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature,
220
                "Chorology", "The Chorological Category", "Choro", null);
221
        CategoricalData catData = CategoricalData.NewInstance(choroFeature);
222
        catData.setOrderRelevant(true);
223

    
224
        String[] splits = value.split(" & ");
225
        replaceDirection(splits, line);
226
        for (String split: splits){
227
            String[] splitsA = split.split("/");
228
            for (String splitA : splitsA){
229
                String[] splitsB = splitA.split(", ");
230
                for (String splitB : splitsB){
231
                    splitB = normalizeChorology(splitB);
232
                    State choroTerm = chorologyMap.get(splitB);
233
                    if (choroTerm == null){
234
                        logger.warn(line + "Some chorology could not be recognized in: " + value + "; Term was: " +splitB);
235
                    }else{
236
                        catData.addStateData(choroTerm);
237
                    }
238
                }
239
            }
240
        }
241
        if (catData.getStateData().size() > 1){
242
            catData.setOrderRelevant(true);
243
        }
244
        desc.addElement(catData);
245
    }
246

    
247
    /**
248
     * @param splitB
249
     * @return
250
     */
251
    private String normalizeChorology(String choroStr) {
252
        choroStr = choroStr.trim()
253
                .replace("BK", "Bk")
254
                .replace("Austral.", "Austr.")
255
                .replace("trop.As.", "trop. As.");
256
        if (choroStr.startsWith("[") && !choroStr.endsWith("]")){
257
            choroStr += "]";
258
        }else if (!choroStr.startsWith("[") && choroStr.endsWith("]")){
259
            choroStr = "[" + choroStr;
260
        }
261
        return choroStr;
262
    }
263

    
264
    /**
265
     * @param splits
266
     * @param line
267
     */
268
    private void replaceDirection(String[] splits, String line) {
269
        if (splits.length > 1){
270
            String[] divs = splits[1].split("-");
271
            if (divs.length == 2){
272
                splits[0] = splits[0] + "-" + divs[1];
273
            }else{
274
                logger.warn(line + "Splits[1] has not expected format: " + splits[1]);
275
            }
276
        }
277
    }
278

    
279
    /**
280
     * @param state
281
     * @param line
282
     * @param noStr
283
     * @param desc
284
     */
285
    private void makeLifeform(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
286
            TaxonDescription desc) {
287
        HashMap<String, String> record = state.getOriginalRecord();
288
        String value = getValue(record, LIFE_FORM);
289
        String[] splits = value.split("\\s+");
290
        if (splits.length > 2){
291
            logger.warn("Unexpected length of lifeform: " + value + " line: "  + line );
292
        }
293
        CategoricalData catData = CategoricalData.NewInstance(Feature.LIFEFORM());
294
        for (String split : splits){
295
            State lifeform = lifeformMap.get(split);
296
            if (lifeform == null){
297
                logger.warn(line + "Unexpected lifeform: " + value);
298
            }else{
299
                catData.addStateData(lifeform);
300
            }
301
        }
302
        desc.addElement(catData);
303

    
304
    }
305

    
306
    /**
307
     * @param state
308
     * @param line
309
     * @param noStr
310
     * @param desc
311
     */
312
    private void makeHabitat(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
313
            TaxonDescription desc) {
314
        CategoricalData catData = CategoricalData.NewInstance(Feature.HABITAT());
315
        handleHabitat(state, catData, "A", FloraHellenicaTransformer.uuidHabitatA, line, noStr);
316
        handleHabitat(state, catData, "C", FloraHellenicaTransformer.uuidHabitatC, line, noStr);
317
        handleHabitat(state, catData, "G", FloraHellenicaTransformer.uuidHabitatG, line, noStr);
318
        handleHabitat(state, catData, "H", FloraHellenicaTransformer.uuidHabitatH, line, noStr);
319
        handleHabitat(state, catData, "M", FloraHellenicaTransformer.uuidHabitatM, line, noStr);
320
        handleHabitat(state, catData, "P", FloraHellenicaTransformer.uuidHabitatP, line, noStr);
321
        handleHabitat(state, catData, "R", FloraHellenicaTransformer.uuidHabitatR, line, noStr);
322
        handleHabitat(state, catData, "W", FloraHellenicaTransformer.uuidHabitatW, line, noStr);
323
        desc.addElement(catData);
324
    }
325

    
326
    /**
327
     * @param state
328
     * @param catData
329
     * @param string
330
     * @param uuidhabitata
331
     * @param line
332
     * @param noStr
333
     */
334
    private void handleHabitat(SimpleExcelTaxonImportState<CONFIG> state, CategoricalData catData, String label,
335
            UUID uuidHabitat, String line, String noStr) {
336
        HashMap<String, String> record = state.getOriginalRecord();
337
        String value = getValue(record, "" + label);
338
        if (value == null){
339
            //do nothing
340
        }else if (value.matches("[ACGHMPRW]")){
341
            State habitatState = this.getStateTerm(state, uuidHabitat, null, null, null, habitatVoc);
342
            catData.addStateData(habitatState);
343
        }else{
344
            logger.warn(line + "Unrecognized habitat state '" + value + "' for " + label);
345
        }
346
    }
347

    
348
    /**
349
     * @param state
350
     * @param line
351
     * @param noStr
352
     * @param desc
353
     */
354
    private void makeDistribution(SimpleExcelTaxonImportState<CONFIG> state, String line, String noStr,
355
            TaxonDescription desc) {
356
        //TODO status Greece
357
        handleStatus(state, desc, STATUS, FloraHellenicaTransformer.uuidAreaGreece, line, noStr);
358

    
359
        handleDistribution(state, desc, "IoI", FloraHellenicaTransformer.uuidAreaIoI, line, noStr);
360
        handleDistribution(state, desc, "NPi", FloraHellenicaTransformer.uuidAreaNPi, line, noStr);
361
        handleDistribution(state, desc, "SPi", FloraHellenicaTransformer.uuidAreaSPi, line, noStr);
362
        handleDistribution(state, desc, "Pe", FloraHellenicaTransformer.uuidAreaPe, line, noStr);
363
        handleDistribution(state, desc, "StE", FloraHellenicaTransformer.uuidAreaStE, line, noStr);
364
        handleDistribution(state, desc, "EC", FloraHellenicaTransformer.uuidAreaEC, line, noStr);
365
        handleDistribution(state, desc, "NC", FloraHellenicaTransformer.uuidAreaNC, line, noStr);
366
        handleDistribution(state, desc, "NE", FloraHellenicaTransformer.uuidAreaNE, line, noStr);
367
        handleDistribution(state, desc, "NAe", FloraHellenicaTransformer.uuidAreaNAe, line, noStr);
368
        handleDistribution(state, desc, "WAe", FloraHellenicaTransformer.uuidAreaWAe, line, noStr);
369
        handleDistribution(state, desc, "Kik", FloraHellenicaTransformer.uuidAreaKik, line, noStr);
370
        handleDistribution(state, desc, "KK", FloraHellenicaTransformer.uuidAreaKK, line, noStr);
371
        handleDistribution(state, desc, "EAe", FloraHellenicaTransformer.uuidAreaEAe, line, noStr);
372
    }
373

    
374
    /**
375
     * @param state
376
     * @param line
377
     * @param record
378
     * @param noStr
379
     * @return
380
     */
381
    private Taxon makeTaxon(SimpleExcelTaxonImportState<CONFIG> state, String line, HashMap<String, String> record,
382
            String noStr) {
383

    
384
        TaxonNode familyTaxon = getFamilyTaxon(record, state);
385
        if (familyTaxon == null){
386
            logger.warn(line + "Family not created: " + record.get("Family"));
387
        }
388

    
389
        String genusStr = getValue(record, "Genus");
390
        String speciesStr = getValue(record, "Species");
391
        String speciesAuthorStr = getValue(record, "Species Author");
392
        String subSpeciesStr = getValue(record, "Subspecies");
393
        String subSpeciesAuthorStr = getValue(record, "Subspecies Author");
394
        String uuidStr = getValue(record, "uuid");
395
        UUID uuid = UUID.fromString(uuidStr);
396
        boolean isSubSpecies = isNotBlank(subSpeciesStr);
397
        boolean isAutonym = isSubSpecies && speciesStr.equals(subSpeciesStr);
398
        if (isSubSpecies && ! isAutonym && isBlank(subSpeciesAuthorStr)){
399
            logger.warn(line + "Non-Autonym subspecies has no auhtor");
400
        }else if (isSubSpecies && isAutonym && isNotBlank(subSpeciesAuthorStr)){
401
            logger.warn(line + "Autonym subspecies has subspecies auhtor");
402
        }
403

    
404
        String[] nameParts;
405
        if (!isSubSpecies){
406
            nameParts = new String[]{genusStr, speciesStr, speciesAuthorStr};
407
        }else if (!isAutonym){
408
            nameParts = new String[]{genusStr, speciesStr, "subsp. " + subSpeciesStr, subSpeciesAuthorStr};
409
        }else{
410
            nameParts = new String[]{genusStr, speciesStr, speciesAuthorStr, "subsp. " + subSpeciesStr};
411
        }
412

    
413
        String nameStr = CdmUtils.concat(" ", nameParts);
414
        Rank rank = isSubSpecies ? Rank.SUBSPECIES() : Rank.SPECIES();
415
        BotanicalName name = (BotanicalName)parser.parseFullName(nameStr, state.getConfig().getNomenclaturalCode(), rank);
416
        if (name.isProtectedTitleCache()){
417
            logger.warn(line + "Name could not be parsed: " + nameStr);
418
        }
419
        Taxon taxon = Taxon.NewInstance(name, getSecReference(state));
420
        taxon.addImportSource(noStr, getWorksheetName(), getSourceCitation(state), null);
421
//        String parentStr = isSubSpecies ? makeSpeciesKey(genusStr, speciesStr, speciesAuthorStr) : genusStr;
422
        taxon.setUuid(uuid);
423
        String parentStr = genusStr;
424
        boolean genusAsBefore = genusStr.equals(lastGenus);
425
        boolean speciesAsBefore = speciesStr.equals(lastSpecies);
426
        TaxonNode parent = getParent(state, parentStr);
427
        if (parent != null){
428
//            if (!isSubSpecies && genusAsBefore || isSubSpecies && speciesAsBefore){
429
            if (genusAsBefore ){
430
                        //everything as expected
431
                TaxonNode newNode = parent.addChildTaxon(taxon, getSecReference(state), null);
432
                getTaxonNodeService().save(newNode);
433
            }else{
434
                logger.warn(line + "Unexpected non-missing parent");
435
            }
436
        }else{
437
//            if (isSubSpecies){
438
//                logger.warn(line + "Subspecies should always have an existing parent");
439
//            }else
440
            if (genusAsBefore){
441
                logger.warn(line + "Unexpected missing genus parent");
442
            }else{
443
                parent = makeGenusNode(state, record, genusStr);
444
                TaxonNode newNode = parent.addChildTaxon(taxon, getSecReference(state), null);
445
                getTaxonNodeService().save(newNode);
446
            }
447
        }
448
        if (!isSubSpecies){
449
            state.putHigherTaxon(makeSpeciesKey(genusStr, speciesStr, speciesAuthorStr), taxon);
450
        }
451

    
452
//        this.lastFamily = familyStr
453
        this.lastGenus = genusStr;
454
        this.lastSpecies = speciesStr;
455
        return taxon;
456
    }
457

    
458
    /**
459
     * @param genusStr
460
     * @param speciesStr
461
     * @param speciesAuthorStr
462
     * @return
463
     */
464
    private String makeSpeciesKey(String genusStr, String speciesStr, String speciesAuthorStr) {
465
        return CdmUtils.concat(" ", new String[]{genusStr, speciesStr, speciesAuthorStr});
466
    }
467

    
468
    /**
469
     * @param state
470
     * @param record
471
     * @param genusStr
472
     * @return
473
     */
474
    private TaxonNode makeGenusNode(SimpleExcelTaxonImportState<CONFIG> state,
475
            HashMap<String, String> record, String genusStr) {
476
        BotanicalName name = TaxonNameFactory.NewBotanicalInstance(Rank.GENUS());
477
        name.setGenusOrUninomial(genusStr);
478
        Taxon genus = Taxon.NewInstance(name, getSecReference(state));
479
        TaxonNode family = getFamilyTaxon(record, state);
480
        TaxonNode genusNode = family.addChildTaxon(genus, getSecReference(state), null);
481
        state.putHigherTaxon(genusStr, genus);
482
        genus.addSource(makeOriginalSource(state));
483
        getTaxonNodeService().save(genusNode);
484
        return genusNode;
485
    }
486

    
487
    /**
488
     * @param state
489
     * @param parentStr
490
     * @return
491
     */
492
    private TaxonNode getParent(SimpleExcelTaxonImportState<CONFIG> state, String parentStr) {
493
        Taxon taxon = state.getHigherTaxon(parentStr);
494

    
495
        return taxon == null ? null : taxon.getTaxonNodes().iterator().next();
496
    }
497

    
498
    /**
499
     * @param record
500
     * @param state
501
     * @return
502
     */
503
    private TaxonNode getFamilyTaxon(HashMap<String, String> record, SimpleExcelTaxonImportState<CONFIG> state) {
504
        String familyStr = getValue(record, "Family");
505
        if (familyStr == null){
506
            return null;
507
        }
508
        familyStr = familyStr.trim();
509

    
510
        Taxon family = state.getHigherTaxon(familyStr);
511
        TaxonNode familyNode;
512
        if (family != null){
513
            familyNode = family.getTaxonNodes().iterator().next();
514
        }else{
515
            BotanicalName name = makeFamilyName(state, familyStr);
516
            Reference sec = getSecReference(state);
517
            family = Taxon.NewInstance(name, sec);
518

    
519
            ITaxonTreeNode groupNode = getGroupTaxon(record, state);
520
            familyNode = groupNode.addChildTaxon(family, sec, null);
521
            state.putHigherTaxon(familyStr, family);
522
            getTaxonNodeService().save(familyNode);
523
        }
524

    
525
        return familyNode;
526
    }
527

    
528
    /**
529
     * @param record
530
     * @param state
531
     * @return
532
     */
533
    private TaxonNode getGroupTaxon(HashMap<String, String> record, SimpleExcelTaxonImportState<CONFIG> state) {
534
        String groupStr = getValue(record, "Group");
535
        if (groupStr == null){
536
            return null;
537
        }
538
        groupStr = groupStr.trim();
539

    
540
        Taxon group = state.getHigherTaxon(groupStr);
541
        TaxonNode groupNode;
542
        if (group != null){
543
            groupNode = group.getTaxonNodes().iterator().next();
544
        }else{
545
            BotanicalName name = makeFamilyName(state, groupStr);
546
            Reference sec = getSecReference(state);
547
            group = Taxon.NewInstance(name, sec);
548
            ITaxonTreeNode rootNode = getClassification(state);
549
            groupNode = rootNode.addChildTaxon(group, sec, null);
550
            state.putHigherTaxon(groupStr, group);
551
            getTaxonNodeService().save(groupNode);
552
        }
553

    
554
        return groupNode;
555
    }
556

    
557
    private TaxonNode rootNode;
558
    private TaxonNode getClassification(SimpleExcelTaxonImportState<CONFIG> state) {
559
        if (rootNode == null){
560
            Reference sec = getSecReference(state);
561
            String classificationName = state.getConfig().getClassificationName();
562
            Language language = Language.DEFAULT();
563
            Classification classification = Classification.NewInstance(classificationName, sec, language);
564
            classification.setUuid(state.getConfig().getClassificationUuid());
565
            classification.getRootNode().setUuid(rootUuid);
566

    
567
            BotanicalName plantaeName = TaxonNameFactory.NewBotanicalInstance(Rank.KINGDOM());
568
            plantaeName.setGenusOrUninomial("Plantae");
569
            Taxon plantae = Taxon.NewInstance(plantaeName, sec);
570
            TaxonNode plantaeNode = classification.addChildTaxon(plantae, null, null);
571
            plantaeNode.setUuid(plantaeUuid);
572
            getClassificationService().save(classification);
573

    
574
            rootNode = plantaeNode;
575
        }
576
        return rootNode;
577
    }
578

    
579
    /**
580
     * @param desc
581
     * @param string
582
     * @param uuidUserDefinedAnnotationTypeVocabulary
583
     */
584
    private void handleDistribution(SimpleExcelTaxonImportState<CONFIG> state,
585
                TaxonDescription desc, String key, UUID uuid, String line, String id) {
586
        HashMap<String, String> record = state.getOriginalRecord();
587
        String value = getValue(record, key);
588
        if (value == null || value.matches("[x\\.\\?]")){
589
            NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
590
            Distribution dist;
591
            if (".".equals(value)){
592
                logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
593
                dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
594
            }else if (value == null){
595
                //TODO is absent wanted
596
                dist = Distribution.NewInstance(area, PresenceAbsenceTerm.ABSENT());
597
            }else if ("x".equals(value)){
598
                dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT());
599
            }else if ("?".equals(value)){
600
                dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT_DOUBTFULLY());
601
            }else {
602
                logger.warn(line + "Not matching status. THis should not happpen '" + value + "' for " + key);
603
                return;
604
            }
605
            desc.addElement(dist);
606
            dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
607
        }else {
608
            logger.warn(line + "Unrecognized distribution status '" + value + "' for " + key);
609
        }
610
    }
611

    
612
    private void handleStatus(SimpleExcelTaxonImportState<CONFIG> state,
613
            TaxonDescription desc, String key, UUID uuid, String line, String id) {
614
        HashMap<String, String> record = state.getOriginalRecord();
615
        String value = getValue(record, key);
616
        NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
617
        Distribution dist;
618
        if (value == null || ".".equals(value) ){
619
            dist = Distribution.NewInstance(area, PresenceAbsenceTerm.NATIVE());
620
            if (".".equals(value)){
621
                logger.warn(line + "'.' Should not exist anmore as a distribution status: '" + value + "' for " + key);
622
            }
623
        }else if ("Range-restricted".equals(value)){
624
            dist = Distribution.NewInstance(area, rangeRestricted);
625
        }else if ("?Range-restricted".equals(value)){
626
            dist = Distribution.NewInstance(area, doubtfullyRangeRestricted);
627
        }else if ("Xenophyte".equals(value)){
628
            dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED());
629
        }else if ("?Xenophyte".equals(value)){
630
            dist = Distribution.NewInstance(area, PresenceAbsenceTerm.INTRODUCED_DOUBTFULLY_INTRODUCED());
631
        }else {
632
            logger.warn(line + "Not matching status. This should not happpen '" + value + "' for " + key);
633
            return;
634
        }
635
        desc.addElement(dist);
636
        dist.addImportSource(id, getWorksheetName(), getSourceCitation(state), line);
637
    }
638

    
639
    @SuppressWarnings("unchecked")
640
    private void initAreaVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
641
        if (areasVoc == null){
642
            areasVoc = (OrderedTermVocabulary<NamedArea>)this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
643
            if (areasVoc == null){
644
                createAreasVoc(state);
645
            }
646
        }
647
    }
648

    
649

    
650
    /**
651
     * @param state
652
     */
653
    private void initChorologicalVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
654
        if (chorologicalVoc == null){
655
            UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologicalVoc;
656
            chorologicalVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
657
            if (chorologicalVoc == null){
658
                createChorologicalVoc(state, uuid);
659
            }
660
        }
661

    
662
    }
663

    
664

    
665
    @SuppressWarnings("unchecked")
666
    private void initLifeformVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
667
        if (lifeformVoc == null){
668
            UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc;
669
            lifeformVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
670
            if (lifeformVoc == null){
671
                createLifeformVoc(state, uuid);
672
            }
673
        }
674
    }
675

    
676
    /**
677
     * @param state
678
     * @param vocUuid
679
     */
680
    private void createLifeformVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
681
        //voc
682
        URI termSourceUri = null;
683
        String label = "Checklist of Greece Lifeforms";
684
        String description = "Lifeforms as used in the Checklist of Greece";
685
        lifeformVoc = OrderedTermVocabulary.NewInstance(TermType.State,
686
                description, label, null, termSourceUri);
687
        lifeformVoc.setUuid(vocUuid);
688

    
689
        addLifeform(state, "A", "Aquatic", FloraHellenicaTransformer.uuidLifeformA);
690
        addLifeform(state, "C", "Chamaephyte", FloraHellenicaTransformer.uuidLifeformC);
691
        addLifeform(state, "G", "Geophyte (Cryptophyte)", FloraHellenicaTransformer.uuidLifeformG);
692
        addLifeform(state, "H", "Hemicryptophyte", FloraHellenicaTransformer.uuidLifeformH);
693
        addLifeform(state, "P", "Phanerophyte", FloraHellenicaTransformer.uuidLifeformP);
694
        addLifeform(state, "T", "Therophyte", FloraHellenicaTransformer.uuidLifeformT);
695
        this.getVocabularyService().save(lifeformVoc);
696
        return;
697
    }
698

    
699

    
700
    /**
701
     * @param state
702
     * @param uuid
703
     */
704
    private void createChorologicalVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
705
        //voc
706
        URI termSourceUri = null;
707
        String label = "Checklist of Greece Chorological Categories";
708
        String description = "Chorological Categories as used in the Checklist of Greece";
709
        chorologicalVoc = OrderedTermVocabulary.NewInstance(TermType.State,
710
                description, label, null, termSourceUri);
711
        chorologicalVoc.setUuid(vocUuid);
712

    
713
        addChorological(state, "*", "Greek endemic", "Greek endemics (incl. single-island and single-mountain endemics)", FloraHellenicaTransformer.uuidChorologicalStar);
714
        addChorological(state, "Bk", "Balkan", "Taxa restricted to Balkan countries, occasionally extending to adjacent parts of SE Europe", FloraHellenicaTransformer.uuidChorologicalBk);
715
        addChorological(state, "BI", "Balkan-Italy", "Taxa restricted to Balkan countries and Italy (amphi-Adreatic)", FloraHellenicaTransformer.uuidChorologicalBI);
716
        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);
717
        addChorological(state, "BC", "Balkan-Central Europe", "Taxa distributed in the Balkans, Carpathians, Alps and adjacent areas (mainly in the mountains)", FloraHellenicaTransformer.uuidChorologicalBC);
718
        addChorological(state, "EM", "East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorologicalEM);
719
        addChorological(state, "Me", "Mediterranean", "Taxa with a circum-Mediterranean distribution including Portugal, occasionally extending to the Caucasus area and N Iran", FloraHellenicaTransformer.uuidChorologicalMe);
720
        addChorological(state, "MA", "Mediterranean-Atlantic", "Taxa restricted to maritime W Europe and the Mediterranean", FloraHellenicaTransformer.uuidChorologicalMA);
721
        addChorological(state, "ME", "Mediterranean-European", "Taxa restricted to the Mediterranean and temperate Europe, occasionally extending to NW Africa and the Caucasus area", FloraHellenicaTransformer.uuidChorologicalME);
722
        addChorological(state, "MS", "Mediterranean-SW Asian", "Taxa distributed in one or more Mediterranean countries and extending to SW and C Asia", FloraHellenicaTransformer.uuidChorologicalMS);
723
        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);
724
        addChorological(state, "ES", "Euro-Siberian", "Taxa with main distribution in temperate Eurasia (occasionally reaching the Caucasus area)", FloraHellenicaTransformer.uuidChorologicalES);
725
        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);
726
        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);
727
        addChorological(state, "Ct", "Circumtemperate", "Taxa of both extratropical Eurasia and North America", FloraHellenicaTransformer.uuidChorologicalCt);
728
        addChorological(state, "IT", "Irano-Turanian", "Taxa with main distribution in arid SW and C Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalIT);
729
        addChorological(state, "SS", "Saharo-Sindian", "Taxa with main distribution in arid N Africa and SQ Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalSS);
730
        addChorological(state, "ST", "Subtropical-tropical", "Taxa widespread in the warmer regions of both hemispheres", FloraHellenicaTransformer.uuidChorologicalST);
731
        addChorological(state, "Bo", "(Circum-)Boreal", "Taxa with main distribution in N and high-montane Eurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalBo);
732
        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);
733
        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);
734

    
735
        addChorological(state, "[trop.]", "[tropical]", "", FloraHellenicaTransformer.uuidChorologicaltrop);
736
        addChorological(state, "[subtrop.]", "[subtropical]", "", FloraHellenicaTransformer.uuidChorologicalsubtrop);
737
        addChorological(state, "[paleotrop.]", "[paleotropical]", "", FloraHellenicaTransformer.uuidChorologicalpaleotrop);
738
        addChorological(state, "[neotrop.]", "[neotropical]", "", FloraHellenicaTransformer.uuidChorologicalneotrop);
739
        addChorological(state, "[pantrop.]", "[pantropical]", "", FloraHellenicaTransformer.uuidChorologicalpantrop);
740
        addChorological(state, "[N-Am.]", "[North American]", "", FloraHellenicaTransformer.uuidChorologicalN_Am);
741
        addChorological(state, "[S-Am.]", "[South American]", "", FloraHellenicaTransformer.uuidChorologicalS_Am);
742
        addChorological(state, "[E-As.]", "[East Asian]", "", FloraHellenicaTransformer.uuidChorologicalE_As);
743
        addChorological(state, "[SE-As.", "[South East Asian]", "", FloraHellenicaTransformer.uuidChorologicalSE_As);
744
        addChorological(state, "[S-Afr.]", "[South African]", "", FloraHellenicaTransformer.uuidChorologicalS_Afr);
745
        addChorological(state, "[Arab.]", "[Arabian]", "", FloraHellenicaTransformer.uuidChorologicalArab);
746
        addChorological(state, "[Arab. NE-Afr.]", "[Arabian and North East African]", "", FloraHellenicaTransformer.uuidChorologicalArab_NE_Afr);
747
        addChorological(state, "[Caucas.]", "[Caucasian]", "", FloraHellenicaTransformer.uuidChorologicalCaucas);
748
        addChorological(state, "[Pontic]", "[Pontic]", "", FloraHellenicaTransformer.uuidChorologicalPontic);
749
        addChorological(state, "[Europ.]", "[European]", "", FloraHellenicaTransformer.uuidChorologicalEurop);
750
        addChorological(state, "[Austr.]", "[Australian]", "", FloraHellenicaTransformer.uuidChorologicalAustral);
751

    
752
        addChorological(state, "[W-Med.]", "[West Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalW_Med);
753
        addChorological(state, "[C-Med.]", "[Central Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalC_Med);
754
        addChorological(state, "[W-Eur.]", "[West European]", "", FloraHellenicaTransformer.uuidChorologicalW_Eur);
755
        addChorological(state, "[S-Eur.]", "[South European]", "", FloraHellenicaTransformer.uuidChorologicalS_Eur);
756
        addChorological(state, "[C-Am.]", "[Central American]", "", FloraHellenicaTransformer.uuidChorologicalC_Am);
757
        addChorological(state, "[C-As.]", "[Central Asian]", "", FloraHellenicaTransformer.uuidChorologicalC_As);
758
        addChorological(state, "[SW-As.]", "[South West Asian]", "", FloraHellenicaTransformer.uuidChorologicalSW_As);
759
        addChorological(state, "[unknown]", "[unknown]", "", FloraHellenicaTransformer.uuidChorologicalUnknown);
760
        addChorological(state, "[N-Afr.]", "[North African]", "", FloraHellenicaTransformer.uuidChorologicalN_Afr);
761
        addChorological(state, "[Am.]", "[American]", "", FloraHellenicaTransformer.uuidChorologicalAm);
762
        addChorological(state, "[paleosubtrop.]", "[paleosubtropical]", "", FloraHellenicaTransformer.uuidChorologicalPaleosubtrop);
763
        addChorological(state, "[SW-Eur.]", "[South West European]", "", FloraHellenicaTransformer.uuidChorologicalSW_Eur);
764

    
765
        addChorological(state, "[S-As.]", "[South Asian]", "", FloraHellenicaTransformer.uuidChorologicalS_As);
766
        addChorological(state, "[NE-Afr.]", "[North East African]", "", FloraHellenicaTransformer.uuidChorologicalNE_Afr);
767
        addChorological(state, "[NW-Afr.]", "[North West African]", "", FloraHellenicaTransformer.uuidChorologicalNW_Afr);
768
        addChorological(state, "[trop. Afr.]", "[tropical African]", "", FloraHellenicaTransformer.uuidChorologicalTrop_Afr);
769
        addChorological(state, "[Afr.]", "[Arican]", "", FloraHellenicaTransformer.uuidChorologicalAfr);
770
        addChorological(state, "[As.]", "[Asian]", "", FloraHellenicaTransformer.uuidChorologicalAs);
771
        addChorological(state, "[W-As.]", "[West Asian]", "", FloraHellenicaTransformer.uuidChorologicalW_As);
772
        addChorological(state, "[C-Eur.]", "[Central European]", "", FloraHellenicaTransformer.uuidChorologicalC_Eur);
773
        addChorological(state, "[E-Afr.]", "[East African]", "", FloraHellenicaTransformer.uuidChorologicalE_Afr);
774
        addChorological(state, "[W-Austr.]", "[West Australian]", "", FloraHellenicaTransformer.uuidChorologicalW_Austr);
775
        addChorological(state, "[trop. As.]", "[tropical Asian]", "", FloraHellenicaTransformer.uuidChorologicaltrop_As);
776

    
777
        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_);
778

    
779
        this.getVocabularyService().save(chorologicalVoc);
780
        return;
781

    
782
    }
783

    
784

    
785
    /**
786
     * @param state
787
     * @param string
788
     * @param string2
789
     * @param string3
790
     * @param uuidchorologicalstar
791
     */
792
    private void addChorological(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label,
793
            String desc, UUID uuidChorological) {
794
        desc = isBlank(desc)? label : desc;
795
        State chorologyTerm = addState(state, abbrevLabel, label, desc, uuidChorological, chorologicalVoc);
796
        chorologyMap.put(abbrevLabel, chorologyTerm);
797
    }
798

    
799
    /**
800
     * @param state
801
     * @param string
802
     * @param uuidlifeformt
803
     */
804
    private void addLifeform(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String label, UUID uuidlifeform) {
805
        State lifeForm = addState(state, abbrevLabel, label, label, uuidlifeform, lifeformVoc);
806
        lifeformMap.put(abbrevLabel, lifeForm);
807
    }
808

    
809
    private State addState(SimpleExcelTaxonImportState<CONFIG> state,
810
            String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
811
        State newState = State.NewInstance(
812
                description, stateLabel, abbrev);
813
        newState.setUuid(uuid);
814
        newState.setIdInVocabulary(abbrev);
815
        voc.addTerm(newState);
816
        return newState;
817
    }
818

    
819
    private PresenceAbsenceTerm addStatus(SimpleExcelTaxonImportState<CONFIG> state,
820
            String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<PresenceAbsenceTerm> voc) {
821
        PresenceAbsenceTerm newStatus = PresenceAbsenceTerm.NewPresenceInstance(
822
                description, stateLabel, abbrev);
823
        newStatus.setUuid(uuid);
824
        newStatus.setIdInVocabulary(abbrev);
825
        newStatus.setSymbol(abbrev);
826
        voc.addTerm(newStatus);
827
        return newStatus;
828
    }
829

    
830
    private void initHabitatVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
831
        if (habitatVoc == null){
832
            UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc;
833
            habitatVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
834
            if (habitatVoc == null){
835
                createHabitatVoc(state, uuid);
836
            }
837
        }
838
    }
839

    
840
    private void initStatusVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
841
        if (statusVoc == null){
842
            UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaStatusVoc;
843
            statusVoc = (OrderedTermVocabulary<PresenceAbsenceTerm>)this.getVocabularyService().find(uuid);
844
            if (statusVoc == null){
845
                createStatusVoc(state, uuid);
846
            }
847
        }
848
    }
849

    
850
    /**
851
     * @param state
852
     */
853
    private void createStatusVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
854
        //voc
855
        URI termSourceUri = null;
856
        String label = "Checklist of Greece Status";
857
        String description = "Status as used in the Checklist of Greece";
858
        statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm,
859
                description, label, null, termSourceUri);
860
        statusVoc.setUuid(vocUuid);
861

    
862
        rangeRestricted = addStatus(state, "RR", "Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestricted, statusVoc);
863
        doubtfullyRangeRestricted = addStatus(state, "?RR", "?Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestrictedDoubtfully, statusVoc);
864

    
865
        this.getVocabularyService().save(statusVoc);
866
        return;
867
    }
868

    
869

    
870
    /**
871
     * @param state
872
     */
873
    private void createHabitatVoc(SimpleExcelTaxonImportState<CONFIG> state, UUID vocUuid) {
874
        //voc
875
        URI termSourceUri = null;
876
        String label = "Checklist of Greece Habitats";
877
        String description = "Habitats as used in the Checklist of Greece";
878
        habitatVoc = OrderedTermVocabulary.NewInstance(TermType.State,
879
                description, label, null, termSourceUri);
880
        habitatVoc.setUuid(vocUuid);
881

    
882
        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);
883
        addHabitat(state, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
884
        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);
885
        addHabitat(state, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
886
        addHabitat(state, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
887
        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);
888
        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);
889
        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);
890

    
891
        this.getVocabularyService().save(habitatVoc);
892
        return;
893
    }
894

    
895
    /**
896
     * @param state
897
     * @param string
898
     * @param uuidlifeformt
899
     */
900
    private void addHabitat(SimpleExcelTaxonImportState<CONFIG> state, String abbrev, String label, String desc, UUID uuidHabitat) {
901
        addState(state, abbrev, label, desc, uuidHabitat, habitatVoc);
902
    }
903

    
904
    /**
905
     * @param state
906
     * @return
907
     */
908
    @SuppressWarnings("unchecked")
909
    private void createAreasVoc(SimpleExcelTaxonImportState<CONFIG> state) {
910
        //voc
911
        URI termSourceUri = null;
912
        String label = "Checklist of Greece Areas";
913
        String description = "Areas as used in the Checklist of Greece";
914
        areasVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea,
915
                description, label, null, termSourceUri);
916
        areasVoc.setUuid(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
917
//        Representation rep = Representation.NewInstance("Estados Méxicanos", "Estados Méxicanos", null, Language.SPANISH_CASTILIAN());
918
//        areasVoc.addRepresentation(rep);
919

    
920
        //greece country
921
        String countryLabel = "Greece";
922
        greece = NamedArea.NewInstance(countryLabel, countryLabel, "GR");
923
        greece.setUuid(FloraHellenicaTransformer.uuidAreaGreece);
924
        greece.setIdInVocabulary("GR");
925
        greece.setSymbol("GR");
926
        areasVoc.addTerm(greece);
927
        //FIXME
928
//        addMapping(greece, xx "mex_adm0", "iso", "MEX");
929

    
930
        addArea(state, "IoI", "Ionian Islands", 4, FloraHellenicaTransformer.uuidAreaIoI);
931
        addArea(state, "NPi", "North Pindos", 13, FloraHellenicaTransformer.uuidAreaNPi);
932
        addArea(state, "SPi", "South Pindos", 11, FloraHellenicaTransformer.uuidAreaSPi);
933
        addArea(state, "Pe", "Peloponnisos", 1, FloraHellenicaTransformer.uuidAreaPe);
934
        addArea(state, "StE", "Sterea Ellas", 12, FloraHellenicaTransformer.uuidAreaStE);
935
        addArea(state, "EC", "East Central Greece", 5, FloraHellenicaTransformer.uuidAreaEC);
936
        addArea(state, "NC", "North Central Greece", 2, FloraHellenicaTransformer.uuidAreaNC);
937
        addArea(state, "NE", "North-East Greece", 10, FloraHellenicaTransformer.uuidAreaNE);
938
        addArea(state, "NAe", "North Aegean islands", 7, FloraHellenicaTransformer.uuidAreaNAe);
939
        addArea(state, "WAe", "West Aegean islands", 9, FloraHellenicaTransformer.uuidAreaWAe);
940
        addArea(state, "Kik", "Kiklades", 8, FloraHellenicaTransformer.uuidAreaKik);
941
        addArea(state, "KK", "Kriti and Karpathos", 6, FloraHellenicaTransformer.uuidAreaKK);
942
        addArea(state, "EAe", "East Aegean islands", 3, FloraHellenicaTransformer.uuidAreaEAe);
943

    
944
        this.getVocabularyService().save(areasVoc);
945
        return;
946
    }
947

    
948
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
949
            Integer id, UUID uuid) {
950
        addArea(state, abbrevLabel, areaLabel, uuid, String.valueOf(id));  //short cut if label and mapping label are equal
951
    }
952

    
953
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
954
            UUID uuid, String mappingLabel) {
955
        addArea(state, abbrevLabel, areaLabel, uuid, mappingLabel, null);  //short cut if label and mapping label are equal
956
    }
957

    
958

    
959
    /**
960
     * @param state
961
     * @param string
962
     * @param uuidaguascalientes
963
     */
964
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String abbrevLabel, String areaLabel,
965
            UUID uuid, String mappingLabel, Integer id1) {
966
        NamedArea newArea = NamedArea.NewInstance(
967
                areaLabel, areaLabel, abbrevLabel);
968
        newArea.setIdInVocabulary(abbrevLabel);
969
        newArea.setUuid(uuid);
970
        newArea.setPartOf(greece);
971
        newArea.setLevel(null);
972
        newArea.setType(NamedAreaType.NATURAL_AREA());
973
        areasVoc.addTerm(newArea);
974
        if (mappingLabel != null){
975
            addMapping(newArea, "phytogeographical_regions_of_greece", "id", mappingLabel);
976
        }
977
    }
978

    
979
    private void addMapping(NamedArea area, String mapping_layer, String mapping_field, String abbrev) {
980
        GeoServiceAreaAnnotatedMapping mapping = (GeoServiceAreaAnnotatedMapping)this.getBean("geoServiceAreaAnnotatedMapping");
981
        GeoServiceArea geoServiceArea = new GeoServiceArea();
982
        geoServiceArea.add(mapping_layer, mapping_field, abbrev);
983
        mapping.set(area, geoServiceArea);
984
    }
985

    
986
}
(7-7/8)