Project

General

Profile

Revision 075bc33f

ID075bc33fed55ad7a90b65b2705849effab7f60c9
Parent d81a4119
Child 81bcaf06

Added by Patrick Plitzner almost 4 years ago

Fix merge problems

View differences:

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/SpecimenImportBase.java
33 33
import eu.etaxonomy.cdm.model.agent.Institution;
34 34
import eu.etaxonomy.cdm.model.agent.Team;
35 35
import eu.etaxonomy.cdm.model.common.CdmBase;
36
import eu.etaxonomy.cdm.model.common.ISourceable;
36 37
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
37 38
import eu.etaxonomy.cdm.model.common.LanguageString;
38 39
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
......
1308 1309
	        return true;
1309 1310
	    }
1310 1311

  
1311
	    /**
1312
	     * @param specimen
1313
	     * @param source
1314
	     * @return
1315
	     */
1316
	    private boolean sourceNotLinkedToElement(SpecimenOrObservationBase<?> specimen, OriginalSourceBase<?> source) {
1317
	        Set<IdentifiableSource> linkedSources = specimen.getSources();
1318
	        for (IdentifiableSource is:linkedSources){
1319
	            Reference a = is.getCitation();
1320
	            Reference b = source.getCitation();
1321
	            String c = is.getCitationMicroReference();
1322
	            String d = source.getCitationMicroReference();
1312
	    private <T extends OriginalSourceBase<?>> boolean  sourceNotLinkedToElement(ISourceable<T> sourcable, Reference reference, String microReference) {
1313
	        Set<T> linkedSources = sourcable.getSources();
1314
	        for (T is:linkedSources){
1315
	            Reference unitReference = is.getCitation();
1316
	            String unitMicroReference = is.getCitationMicroReference();
1323 1317

  
1324 1318
	            boolean refMatch=false;
1325 1319
	            boolean microMatch=false;
1326 1320

  
1327 1321
	            try{
1328
	                if (a==null && b==null) {
1322
	                if (unitReference==null && reference==null) {
1329 1323
	                    refMatch=true;
1330 1324
	                }
1331
	                if (a!=null && b!=null) {
1332
	                    if (a.getTitleCache().equalsIgnoreCase(b.getTitleCache())) {
1325
	                if (unitReference!=null && reference!=null) {
1326
	                    if (unitReference.getTitleCache().equalsIgnoreCase(reference.getTitleCache())) {
1333 1327
	                        refMatch=true;
1334 1328
	                    }
1335 1329
	                }
1336 1330
	            }catch(Exception e){}
1337 1331

  
1338

  
1339 1332
	            try{
1340
	                if (c==null && d==null) {
1333
	                if (unitMicroReference==null && microReference==null) {
1341 1334
	                    microMatch=true;
1342 1335
	                }
1343
	                if(c!=null && d!=null) {
1344
	                    if(c.equalsIgnoreCase(d)) {
1336
	                if(unitMicroReference!=null && microReference!=null) {
1337
	                    if(unitMicroReference.equalsIgnoreCase(microReference)) {
1345 1338
	                        microMatch=true;
1346 1339
	                    }
1347 1340
	                }
......
1351 1344
	            if (microMatch && refMatch) {
1352 1345
	                return false;
1353 1346
	            }
1354

  
1355

  
1356
	        }
1357
	        return true;
1358
	    }
1359

  
1360
	    /**
1361
	     * @param indAssociation
1362
	     * @param ref2
1363
	     * @param object
1364
	     * @return
1365
	     */
1366
	    private boolean sourceNotLinkedToElement(IndividualsAssociation indAssociation, Reference a, String d) {
1367
	        Set<DescriptionElementSource> linkedSources = indAssociation.getSources();
1368
	        for (DescriptionElementSource is:linkedSources){
1369
	            Reference b = is.getCitation();
1370
	            String c = is.getCitationMicroReference();
1371

  
1372
	            boolean refMatch=false;
1373
	            boolean microMatch=false;
1374

  
1375
	            try{
1376
	                if (a==null && b==null) {
1377
	                    refMatch=true;
1378
	                }
1379
	                if (a!=null && b!=null) {
1380
	                    if (a.getTitleCache().equalsIgnoreCase(b.getTitleCache())) {
1381
	                        refMatch=true;
1382
	                    }
1383
	                }
1384
	            }catch(Exception e){}
1385

  
1386

  
1387
	            try{
1388
	                if (c==null && d==null) {
1389
	                    microMatch=true;
1390
	                }
1391
	                if(c!=null && d!=null) {
1392
	                    if(c.equalsIgnoreCase(d)) {
1393
	                        microMatch=true;
1394
	                    }
1395
	                }
1396
	            }
1397
	            catch(Exception e){}
1398

  
1399
	            if (microMatch && refMatch) {
1400
	                return false;
1401
	            }
1402
	        }
1403
	        return true;
1404
	    }
1405

  
1406
	    /**
1407
	     * @param taxonDescription
1408
	     * @param ref2
1409
	     * @param object
1410
	     * @return
1411
	     */
1412
	    private boolean sourceNotLinkedToElement(TaxonDescription taxonDescription, Reference a, String d) {
1413
	        Set<IdentifiableSource> linkedSources = taxonDescription.getSources();
1414
	        for (IdentifiableSource is:linkedSources){
1415
	            Reference b = is.getCitation();
1416
	            String c = is.getCitationMicroReference();
1417

  
1418
	            boolean refMatch=false;
1419
	            boolean microMatch=false;
1420

  
1421
	            try{
1422
	                if (a==null && b==null) {
1423
	                    refMatch=true;
1424
	                }
1425
	                if (a!=null && b!=null) {
1426
	                    if (a.getTitleCache().equalsIgnoreCase(b.getTitleCache())) {
1427
	                        refMatch=true;
1428
	                    }
1429
	                }
1430
	            }catch(Exception e){}
1431

  
1432

  
1433
	            try{
1434
	                if (c==null && d==null) {
1435
	                    microMatch=true;
1436
	                }
1437
	                if(c!=null && d!=null) {
1438
	                    if(c.equalsIgnoreCase(d)) {
1439
	                        microMatch=true;
1440
	                    }
1441
	                }
1442
	            }
1443
	            catch(Exception e){}
1444

  
1445
	            if (microMatch && refMatch) {
1446
	                return false;
1447
	            }
1448
	        }
1449
	        return true;
1450
	    }
1451

  
1452
	    /**
1453
	     * @param indAssociation
1454
	     * @param source
1455
	     * @return
1456
	     */
1457
	    private boolean sourceNotLinkedToElement(IndividualsAssociation indAssociation, OriginalSourceBase<?> source) {
1458
	        Set<DescriptionElementSource> linkedSources = indAssociation.getSources();
1459
	        for (DescriptionElementSource is:linkedSources){
1460
	            Reference a = is.getCitation();
1461
	            Reference b = source.getCitation();
1462
	            String c = is.getCitationMicroReference();
1463
	            String d = source.getCitationMicroReference();
1464

  
1465
	            boolean refMatch=false;
1466
	            boolean microMatch=false;
1467

  
1468
	            try{
1469
	                if (a==null && b==null) {
1470
	                    refMatch=true;
1471
	                }
1472
	                if (a!=null && b!=null) {
1473
	                    if (a.getTitleCache().equalsIgnoreCase(b.getTitleCache())) {
1474
	                        refMatch=true;
1475
	                    }
1476
	                }
1477
	            }catch(Exception e){}
1478

  
1479

  
1480
	            try{
1481
	                if (c==null && d==null) {
1482
	                    microMatch=true;
1483
	                }
1484
	                if(c!=null && d!=null) {
1485
	                    if(c.equalsIgnoreCase(d)) {
1486
	                        microMatch=true;
1487
	                    }
1488
	                }
1489
	            }
1490
	            catch(Exception e){}
1491

  
1492
	            if (microMatch && refMatch) {
1493
	                return false;
1494
	            }
1495
	        }
1496
	        return true;
1497
	    }
1498

  
1499
	    /**
1500
	     * @param taxonDescription
1501
	     * @param sour
1502
	     * @return
1503
	     */
1504
	    private boolean sourceNotLinkedToElement(TaxonDescription taxonDescription, OriginalSourceBase<?> sour) {
1505
	        Set<IdentifiableSource> linkedSources = taxonDescription.getSources();
1506
	        for (IdentifiableSource is:linkedSources){
1507
	            Reference a = is.getCitation();
1508
	            Reference b = sour.getCitation();
1509
	            String c = is.getCitationMicroReference();
1510
	            String d = sour.getCitationMicroReference();
1511

  
1512
	            boolean refMatch=false;
1513
	            boolean microMatch=false;
1514

  
1515
	            try{
1516
	                if (a==null && b==null) {
1517
	                    refMatch=true;
1518
	                }
1519
	                if (a!=null && b!=null) {
1520
	                    if (a.getTitleCache().equalsIgnoreCase(b.getTitleCache())) {
1521
	                        refMatch=true;
1522
	                    }
1523
	                }
1524
	            }catch(Exception e){}
1525

  
1526

  
1527
	            try{
1528
	                if (c==null && d==null) {
1529
	                    microMatch=true;
1530
	                }
1531
	                if(c!=null && d!=null) {
1532
	                    if(c.equalsIgnoreCase(d)) {
1533
	                        microMatch=true;
1534
	                    }
1535
	                }
1536
	            }
1537
	            catch(Exception e){}
1538

  
1539
	            if (microMatch && refMatch) {
1540
	                return false;
1541
	            }
1542

  
1543

  
1544 1347
	        }
1545 1348
	        return true;
1546 1349
	    }
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/Abcd206Import.java
42 42
import eu.etaxonomy.cdm.model.common.CdmBase;
43 43
import eu.etaxonomy.cdm.model.common.DefinedTerm;
44 44
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
45
import eu.etaxonomy.cdm.model.common.ISourceable;
46 45
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
47 46
import eu.etaxonomy.cdm.model.common.Language;
48 47
import eu.etaxonomy.cdm.model.common.OriginalSourceBase;
......
831 830
        }
832 831
    }
833 832

  
834
<<<<<<< e12074844fd16df32275a14151d604461a15a064
835

  
836

  
837

  
838

  
839

  
840
=======
841
    /**
842
     * Look if the Institution does already exist
843
     * @param institutionCode: a string with the institutioncode
844
     * @param config : the configurator
845
     * @return the Institution (existing or new)
846
     */
847
    private Institution getInstitution(String institutionCode, Abcd206ImportState state) {
848
        Abcd206ImportConfigurator config = state.getConfig();
849
        Institution institution=null;
850
        List<Institution> institutions;
851
        try {
852
            institutions = getAgentService().list(Institution.class, null, null, null, null);
853
        } catch (Exception e) {
854
            institutions = new ArrayList<Institution>();
855
            logger.warn(e);
856
        }
857
        if (institutions.size() > 0 && config.isReUseExistingMetadata()) {
858
            for (Institution institut:institutions){
859
                try{
860
                    if (institut.getCode().equalsIgnoreCase(institutionCode)) {
861
                        institution=institut;
862
                    }
863
                }catch(Exception e){logger.warn("no institution code in the db");}
864
            }
865
        }
866
        if(DEBUG) {
867
            if(institution !=null) {
868
                logger.info("getinstitution " + institution.toString());
869
            }
870
        }
871
        if (institution == null){
872
            // create institution
873
            institution = Institution.NewInstance();
874
            institution.setCode(institutionCode);
875
            institution.setTitleCache(institutionCode, true);
876
        }
877
        save(institution, state);
878
        return institution;
879
    }
880

  
881
    /**
882
     * Look if the Collection does already exist
883
     * @param collectionCode
884
     * @param collectionCode: a string
885
     * @param config : the configurator
886
     * @return the Collection (existing or new)
887
     */
888
    private Collection getCollection(Institution institution, String collectionCode, Abcd206ImportState state) {
889
        Abcd206ImportConfigurator config = state.getConfig();
890
        Collection collection = null;
891
        List<Collection> collections;
892
        try {
893
            collections = getCollectionService().list(Collection.class, null, null, null, null);
894
        } catch (Exception e) {
895
            collections = new ArrayList<Collection>();
896
        }
897
        if (collections.size() > 0 && config.isReUseExistingMetadata()) {
898
            for (Collection coll:collections){
899
                if (coll.getCode() != null && coll.getInstitute() != null
900
                        && coll.getCode().equalsIgnoreCase(collectionCode) && coll.getInstitute().equals(institution)) {
901
                    collection = coll;
902
                    break;
903
                }
904
            }
905
        }
906

  
907
        if(collection == null){
908
            collection =Collection.NewInstance();
909
            collection.setCode(collectionCode);
910
            collection.setInstitute(institution);
911
            collection.setTitleCache(collectionCode);
912
        }
913
        save(collection, state);
914
        return collection;
915
    }
916

  
917

  
918
    /**
919
     * join DeterminationEvent to the Taxon Object
920
     * @param state : the ABCD import state
921
     * @param taxon: the current Taxon
922
     * @param preferredFlag :if the current name is preferred
923
     * @param derivedFacade : the derived Unit Facade
924
     */
925
    @SuppressWarnings("rawtypes")
926
    private void linkDeterminationEvent(Abcd206ImportState state, Taxon taxon, boolean preferredFlag,  DerivedUnitFacade derivedFacade) {
927
        Abcd206ImportConfigurator config = state.getConfig();
928
        if(DEBUG){
929
            logger.info("start linkdetermination with taxon:" + taxon.getUuid()+", "+taxon);
930
        }
931

  
932
        DeterminationEvent determinationEvent = DeterminationEvent.NewInstance();
933
        determinationEvent.setTaxonName(taxon.getName());
934
        determinationEvent.setPreferredFlag(preferredFlag);
935

  
936
        determinationEvent.setIdentifiedUnit(state.getDerivedUnitBase());
937
        state.getDerivedUnitBase().addDetermination(determinationEvent);
938

  
939
        if(DEBUG){
940
            logger.info("NB TYPES INFO: "+ state.getDataHolder().statusList.size());
941
        }
942
        for (SpecimenTypeDesignationStatus specimenTypeDesignationstatus : state.getDataHolder().statusList) {
943
            if (specimenTypeDesignationstatus != null) {
944
                if(DEBUG){
945
                    logger.info("specimenTypeDesignationstatus :"+ specimenTypeDesignationstatus);
946
                }
947

  
948
                ICdmApplicationConfiguration cdmAppController = config.getCdmAppController();
949
                if(cdmAppController == null){
950
                    cdmAppController = this;
951
                }
952
                specimenTypeDesignationstatus = (SpecimenTypeDesignationStatus) cdmAppController.getTermService().find(specimenTypeDesignationstatus.getUuid());
953
                //Designation
954
                TaxonNameBase<?,?> name = taxon.getName();
955
                SpecimenTypeDesignation designation = SpecimenTypeDesignation.NewInstance();
956

  
957
                designation.setTypeStatus(specimenTypeDesignationstatus);
958
                designation.setTypeSpecimen(state.getDerivedUnitBase());
959
                name.addTypeDesignation(designation, true);
960
            }
961
        }
962

  
963
        for (String[] fullReference : state.getDataHolder().referenceList) {
964

  
965

  
966
            String strReference=fullReference[0];
967
            String citationDetail = fullReference[1];
968
            String citationURL = fullReference[2];
969
            List<Reference> references = getReferenceService().listByTitle(Reference.class, "strReference", MatchMode.EXACT, null, null, null, null, null);
970

  
971
            if (!references.isEmpty()){
972
                Reference reference = null;
973
                for (Reference refe: references) {
974
                    if (refe.getTitleCache().equalsIgnoreCase(strReference)) {
975
                        reference =refe;
976
                        break;
977
                    }
978
                }
979
                if (reference ==null){
980
                    reference = ReferenceFactory.newGeneric();
981
                    reference.setTitleCache(strReference, true);
982
                    save(reference, state);
983
                }
984
                determinationEvent.addReference(reference);
985
            }
986
        }
987
        save(state.getDerivedUnitBase(), state);
988

  
989
        if (config.isAddIndividualsAssociationsSuchAsSpecimenAndObservations() && preferredFlag) {
990
            //do not add IndividualsAssociation to non-preferred taxa
991
            if(DEBUG){
992
                logger.info("isDoCreateIndividualsAssociations");
993
            }
994

  
995
            makeIndividualsAssociation(state, taxon, determinationEvent);
996

  
997
            save(state.getDerivedUnitBase(), state);
998
        }
999
    }
1000

  
1001
    /**
1002
     * create and link each association (specimen, observation..) to the accepted taxon
1003
     * @param state : the ABCD import state
1004
     * @param taxon: the current Taxon
1005
     * @param determinationEvent:the determinationevent
1006
     */
1007
    private void makeIndividualsAssociation(Abcd206ImportState state, Taxon taxon, DeterminationEvent determinationEvent) {
1008
        Abcd206ImportConfigurator config = state.getConfig();
1009
        SpecimenUserInteraction sui = config.getSpecimenUserInteraction();
1010

  
1011
        if (DEBUG) {
1012
            logger.info("MAKE INDIVIDUALS ASSOCIATION");
1013
        }
1014

  
1015
        TaxonDescription taxonDescription = null;
1016
        Set<TaxonDescription> descriptions= taxon.getDescriptions();
1017
        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
1018
            if(!state.isDescriptionGroupSet()){
1019
                taxonDescription = sui.askForDescriptionGroup(descriptions);
1020
                state.setDescriptionGroup(taxonDescription);
1021
                state.setDescriptionGroupSet(true);
1022
            }else{
1023
                taxonDescription=state.getDescriptionGroup();
1024
            }
1025
        } else {
1026
            for (TaxonDescription description : descriptions){
1027
                Set<IdentifiableSource> sources =  new HashSet<>();
1028
                sources.addAll(description.getTaxon().getSources());
1029
                sources.addAll(description.getSources());
1030
                for (IdentifiableSource source:sources){
1031
                    if(state.getRef().equals(source.getCitation())) {
1032
                        taxonDescription = description;
1033
                    }
1034
                }
1035
            }
1036
        }
1037
        if (taxonDescription == null){
1038
            taxonDescription = TaxonDescription.NewInstance(taxon, false);
1039
            if(sourceNotLinkedToElement(taxonDescription,state.getRef(),null)) {
1040
                taxonDescription.addSource(OriginalSourceType.Import, null, null, state.getRef(), null);
1041
            }
1042
            state.setDescriptionGroup(taxonDescription);
1043
            taxon.addDescription(taxonDescription);
1044
        }
1045

  
1046
        //PREPARE REFERENCE QUESTIONS
1047

  
1048
        Map<String,OriginalSourceBase<?>> sourceMap = new HashMap<String, OriginalSourceBase<?>>();
1049

  
1050
        List<IdentifiableSource> issTmp = new ArrayList<>();//getCommonService().list(IdentifiableSource.class, null, null, null, null);
1051
        List<DescriptionElementSource> issTmp2 = new ArrayList<>();//getCommonService().list(DescriptionElementSource.class, null, null, null, null);
1052

  
1053
        Set<OriginalSourceBase> osbSet = new HashSet<OriginalSourceBase>();
1054
        if(issTmp2!=null) {
1055
            osbSet.addAll(issTmp2);
1056
        }
1057
        if(issTmp!=null) {
1058
            osbSet.addAll(issTmp);
1059
        }
1060

  
1061

  
1062
        addToSourceMap(sourceMap, osbSet);
1063

  
1064
        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
1065
            List<OriginalSourceBase<?>> res = null;
1066
            if(!state.isDescriptionSourcesSet()){
1067
                res = sui.askForSource(sourceMap, "the description group ("+taxon+")",
1068
                        "The current reference is "+state.getRef().getTitleCache(),getReferenceService(), state.getDataHolder().docSources);
1069
                state.setDescriptionRefs(res);
1070
                state.setDescriptionSourcesSet(true);
1071
            }
1072
            else{
1073
                res=state.getDescriptionRefs();
1074
            }
1075
            if(res !=null) {
1076
                for (OriginalSourceBase<?> sour:res){
1077
                    if(sour.isInstanceOf(IdentifiableSource.class)){
1078
                        try {
1079
                            if(sourceNotLinkedToElement(taxonDescription,sour)) {
1080
                                taxonDescription.addSource((IdentifiableSource)sour.clone());
1081
                            }
1082
                        } catch (CloneNotSupportedException e) {
1083
                            logger.warn("no cloning?");
1084
                        }
1085
                    }else{
1086
                        if(sourceNotLinkedToElement(taxonDescription,sour)) {
1087
                            taxonDescription.addSource(OriginalSourceType.Import,null, null, sour.getCitation(),sour.getCitationMicroReference());
1088
                        }
1089
                    }
1090
                }
1091
            }
1092
        }
1093
        else {
1094
            if(sourceNotLinkedToElement(taxonDescription,state.getRef(),null)) {
1095
                taxonDescription.addSource(OriginalSourceType.Import,null, null, state.getRef(), null);
1096
            }
1097
        }
1098
        state.setDescriptionGroup(taxonDescription);
1099

  
1100
        IndividualsAssociation indAssociation = IndividualsAssociation.NewInstance();
1101
        Feature feature = makeFeature(state.getDerivedUnitBase());
1102
        indAssociation.setAssociatedSpecimenOrObservation(state.getDerivedUnitBase());
1103
        indAssociation.setFeature(feature);
1104

  
1105
        if (((Abcd206ImportConfigurator) state.getConfig()).isInteractWithUser()){
1106
            sourceMap = new HashMap<String, OriginalSourceBase<?>>();
1107

  
1108
            issTmp = getCommonService().list(IdentifiableSource.class, null, null, null, null);
1109
            issTmp2 = getCommonService().list(DescriptionElementSource.class, null, null, null, null);
1110

  
1111
            osbSet = new HashSet<OriginalSourceBase>();
1112
            if(issTmp2!=null) {
1113
                osbSet.addAll(issTmp2);
1114
            }
1115
            if(issTmp!=null) {
1116
                osbSet.addAll(issTmp);
1117
            }
1118

  
1119

  
1120
            addToSourceMap(sourceMap, osbSet);
1121

  
1122
            List<OriginalSourceBase<?>> sources =null;
1123
            if(!state.isAssociationSourcesSet()) {
1124
                sources = sui.askForSource(sourceMap,  "descriptive element (association) ",taxon.toString(),
1125
                        getReferenceService(),state.getDataHolder().docSources);
1126
                state.setAssociationRefs(sources);
1127
                state.setAssociationSourcesSet(true);
1128
            }
1129
            else{
1130
                sources=state.getAssociationRefs();
1131
            }
1132
            if(sources !=null) {
1133
                for (OriginalSourceBase<?> source: sources) {
1134
                    if(source !=null) {
1135
                        if(source.isInstanceOf(DescriptionElementSource.class)){
1136
                            try {
1137
                                if(sourceNotLinkedToElement(indAssociation,source)) {
1138
                                    indAssociation.addSource((DescriptionElementSource)source.clone());
1139
                                }
1140
                            } catch (CloneNotSupportedException e) {
1141
                                logger.warn("clone forbidden?");
1142
                            }
1143
                        }else{
1144
                            if(sourceNotLinkedToElement(indAssociation,source)) {
1145
                                indAssociation.addSource(OriginalSourceType.Import,null, null, source.getCitation(),source.getCitationMicroReference());
1146
                            }
1147
                            try {
1148
                                if(sourceNotLinkedToElement(state.getDerivedUnitBase(), source)) {
1149
                                    state.getDerivedUnitBase().addSource((IdentifiableSource) source.clone());
1150
                                }
1151
                            } catch (CloneNotSupportedException e) {
1152
                                // TODO Auto-generated catch block
1153
                                e.printStackTrace();
1154
                            }
1155
                        }
1156

  
1157
                    }
1158
                }
1159
            }
1160
        }else {
1161
            if(sourceNotLinkedToElement(indAssociation,state.getRef(),null)) {
1162
                indAssociation.addSource(OriginalSourceType.Import,null, null, state.getRef(), null);
1163
            }
1164
            if(sourceNotLinkedToElement(state.getDerivedUnitBase(), state.getRef(),null)) {
1165
                state.getDerivedUnitBase().addSource(OriginalSourceType.Import,null, null, state.getRef(), null);
1166
            }
1167
            for (Reference citation : determinationEvent.getReferences()) {
1168
                if(sourceNotLinkedToElement(indAssociation,citation,null))
1169
                {
1170
                    indAssociation.addSource(DescriptionElementSource.NewInstance(OriginalSourceType.Import, null, null, citation, null));
1171
                }
1172
                if(sourceNotLinkedToElement(state.getDerivedUnitBase(), state.getRef(),null)) {
1173
                    state.getDerivedUnitBase().addSource(OriginalSourceType.Import,null, null, state.getRef(), null);
1174
                }
1175
            }
1176
        }
1177

  
1178
        taxonDescription.addElement(indAssociation);
1179

  
1180
        save(taxonDescription, state);
1181
        save(taxon, state);
1182
        state.getReport().addDerivate(state.getDerivedUnitBase(), config);
1183
        state.getReport().addIndividualAssociation(taxon, state.getDataHolder().unitID, state.getDerivedUnitBase());
1184
    }
1185

  
1186
    private <T extends OriginalSourceBase<?>> boolean  sourceNotLinkedToElement(ISourceable<T> sourcable, Reference reference, String microReference) {
1187
        Set<T> linkedSources = sourcable.getSources();
1188
        for (T is:linkedSources){
1189
            Reference unitReference = is.getCitation();
1190
            String unitMicroReference = is.getCitationMicroReference();
1191

  
1192
            boolean refMatch=false;
1193
            boolean microMatch=false;
1194

  
1195
            try{
1196
                if (unitReference==null && reference==null) {
1197
                    refMatch=true;
1198
                }
1199
                if (unitReference!=null && reference!=null) {
1200
                    if (unitReference.getTitleCache().equalsIgnoreCase(reference.getTitleCache())) {
1201
                        refMatch=true;
1202
                    }
1203
                }
1204
            }catch(Exception e){}
1205

  
1206
            try{
1207
                if (unitMicroReference==null && microReference==null) {
1208
                    microMatch=true;
1209
                }
1210
                if(unitMicroReference!=null && microReference!=null) {
1211
                    if(unitMicroReference.equalsIgnoreCase(microReference)) {
1212
                        microMatch=true;
1213
                    }
1214
                }
1215
            }
1216
            catch(Exception e){}
1217

  
1218
            if (microMatch && refMatch) {
1219
                return false;
1220
            }
1221
        }
1222
        return true;
1223
    }
1224

  
1225
    private <T extends OriginalSourceBase<?>> boolean sourceNotLinkedToElement(ISourceable<T> sourcable, OriginalSourceBase<?> source) {
1226
        return sourceNotLinkedToElement(sourcable, source.getCitation(), source.getCitationMicroReference());
1227
    }
1228
>>>>>>> fix #6001 Clean up multiple sourceNotLinked() methods
1229

  
1230

  
1231

  
1232

  
1233

  
1234

  
1235

  
1236

  
1237

  
1238

  
1239

  
1240

  
1241

  
1242

  
1243

  
1244

  
1245

  
1246

  
1247

  
1248

  
1249

  
1250

  
1251

  
1252

  
1253

  
1254

  
1255

  
1256

  
1257

  
1258 833
    //    private void compareABCDtoCDM(URI urlFileName, List<String> knownElts, Abcd206XMLFieldGetter abcdFieldGetter) {
1259 834
    //        try {
1260 835
    //            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)