Project

General

Profile

« Previous | Next » 

Revision c9f78619

Added by Andreas Müller about 8 years ago

Latest changes to cuba import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/cuba/CubaActivator.java
22 22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23 23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
24 24
import eu.etaxonomy.cdm.io.cuba.CubaImportConfigurator;
25
import eu.etaxonomy.cdm.io.cuba.CubaTransformer;
25 26
import eu.etaxonomy.cdm.model.agent.Person;
26 27
import eu.etaxonomy.cdm.model.description.Feature;
27 28
import eu.etaxonomy.cdm.model.description.FeatureNode;
......
39 40
	//database validation status (create, update, validate ...)
40 41
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41 42

  
42
    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
43
//    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
43 44
//  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
44
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cuba_production();
45
    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cuba_production();
45 46

  
46 47
	static boolean invers = false;
47 48

  
......
217 218
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
218 219
		root.addChild(newNode);
219 220

  
221
		Feature featurAltFam = (Feature)service.find(CubaTransformer.uuidAlternativeFamily);
222
		newNode = FeatureNode.NewInstance(featurAltFam);
223
		root.addChild(newNode);
224

  
225
	    Feature featurAltFam2 = (Feature)service.find(CubaTransformer.uuidAlternativeFamily2);
226
	    newNode = FeatureNode.NewInstance(featurAltFam2);
227
	    root.addChild(newNode);
228

  
220 229
//		newNode = FeatureNode.NewInstance(Feature.SYSTEMATICS());
221 230
//		root.addChild(newNode);
222 231

  
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaExcelImport.java
12 12
import java.util.ArrayList;
13 13
import java.util.Arrays;
14 14
import java.util.HashMap;
15
import java.util.HashSet;
15 16
import java.util.List;
16 17
import java.util.Set;
17 18
import java.util.UUID;
......
30 31
import eu.etaxonomy.cdm.model.common.Annotation;
31 32
import eu.etaxonomy.cdm.model.common.AnnotationType;
32 33
import eu.etaxonomy.cdm.model.common.Language;
34
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
33 35
import eu.etaxonomy.cdm.model.description.Distribution;
36
import eu.etaxonomy.cdm.model.description.Feature;
34 37
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
35 38
import eu.etaxonomy.cdm.model.description.TaxonDescription;
39
import eu.etaxonomy.cdm.model.description.TaxonInteraction;
40
import eu.etaxonomy.cdm.model.description.TextData;
36 41
import eu.etaxonomy.cdm.model.location.NamedArea;
37 42
import eu.etaxonomy.cdm.model.name.BotanicalName;
38 43
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
......
48 53
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
49 54
import eu.etaxonomy.cdm.model.taxon.Taxon;
50 55
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
56
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
51 57
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
52 58
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
53 59

  
......
71 77
    private static INonViralNameParser<?> nameParser = NonViralNameParserImpl.NewInstance();
72 78
    private static NomenclaturalCode nc = NomenclaturalCode.ICNAFP;
73 79

  
74
    private  static List<String> expectedKeys= Arrays.asList(new String[]{"Fam.","(Fam.)","Taxón","(Notas)","Syn.","End","Ind","Ind? D","Nat","Dud P","Adv","Cult C","CuW","PR PR*","Art","Hab(*)","May","Mat","IJ","CuC","VC","Ci","SS","CA","Cam","LT","CuE","Gr","Ho","SC","Gu","Esp","Ja","PR","Men","Bah","Cay","AmN","AmC","AmS","VM"});
80
    private  static List<String> expectedKeys= Arrays.asList(new String[]{
81
            "Fam. default","Fam. FRC","Fam. A&S","Fam. FC",
82
            "Taxón","(Notas)","Syn.","End","Ind","Ind? D","Nat","Dud P","Adv","Cult C","CuW","PR PR*","Art","Hab(*)","May","Mat","IJ","CuC","VC","Ci","SS","CA","Cam","LT","CuE","Gr","Ho","SC","Gu","Esp","Ja","PR","Men","Bah","Cay","AmN","AmC","AmS","VM"});
75 83

  
76 84
	@Override
77 85
    protected void analyzeRecord(HashMap<String, String> record, CubaImportState state) {
......
131 139
                PresenceAbsenceTerm endemicState = getPresenceTerm(state, endemicUuid, null, null, null, false);
132 140
                result.add(endemicState);
133 141
                checkAbsentHighestState(highestStatus, line, "endemic", false);
142
            }else if(endemicStr.equals("?")){
143
                UUID endemicDoubtfulUuid = state.getTransformer().getPresenceTermUuid("?E");
144
                PresenceAbsenceTerm endemicState = getPresenceTerm(state, endemicDoubtfulUuid, null, null, null, false);
145
                result.add(endemicState);
146
                checkAbsentHighestState(highestStatus, line, "endemic", false);
134 147
            }else{
135 148
                logger.warn(line + "Endemic not recognized: " + endemicStr);
136 149
            }
......
302 315
    private static final String heterotypicRegExStr_TEST = "([^\\(]{5,}" +"(\\(.+\\))?" + "[^\\)\\(]{2,})"
303 316
            +"(\\((.{6,})\\))?";
304 317
    private static final String auctRegExStr = "auct\\."
305
            +"((\\sFC(\\-S)?(\\s&\\sA&S)?)|(\\sA&S)|\\sSagra|\\sBritton|\\sGriseb\\.|\\sWright|\\sFRC|\\sCoL|\\sUrb\\.)?(\\s+p\\.\\s*p\\.)?";
318
            +"((\\sFC(\\-S)?(\\s&\\sA&S)?)|(\\sA&S)|\\sSagra|\\sCombs|\\sBritton|\\sGriseb\\.|\\sWright"
319
            + "|\\sHammer|\\sEngl\\.||\\sMaza|\\sMiers|\\sRoig|\\sBorhidi|\\sFRC|\\sCoL"
320
            + "|\\sAckerman|\\sMújica|\\sDíaz|\\sUrb\\.)?(\\s+p\\.\\s*p\\.)?";
321

  
322

  
306 323
    private static final String missapliedRegExStr = "(\\?\\s)?“(.*{5,})”\\s+(" + auctRegExStr + "|sensu\\s+.{2,})";
307
    private static final String nomInvalRegExStr = "“(.*{5,})”\\s+nom\\.\\s+inval\\.";
324
    private static final String sphalmRegExStr = "“(.*{5,})”\\s+((FC-S|A&S)\\s)?sphalm\\.(\\s(FC(-S)?|A&S|inval\\.))?";
325
    private static final String nomInvalRegExStr = "“(.*{5,})”\\s+nom\\.\\s+inval\\.(\\s(West|Moldenke|FC|Jacq.))?";
308 326
    private static final String homonymRegExStr = "\\s*(\\[.*\\])*\\s*";
309 327

  
310 328
    private static final Pattern acceptedRegEx = Pattern.compile(acceptedRegExStr + homonymRegExStr);
311 329
    private static final Pattern heterotypicRegEx = Pattern.compile(heterotypicRegExStr + homonymRegExStr);
312 330
    private static final Pattern missapliedRegEx = Pattern.compile(missapliedRegExStr);
313 331
    private static final Pattern nomInvalRegEx = Pattern.compile(nomInvalRegExStr);
332
    private static final Pattern sphalmRegEx = Pattern.compile(sphalmRegExStr);
314 333

  
315 334
    /**
316 335
     * @param record
......
337 356
        Matcher nomInvalMatcher = nomInvalRegEx.matcher(synonymStr);
338 357
        Matcher acceptedMatcher = acceptedRegEx.matcher(synonymStr);
339 358
        Matcher heterotypicMatcher = heterotypicRegEx.matcher(synonymStr);
359
        Matcher sphalmMatcher = sphalmRegEx.matcher(synonymStr);
340 360

  
341 361
        List<BotanicalName> homonyms = new ArrayList<>();
342 362
        if (missapliedMatcher.matches()){
......
367 387
            state.getCurrentTaxon().addMisappliedName(misappliedNameTaxon, relRef, null);
368 388
        }else if (nomInvalMatcher.matches()){
369 389
            String firstPart = nomInvalMatcher.group(1);
390
            String afterInval = nomInvalMatcher.group(2);
391
            if (StringUtils.isNotBlank(afterInval)){
392
                logger.warn(state.getCurrentLine() + ": After inval to be implemented: " + afterInval);
393
            }
370 394
            BotanicalName name = (BotanicalName)nameParser.parseSimpleName(firstPart, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
371 395
            NomenclaturalStatus status = NomenclaturalStatus.NewInstance( NomenclaturalStatusType.INVALID());
372 396
            name.addStatus(status);
373 397
            state.getCurrentTaxon().addSynonymName(name, SynonymRelationshipType.SYNONYM_OF());
398
        }else if (sphalmMatcher.matches()){
399
            String firstPart = sphalmMatcher.group(1);
400
            String sphalmPart = synonymStr.replace(firstPart, "").replace("“","").replace("”","").trim();
401
            BotanicalName name = (BotanicalName)nameParser.parseSimpleName(firstPart, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
402
//            NomenclaturalStatus status = NomenclaturalStatus.NewInstance( NomenclaturalStatusType.INVALID());
403
//            name.addStatus(status);
404
            SynonymRelationship sr = state.getCurrentTaxon().addSynonymName(name, SynonymRelationshipType.SYNONYM_OF());
405
            sr.getSynonym().setAppendedPhrase(sphalmPart);
406
            sr.getSynonym().setSec(null);
374 407
        }else if (acceptedMatcher.matches()){
375 408
            String firstPart = acceptedMatcher.group(1);
376 409
            String homonymPart = acceptedMatcher.groupCount() < 2 ? null : acceptedMatcher.group(2);
......
380 413
            String secondPart = heterotypicMatcher.groupCount() < 3 ? null : heterotypicMatcher.group(3);
381 414
            String homonymPart = heterotypicMatcher.groupCount() < 4 ? null : heterotypicMatcher.group(4);
382 415
            boolean isDoubtful = firstPart.matches("^\\?\\s*.*");
383
            boolean isHomonym = firstPart.trim().matches(".*" + HOMONYM_MARKER);
384
            firstPart = normalizeStatus(firstPart);
385
            BotanicalName synName = (BotanicalName)nameParser.parseReferencedName(firstPart, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
416
            firstPart = replaceHomonIlleg(firstPart);
417
            boolean isHomonym = firstPart.matches(".*" + HOMONYM_MARKER);
418
            BotanicalName synName = makeName(firstPart);
386 419
            if (synName.isProtectedTitleCache()){
387
                logger.warn(line + "heterotypic base synonym could not be parsed correctly:" + firstPart);
420
                logger.warn(line + " heterotypic base synonym could not be parsed correctly:" + firstPart);
388 421
            }
389 422
            if (isHomonym){
390 423
                homonyms.add(synName);
......
425 458
        BotanicalName currentBasionym = homotypicName;
426 459
        String[] splits = homotypicStr.split("\\s*,\\s*");
427 460
        for (String split : splits){
428
            boolean isHomonym = split.trim().matches(".*" + HOMONYM_MARKER);
429
            String singleName = normalizeStatus(split);
430
            BotanicalName newName = (BotanicalName)nameParser.parseReferencedName(singleName, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
461
            split = replaceHomonIlleg(split);
462
            boolean isHomonym = split.matches(".*" + HOMONYM_MARKER);
463
            BotanicalName newName = makeName(split);
431 464
            if (newName.isProtectedTitleCache()){
432 465
                logger.warn(state.getCurrentLine() + ": homotypic name part could not be parsed: " + split);
433 466
            }
......
444 477
                handleBasionym(currentBasionym, newName);
445 478
            }
446 479
        }
447
        makeHomonyms(homonyms, homonymPart, state);
480
        makeHomonyms(homonyms, homonymPart, state, currentBasionym);
481
    }
482

  
483

  
484
    /**
485
     * @param split
486
     * @return
487
     */
488
    private String replaceHomonIlleg(String split) {
489
        String result = split.trim().replace("homon. illeg.", "nom. illeg. homon.").trim();
490
        return result;
448 491
    }
449 492

  
450 493

  
......
452 495
     * @param homonyms
453 496
     * @param homonymPart
454 497
     * @param state
498
     * @param currentBasionym
455 499
     */
456
    private void makeHomonyms(List<BotanicalName> homonyms, String homonymPart, CubaImportState state) {
500
    private void makeHomonyms(List<BotanicalName> homonyms, String homonymPartOrig, CubaImportState state,
501
            BotanicalName currentBasionym) {
457 502
        String line = state.getCurrentLine() + ": ";
458
        homonymPart = homonymPart == null ? "" : homonymPart.trim();
503
        String homonymPart = homonymPartOrig == null ? "" : homonymPartOrig.trim();
459 504
        if (homonyms.isEmpty() && homonymPart.equals("")){
460 505
            return;
461 506
        }else if (homonymPart.equals("")){
......
465 510
        homonymPart = homonymPart.substring(1, homonymPart.length() - 1);
466 511
        String[] splits = homonymPart.split("\\]\\s*\\[");
467 512
        if (splits.length != homonyms.size()){
468
            logger.warn(line + "Number of homonyms (" + homonyms.size() + ") and homonymParts ("+splits.length+") does not match");
513
            if(homonyms.size() == 0 && splits.length >= 1){
514
                handleSimpleBlockingNames(splits, state, currentBasionym);
515
            }else{
516
                logger.warn(line + "Number of homonyms (" + homonyms.size() + ") and homonymParts ("+splits.length+") does not match");
517
            }
469 518
            return;
470 519
        }
471 520
        int i = 0;
472 521
        for (String split : splits){
473 522
            split = split.replaceAll("^non\\s+", "");
474
            BotanicalName newName = (BotanicalName)nameParser.parseReferencedName(split, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
523
            BotanicalName newName = makeName(split);
524
//            BotanicalName newName = (BotanicalName)nameParser.parseReferencedName(split, state.getConfig().getNomenclaturalCode(), Rank.SPECIES());
475 525
            if (newName.isProtectedTitleCache()){
476 526
                logger.warn(state.getCurrentLine() + ": homonym name could not be parsed: " + split);
477 527
            }
......
481 531
    }
482 532

  
483 533

  
534
    /**
535
     * @param homonymPart
536
     * @param state
537
     * @param currentBasionym
538
     */
539
    private void handleSimpleBlockingNames(String[] splitsi, CubaImportState state,
540
            BotanicalName currentBasionym) {
541
        for (String spliti : splitsi){
542

  
543
            String split = spliti.replaceAll("^non\\s+", "");
544
            BotanicalName newName = makeName(split);
545
            if (newName.isProtectedTitleCache()){
546
                logger.warn(state.getCurrentLine() + ": blocking name could not be parsed: " + split);
547
            }
548
            Set<BotanicalName> typifiedNames = (Set)currentBasionym.getHomotypicalGroup().getTypifiedNames();
549
            Set<BotanicalName> candidates = new HashSet<>();
550
            for (BotanicalName name : typifiedNames){
551
                if (name.getGenusOrUninomial() != null && name.getGenusOrUninomial().equals(newName.getGenusOrUninomial())){
552
                    if (name.getStatus().isEmpty() || ! name.getStatus().iterator().next().getType().equals(NomenclaturalStatusType.ILLEGITIMATE())){
553
                        candidates.add(name);
554
                    }
555
                }
556
            }
557
            if (candidates.size() == 1){
558
                newName.addRelationshipToName(candidates.iterator().next(), NameRelationshipType.BLOCKING_NAME_FOR(), null);
559
            }else{
560
                logger.warn(state.getCurrentLine() + ": Blocking name could not be handled. " + candidates.size() + " candidates.");
561
            }
562
        }
563
    }
564

  
565

  
484 566
    /**
485 567
     * @param newName
486 568
     * @param homotypicName
......
550 632
            taxonStr = taxonStr.substring(1, taxonStr.length() - 1);
551 633
            isAbsent = true;
552 634
        }
553
        taxonStr = normalizeStatus(taxonStr);
554 635

  
555
        BotanicalName botanicalName = (BotanicalName)nameParser.parseReferencedName(taxonStr, nc, Rank.SPECIES());
636
        BotanicalName botanicalName = makeName(taxonStr);
556 637
        Reference<?> sec = getSecReference(state);
557 638
        Taxon taxon = Taxon.NewInstance(botanicalName, sec);
558 639
        TaxonNode higherNode;
......
578 659
        return taxon;
579 660
    }
580 661

  
662
    private final String orthVarRegExStr = "[A-Z][a-z]+\\s[a-z]+\\s(\\(‘([a-z]){3,}’\\))\\s(\\([A-Z][a-z]+\\.?\\)\\s)?[A-Z][a-zó]+\\.?";
663
    private final Pattern orthVarRegEx = Pattern.compile(orthVarRegExStr);
664
    /**
665
     * @param taxonStr
666
     * @return
667
     */
668
    private BotanicalName makeName(String nameStrOrig) {
669
        //normalize
670
        String nameStr = normalizeStatus(nameStrOrig);
671
        //orthVar
672
        Matcher orthVarMatcher = orthVarRegEx.matcher(nameStr);
673
        String orthVar = null;
674
        if (orthVarMatcher.matches()) {
675
            orthVar = orthVarMatcher.group(1);
676
            nameStr = nameStr.replace(" " + orthVar, "").trim().replaceAll("\\s{2,}", " ");
677
            orthVar = orthVar.substring(2, orthVar.length() - 2);
678

  
679
        }
680
        BotanicalName result = (BotanicalName)nameParser.parseReferencedName(nameStr, nc, Rank.SPECIES());
681
        if (orthVar != null){
682
            BotanicalName orthVarName = (BotanicalName)result.clone();
683
            //TODO
684
            Reference<?> citation = null;
685
            orthVarName.addRelationshipToName(result, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), citation, null, null);
686
            orthVarName.setSpecificEpithet(orthVar);
687
        }
688
        return result;
689

  
690
    }
691

  
581 692
    /**
582 693
     * @param state
583 694
     * @return
......
594 705

  
595 706

  
596 707
    private static final String[] nomStatusStrings = new String[]{"nom. cons.", "ined.", "nom. illeg.",
597
            "nom. rej.","nom. cons. prop.","nom. altern.","nom. confus.","nom. dub."};
708
            "nom. rej.","nom. cons. prop.","nom. altern.","nom. confus.","nom. dub.", "nom. nud."};
598 709
    /**
599 710
     * @param taxonStr
600 711
     * @return
601 712
     */
602
    private String normalizeStatus(String taxonStr) {
603
        if (taxonStr == null){
713
    private String normalizeStatus(String nameStr) {
714
        if (nameStr == null){
604 715
            return null;
605 716
        }
717
        String result = nameStr.replaceAll(HOMONYM_MARKER, "").trim();
606 718
        for (String nomStatusStr : nomStatusStrings){
607 719
            nomStatusStr = " " + nomStatusStr;
608
            if (taxonStr.endsWith(nomStatusStr)){
609
                taxonStr = taxonStr.replace(nomStatusStr, "," + nomStatusStr);
720
            if (result.endsWith(nomStatusStr)){
721
                result = result.replace(nomStatusStr, "," + nomStatusStr);
610 722
            }
611 723
        }
612
        taxonStr = taxonStr.replaceAll(HOMONYM_MARKER, "").trim();
613
        taxonStr = taxonStr.replaceAll(DOUBTFUL_MARKER, "").trim();
614
        return taxonStr;
724
        result = result.replaceAll(DOUBTFUL_MARKER, "").trim();
725
        result = result.replace("[taxon]", "[infraspec.]");
726
        return result;
615 727

  
616 728

  
617 729
    }
......
623 735
     * @return
624 736
     */
625 737
    private TaxonNode getFamilyTaxon(HashMap<String, String> record, CubaImportState state) {
626
        String familyStr = getValue(record, "Fam.");
738
        String familyStr = getValue(record, "Fam. default");
627 739
        if (familyStr == null){
628 740
            return null;
629 741
        }
......
632 744
        if (family != null){
633 745
            familyNode = family.getTaxonNodes().iterator().next();
634 746
        }else{
635
            BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
636
            name.setGenusOrUninomial(familyStr);
747
            BotanicalName name = state.getFamilyName(familyStr);
748
            if (name == null){
749
                name = BotanicalName.NewInstance(Rank.FAMILY());
750
                name.setGenusOrUninomial(familyStr);
751
                state.putFamilyName(familyStr, name);
752
            }
637 753
            Reference<?> sec = getSecReference(state);
638 754
            Taxon taxon = Taxon.NewInstance(name, sec);
639 755
            ITaxonTreeNode rootNode = getClassification(state);
......
644 760
        return familyNode;
645 761
    }
646 762

  
763
    /**
764
     * @param state
765
     * @param taxon
766
     * @param famStr
767
     * @param famRef
768
     * @return
769
     */
770
    private Taxon makeAlternativeFamilyTaxon(CubaImportState state, String famStr, Reference<?> famRef) {
771
        String key = famRef.getTitle() + ":"+ famStr;
772
        Taxon family = state.getHigherTaxon(key);
773
        if (family == null){
774
            BotanicalName name = state.getFamilyName(famStr);
775
            if (name == null){
776
                name = BotanicalName.NewInstance(Rank.FAMILY());
777
                name.setGenusOrUninomial(famStr);
778
                state.putFamilyName(famStr, name);
779
            }
780
            family = Taxon.NewInstance(name, famRef);
781
            state.putHigherTaxon(key, family);
782
        }
783

  
784
        return family;
785
    }
786

  
647 787

  
648 788
    /**
649 789
     * @param state
......
719 859
            }
720 860
        }
721 861

  
722
        if (record.get("Fam.") == null && keys.size() == 2 && record.get("Syn.") == null && record.get("Nat") != null && record.get("Adv") != null){
862
        if (record.get("Fam. default") == null && keys.size() == 2 && record.get("Syn.") == null && record.get("Nat") != null && record.get("Adv") != null){
723 863
            //second header line, don't handle
724 864
            return;
725 865
        }
......
738 878
            }
739 879
        }
740 880

  
741
        //(Fam.)
742
        //TODO
881

  
743 882

  
744 883
        //Taxón
745 884
        Taxon taxon = makeTaxon(record, state, familyTaxon, isSynonym);
......
749 888
        }
750 889
        state.setCurrentTaxon(taxon);
751 890

  
891
        //Fam. ALT
892
        makeAlternativeFamilies(record, state, familyTaxon, taxon);
893

  
752 894
        //(Notas)
753 895
        makeNotes(record, state);
754 896

  
......
764 906
//        "CuE","Gr","Ho","SC","Gu",
765 907
        makeProvincesDistribution(record, state);
766 908

  
767
//    "Esp","Ja","PR","Men","Bah","Cay",
768
//    "AmN","AmC","AmS","VM"});
769
      makeOtherAreasDistribution(record, state);
770

  
909
//      "Esp","Ja","PR","Men","Bah","Cay",
910
//      "AmN","AmC","AmS","VM"});
911
        makeOtherAreasDistribution(record, state);
771 912

  
772 913

  
773 914
        state.setHighestStatusForTaxon(null);
......
780 921
	/**
781 922
     * @param record
782 923
     * @param state
924
     * @param familyTaxon
925
     * @param taxon
926
     */
927
    private void makeAlternativeFamilies(HashMap<String, String> record,
928
            CubaImportState state,
929
            TaxonNode familyTaxon,
930
            Taxon taxon) {
931

  
932
        String famFRC = record.get("Fam. FRC");
933
        String famAS = record.get("Fam. A&S");
934
        String famFC = record.get("Fam. FC");
935

  
936
        Reference<?> refFRC = makeReference(state, CubaTransformer.uuidRefFRC);
937
        Reference<?> refAS = makeReference(state, CubaTransformer.uuidRefAS);
938
        Reference<?> refFC = makeReference(state, CubaTransformer.uuidRefFC);
939

  
940
        makeSingleAlternativeFamily(state, taxon, famFRC, refFRC);
941
        makeSingleAlternativeFamily(state, taxon, famAS, refAS);
942
        makeSingleAlternativeFamily(state, taxon, famFC, refFC);
943
    }
944

  
945

  
946
    /**
947
     * @param state
948
     * @param uuidreffrc
949
     * @return
950
     */
951
    private Reference<?> makeReference(CubaImportState state, UUID uuidRef) {
952
        Reference<?> ref = state.getReference(uuidRef);
953
        if (ref == null){
954
            ref = getReferenceService().find(uuidRef);
955
            state.putReference(uuidRef, ref);
956
        }
957
        return ref;
958
    }
959

  
960

  
961
    /**
962
     * @param state
963
     * @param taxon
964
     * @param famString
965
     * @param famRef
966
     */
967
    private void makeSingleAlternativeFamily(CubaImportState state, Taxon taxon, String famStr, Reference<?> famRef) {
968
        if (isBlank(famStr)){
969
            return;
970
        }
971

  
972
        TaxonDescription desc = getTaxonDescription(taxon, false, true);
973

  
974
        UUID altFamUuid1;
975
        UUID altFamUuid2;
976
        try {
977
            altFamUuid1 = state.getTransformer().getFeatureUuid("Alt.Fam.");
978
            altFamUuid2 = state.getTransformer().getFeatureUuid("Alt.Fam.2");
979
        } catch (UndefinedTransformerMethodException e) {
980
            throw new RuntimeException(e);
981
        }
982

  
983

  
984
        Taxon famTaxon = makeAlternativeFamilyTaxon(state, famStr, famRef);
985

  
986

  
987
        //TextData
988
        Feature feature1 = getFeature(state, altFamUuid1, "Family in other floras", "Family in other floras", "Other floras", null);
989
//        TextData textData = TextData.NewInstance(feature1, famStr, Language.DEFAULT(), null);
990
        TextData textData = TextData.NewInstance(feature1, null, Language.DEFAULT(), null);
991
        textData.addSource(OriginalSourceType.PrimaryTaxonomicSource, null,null, famRef, null, famTaxon.getName(),null);
992
        desc.addElement(textData);
993

  
994

  
995

  
996
        //TaxonInteraction
997
        Feature feature2 = getFeature(state, altFamUuid2, "Family in other floras(2)", "Family in other floras(2)", "Other floras(2)", null);
998
        feature2.setSupportsTaxonInteraction(true);
999
        TaxonInteraction taxInteract = TaxonInteraction.NewInstance(feature2);
1000
        taxInteract.setTaxon2(famTaxon);
1001
        taxInteract.addSource(OriginalSourceType.PrimaryTaxonomicSource, null,null, famRef, null);
1002
        desc.addElement(taxInteract);
1003

  
1004
        //Concept Relation
1005
        famTaxon.addTaxonRelation(taxon, TaxonRelationshipType.INCLUDES(), taxon.getSec(), null);
1006

  
1007
    }
1008

  
1009

  
1010

  
1011

  
1012

  
1013
    /**
1014
     * @param record
1015
     * @param state
783 1016
     * @param taxon
784 1017
     */
785 1018
    // "CuW","PR PR*","Art","Hab(*)","May","Mat","IJ",
......
867 1100
            if (state.isCubanProvince() && isMinus(statusStr)){
868 1101
                getAbsenceTermForStatus(state, highestStatus);
869 1102
            }else if (! state.isCubanProvince() && isMinus(statusStr)){
870
                status = state.getTransformer().getPresenceTermByKey("");
1103
                status = state.getTransformer().getPresenceTermByKey("--");
871 1104
            }else{
872 1105
                UUID statusUuid = state.getTransformer().getPresenceTermUuid(statusStr);
873 1106
                status = getPresenceTerm(state, statusUuid, null, null, null, false);
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaImportState.java
19 19
import eu.etaxonomy.cdm.io.excel.common.ExcelImportState;
20 20
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
21 21
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
22
import eu.etaxonomy.cdm.model.name.BotanicalName;
22 23
import eu.etaxonomy.cdm.model.reference.Reference;
23 24
import eu.etaxonomy.cdm.model.taxon.Classification;
24 25
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
36 37

  
37 38
	private final Map<String, UUID> higherTaxonUuidMap = new HashMap<String, UUID>();
38 39

  
40
	private final Map<String, BotanicalName> familyNameMap = new HashMap<String, BotanicalName>();
41

  
42

  
43

  
39 44
	//classification
40 45
	private Classification classification;
41 46
    public Classification getClassification() {return classification;}
......
97 102
        return higherTaxonUuidMap.containsKey(higherName);
98 103
    }
99 104

  
105
    //family names
106
    public BotanicalName getFamilyName(String familyStr) {
107
        return familyNameMap.get(familyStr);
108
    }
109
    public void putFamilyName(String familyStr, BotanicalName name) {
110
        familyNameMap.put(familyStr, name);
111
    }
112

  
113

  
114
    Map<UUID, Reference<?>> refMap = new HashMap<UUID, Reference<?>>();
115
    //reference
116
    public Reference<?> getReference(UUID uuidRef) {
117
        return refMap.get(uuidRef);
118
    }
119
    public void putReference(UUID uuidRef, Reference<?> ref) {
120
        refMap.put(uuidRef, ref);
121
    }
122

  
100 123

  
101 124

  
102 125
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaTransformer.java
30 30
    @SuppressWarnings("unused")
31 31
	private static final Logger logger = Logger.getLogger(CubaTransformer.class);
32 32

  
33
    //references
34
    public static final UUID uuidRefFRC = UUID.fromString("c1caf6a2-5083-4f44-8f97-9abe23a84cd8");
35
    public static final UUID uuidRefAS = UUID.fromString("1f15291a-b4c5-4e15-960f-d0145a250539");
36
    public static final UUID uuidRefFC = UUID.fromString("c5a0bfb8-85b2-422d-babe-423aa2e24c35");
37

  
38
    //featureUUID
39
    public static final UUID uuidAlternativeFamily = UUID.fromString("a005f8a1-6377-4641-a826-185f67136860");
40
    public static final UUID uuidAlternativeFamily2 = UUID.fromString("ff15b54a-6785-4ba0-acb6-8fb2eab80a6a");
41

  
33 42
    //presenceTerm
34 43
    public static final UUID nonNativeDoubtfullyNaturalisedUuid = UUID.fromString("a1e26234-831e-4190-9fe3-011aca09ddba");
35 44
    public static final UUID adventiveAlienUuid = UUID.fromString("06e48a0b-3e48-4ef8-9bdd-0755880e99ce");
......
38 47
    public static final UUID doubtfulIndigenousUuid = UUID.fromString("f47f4f4e-9d84-459a-b747-27a1af24ab7a");
39 48
    public static final UUID doubtfulIndigenousDoubtfulUuid = UUID.fromString("7ddfd94d-01a4-496c-a6d6-18584c00af59");
40 49

  
50
    public static final UUID doubtfullyEndemicUuid = UUID.fromString("5f954f08-267a-4928-b073-12328f74c187");
41 51
    public static final UUID doubtfullyNaturalisedUuid = UUID.fromString("9e0b413b-5a68-4e5b-91f2-227b4f832466");
42 52
    public static final UUID doubtfullyNonNativeUuid = UUID.fromString("c42ca644-1773-4230-a2ee-328a5d4a21ab");
43

  
44 53
    public static final UUID endemicInErrorUuid = UUID.fromString("679b215d-c231-4ee2-ae12-3ffc3dd528ad");
45 54
    public static final UUID adventiveInErrorUuid = UUID.fromString("9b910b7b-43e3-4260-961c-6063b11cb7dc");
46 55
    public static final UUID nonNativeInErrorUuid = UUID.fromString("b9153d90-9e31-465a-a28c-79077a8ed4c2");
......
102 111
    public static final UUID uuidSouthAmerica = UUID.fromString("0fccc041-ce9d-40d5-8b9b-d7d833feed38");
103 112
    public static final UUID uuidOldWorld = UUID.fromString("c6b45544-01df-4c97-bb29-9058964c5b57");
104 113

  
105
//    public static final UUID uuid = UUID.fromString("");
106
//    public static final UUID uuid = UUID.fromString("");
107
//    public static final UUID uuid = UUID.fromString("");
108

  
109
    private static final UUID uuidCubaTdwg = UUID.fromString("66ce6bb4-b48e-483b-aed1-62646e9c80b8");
110 114
    @Override
111 115
    public UUID getNamedAreaUuid(String key) throws UndefinedTransformerMethodException {
112 116
        if (StringUtils.isBlank(key)){return null;
......
181 185
        }else if (key.equalsIgnoreCase("C")){return cultivatedOnlyUuid;
182 186
        }else if (key.equalsIgnoreCase("(C)")){return occasionallyCultivatedUuid;
183 187

  
188
        }else if (key.equalsIgnoreCase("?E")){return doubtfullyEndemicUuid;
184 189
        }else if (key.equalsIgnoreCase("?Nat.")){return doubtfullyNaturalisedUuid;
185 190
        }else if (key.equalsIgnoreCase("?N")){return doubtfullyNaturalisedUuid;
186 191
        }else if (key.equalsIgnoreCase("?Dud.")){return doubtfullyNonNativeUuid;
......
217 222

  
218 223
        }else if (key.equalsIgnoreCase("-Cult.")){return PresenceAbsenceTerm.CULTIVATED_REPORTED_IN_ERROR();
219 224

  
225
        }else if (key.equalsIgnoreCase("--")){return PresenceAbsenceTerm.REPORTED_IN_ERROR();
226

  
220 227
//        }else if (key.equalsIgnoreCase("--")){return PresenceAbsenceTerm;
221 228

  
222 229
        }else{
......
224 231
        }
225 232
    }
226 233

  
234
    @Override
235
    public UUID getFeatureUuid(String key) throws UndefinedTransformerMethodException {
236
        if (key == null){
237
            return null;
238
        }else if (key.equalsIgnoreCase("Alt.Fam.")){
239
            return uuidAlternativeFamily;
240
        }else if (key.equalsIgnoreCase("Alt.Fam.2")){
241
            return uuidAlternativeFamily2;
242
        }else{
243
            throw new RuntimeException("feature not defined: " + key);
244
        }
245
    }
246

  
247

  
248

  
227 249
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaVocabularyImport.java
9 9

  
10 10
package eu.etaxonomy.cdm.io.cuba;
11 11

  
12
import java.net.URI;
12 13
import java.util.UUID;
13 14

  
14 15
import org.apache.log4j.Logger;
15 16
import org.springframework.stereotype.Component;
16 17
import org.springframework.transaction.TransactionStatus;
17 18

  
19
import eu.etaxonomy.cdm.common.DOI;
18 20
import eu.etaxonomy.cdm.io.common.CdmImportBase;
19 21
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
20 22
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
21 25
import eu.etaxonomy.cdm.model.common.TermType;
22 26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
23 27
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
24 28
import eu.etaxonomy.cdm.model.location.NamedArea;
25 29
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
26 30
import eu.etaxonomy.cdm.model.location.NamedAreaType;
31
import eu.etaxonomy.cdm.model.reference.Reference;
32
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
33
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
34

  
27 35

  
28 36
/**
29 37
 * @author a.mueller
......
44 52
        try {
45 53
            makeAreas(state);
46 54
            makePresenceAbsenceTerms(state);
55
            makeAlternativeFloras(state);
47 56
        } catch (UndefinedTransformerMethodException e) {
48 57
           e.printStackTrace();
49 58
        }
50 59
    }
51 60

  
61
    /**
62
     * @param state
63
     */
64
    private void makeAlternativeFloras(CubaImportState state) {
65

  
66
        //FRC
67
        Reference<?> refFRC = ReferenceFactory.newBook();
68
        refFRC.setUuid(CubaTransformer.uuidRefFRC);
69
        refFRC.setTitle("Flora de la República de Cuba");
70
        getReferenceService().save(refFRC);
71

  
72
        //A&S
73
        Reference<?> refAS = ReferenceFactory.newArticle();
74
        refAS.setUuid(CubaTransformer.uuidRefAS);
75
        refAS.setTitle("Catalogue of seed plants of the West Indies");
76
        Person acevedo = Person.NewInstance();
77
        acevedo.setFirstname("Pedro");
78
        acevedo.setLastname("Acevedo-Rodríguez");
79
        Person strong = Person.NewInstance();
80
        strong.setFirstname("Mark T.");
81
        strong.setLastname("Strong");
82
        Team asTeam = Team.NewInstance();
83
        asTeam.addTeamMember(acevedo);
84
        asTeam.addTeamMember(strong);
85
        refAS.setAuthorship(asTeam);
86
        refAS.setDatePublished(TimePeriodParser.parseString("2012-01-01"));
87
        refAS.setVolume("98");
88
        refAS.setPages("i-xxv, 1-1192");
89
        refAS.setIssn("0081-024X");
90
        refAS.setDoi(DOI.fromString("10.5479/si.0081024X.98.1"));
91
        refAS.setUri(URI.create("http://hdl.handle.net/10088/17551"));
92
        String abstracct = "The catalogue enumerates all taxa of Gymnosperms, Dicotyledons, and Monocotyledons occurring in the West Indies archipelago excluding the islands off the coast of Venezuela (Netherlands Antilles, Venezuelan Antilles, Tobago, and Trinidad). For each accepted taxon, nomenclature (including synonyms described from the West Indies and their references to publication), distribution in the West Indies (including endemic, native, or exotic status), common names, and a numerical listing of literature records are given. Type specimen citations are provided for accepted names and synonyms of Cyperaceae, Sapindaceae, and some selected genera in several families including the Apocynaceae (Plumeria), Aquifoliaceae (Ilex), and Santalaceae (Dendrophthora). More than 30,000 names were treated comprising 208 families, 2,033 genera, and 12,279 taxa, which includes exotic and commonly cultivated plants. The total number of indigenous taxa was approximately 10,470 of which 71% (7,446 taxa) are endemic to the archipelago or part of it. Fifteen new names, 37 combinations, and 7 lectotypifications are validated. A searchable website of this catalogue, maintained and continuously updated at the Smithsonian Institution, is available at http://botany.si.edu/antilles/WestIndies/.";
93
        refAS.setReferenceAbstract(abstracct);
94
        Reference<?> refASIn = ReferenceFactory.newJournal();
95
        refAS.setInReference(refASIn);
96
        getReferenceService().save(refAS);
97

  
98
        //FC
99
        Reference<?> refFC = ReferenceFactory.newBook();
100
        refFC.setUuid(CubaTransformer.uuidRefFC);
101
        refFC.setTitle("Flora de Cuba");
102
        Person leon = Person.NewTitledInstance("León");
103
        Person alain = Person.NewTitledInstance("Alain");
104
        Team fcTeam = Team.NewInstance();
105
        fcTeam.addTeamMember(leon);
106
        fcTeam.addTeamMember(alain);
107
        refAS.setAuthorship(fcTeam);
108
        getReferenceService().save(refFC);
109

  
110
    }
111

  
52 112
    /**
53 113
     * @param state
54 114
     * @throws UndefinedTransformerMethodException
......
68 128

  
69 129
        final boolean PRESENT = false;
70 130

  
131
        //doubtfully endemic
132
        UUID doubtfullyEndemicUuid = transformer.getPresenceTermUuid("?E");
133
        this.getPresenceTerm(state, doubtfullyEndemicUuid, "doubtfully endemic", "doubtfully endemic", "?E", false);
71 134

  
72 135
        //indigenous
73 136
        UUID indigenousUuid = transformer.getPresenceTermUuid("+");
74
        PresenceAbsenceTerm indigenous = this.getPresenceTerm(state, indigenousUuid, "indigenous", "Indigenous", "+", false);
137
        this.getPresenceTerm(state, indigenousUuid, "indigenous", "Indigenous", "+", false);
75 138
        UUID indigenousDoubtfulUuid = transformer.getPresenceTermUuid("?");
76
        PresenceAbsenceTerm indigenousDoubtful = this.getPresenceTerm(state, indigenousDoubtfulUuid, "indigenous, doubtfully present", "indigenous, doubtfully present", "?", false);
139
        this.getPresenceTerm(state, indigenousDoubtfulUuid, "indigenous, doubtfully present", "indigenous, doubtfully present", "?", false);
77 140
        UUID nonNativeDoubtfulNaturalizedUuid = transformer.getPresenceTermUuid("P");
78
        PresenceAbsenceTerm nonNative = this.getPresenceTerm(state, nonNativeDoubtfulNaturalizedUuid, "non-native and doubtfully naturalised", "non-native and doubtfully naturalised", "P", false);
141
        this.getPresenceTerm(state, nonNativeDoubtfulNaturalizedUuid, "non-native and doubtfully naturalised", "non-native and doubtfully naturalised", "P", false);
79 142
        UUID casualUuid = transformer.getPresenceTermUuid("A");
80
        PresenceAbsenceTerm casual = this.getPresenceTerm(state, casualUuid, "adventive (casual) alien", "adventive (casual) alien", "A", false);
143
        this.getPresenceTerm(state, casualUuid, "adventive (casual) alien", "adventive (casual) alien", "A", false);
81 144

  
82 145
        //occasionally cultivated
83 146
        label = "occasionally cultivated";
84 147
        abbrev = "(C)";
85 148
        UUID occasionallyCultivatedUuid = transformer.getPresenceTermUuid(abbrev);
86
        PresenceAbsenceTerm occasionallyCultivated = getPresenceTerm(state, occasionallyCultivatedUuid, label, label, abbrev, PRESENT, cubaStatusVocabualary);
149
        getPresenceTerm(state, occasionallyCultivatedUuid, label, label, abbrev, PRESENT, cubaStatusVocabualary);
87 150

  
88 151
        //doubtfully present
89 152
        UUID doubtfullyIndigenousUuid = transformer.getPresenceTermUuid("D");
90
        PresenceAbsenceTerm doubtfullyIndigenous = this.getPresenceTerm(state, doubtfullyIndigenousUuid, "indigenous?", "Indigenous?", "D", false);
153
        this.getPresenceTerm(state, doubtfullyIndigenousUuid, "indigenous?", "Indigenous?", "D", false);
91 154
        UUID doubtfullyIndigenousDoubtfulUuid = transformer.getPresenceTermUuid("??");
92
        PresenceAbsenceTerm doubtfulIndigenousDoutful = this.getPresenceTerm(state, doubtfullyIndigenousDoubtfulUuid, "?indigenous?", "doubfully indigenous, (und) doubtfully present", "??", false);
155
        this.getPresenceTerm(state, doubtfullyIndigenousDoubtfulUuid, "?indigenous?", "doubfully indigenous, (und) doubtfully present", "??", false);
93 156

  
94 157
        UUID doubtfullyNaturalisedUuid = transformer.getPresenceTermUuid("?N");
95
        PresenceAbsenceTerm doubtfullyNaturalised = this.getPresenceTerm(state, doubtfullyNaturalisedUuid, "?non-native and doubtfully naturalised", "non-native and doubtfully naturalised, doubtfully present", "?N", false);
158
        this.getPresenceTerm(state, doubtfullyNaturalisedUuid, "?non-native and doubtfully naturalised", "non-native and doubtfully naturalised, doubtfully present", "?N", false);
96 159
        UUID doubtfullyNonNativeUuid = transformer.getPresenceTermUuid("?P");
97
        PresenceAbsenceTerm doubtfullyNonNative = this.getPresenceTerm(state, doubtfullyNonNativeUuid, "?adventive (casual) alien ", "adventive (casual) alien, doubtfully present", "?P", false);
160
        this.getPresenceTerm(state, doubtfullyNonNativeUuid, "?adventive (casual) alien ", "adventive (casual) alien, doubtfully present", "?P", false);
98 161

  
99 162
        //reported in error
100 163
        boolean isAbsent = true;
101 164
        UUID endemicErrorUuid = transformer.getPresenceTermUuid("-E");
102
        PresenceAbsenceTerm endemicError = this.getPresenceTerm(state, endemicErrorUuid, "endemic, reported in error", "endemic, reported in error", "-E", isAbsent);
165
        this.getPresenceTerm(state, endemicErrorUuid, "endemic, reported in error", "endemic, reported in error", "-E", isAbsent);
103 166
        UUID naturalizedErrorUuid = transformer.getPresenceTermUuid("-N");
104
        PresenceAbsenceTerm naturalizedError = this.getPresenceTerm(state, naturalizedErrorUuid, "naturalised, reported in error", "naturalised, reported in error", "-N", isAbsent);
167
        this.getPresenceTerm(state, naturalizedErrorUuid, "naturalised, reported in error", "naturalised, reported in error", "-N", isAbsent);
105 168
        UUID nonNativeErrorUuid = transformer.getPresenceTermUuid("-P");
106
        PresenceAbsenceTerm nonNativeError = this.getPresenceTerm(state, nonNativeErrorUuid, "non-native and doubtfully naturalised, reported in error", "non-native and doubtfully naturalised, reported in error", "-P", isAbsent);
169
        this.getPresenceTerm(state, nonNativeErrorUuid, "non-native and doubtfully naturalised, reported in error", "non-native and doubtfully naturalised, reported in error", "-P", isAbsent);
107 170
        UUID casualErrorUuid = transformer.getPresenceTermUuid("-A");
108
        PresenceAbsenceTerm casualError = this.getPresenceTerm(state, casualErrorUuid, "adventive alien , reported in error", "adventive alien , reported in error", "-A", isAbsent);
109

  
110

  
171
        this.getPresenceTerm(state, casualErrorUuid, "adventive alien , reported in error", "adventive alien , reported in error", "-A", isAbsent);
111 172

  
112 173
        commitTransaction(tx);
113 174
    }

Also available in: Unified diff