Project

General

Profile

« Previous | Next » 

Revision e436a9ce

Added by Andreas Müller almost 3 years ago

ref #8297 improve out of scope handling for alphabetically ordered condensed distributions

View differences:

cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/geo/CondensedDistributionComposer.java
100 100

  
101 101
        //4. replace the area by the abbreviated representation and add symbols
102 102
        AreaNodeComparator areaNodeComparator = new AreaNodeComparator(config, languages);
103
        Collections.sort(topLevelNodes, areaNodeComparator);
103
        AreaNodeComparator topLevelAreaOfScopeComparator = config.orderType == OrderType.NATURAL ? areaNodeComparator : new AreaNodeComparator(config, languages, OrderType.NATURAL);
104

  
105
        Collections.sort(topLevelNodes, topLevelAreaOfScopeComparator);
104 106

  
105 107
        final boolean NOT_BOLED = false;
106 108
        final boolean NOT_HANDLED_BY_PARENT = false;
......
134 136

  
135 137
        //outOfScope areas  (areas outside the endemic area)
136 138
        if (!outOfScopeNodes.isEmpty()){
139
            Collections.sort(topLevelNodes, areaNodeComparator);
140

  
137 141
            result.addPostSeparatorTaggedText(config.outOfScopeAreasSeperator);
138 142
            List<AreaNode> outOfScopeList = new ArrayList<>(outOfScopeNodes);
139 143
            Collections.sort(outOfScopeList, areaNodeComparator);
......
424 428
    }
425 429

  
426 430
    private class AreaNodeComparator implements Comparator<AreaNode>{
427
        CondensedDistributionConfiguration config;
428
        List<Language> languages;
431
        private CondensedDistributionConfiguration config;
432
        private OrderType orderType;
433
        private List<Language> languages;
434

  
429 435
        private AreaNodeComparator(CondensedDistributionConfiguration config, List<Language> languages){
436
            this(config, languages, null);
437
        }
438

  
439
        private AreaNodeComparator(CondensedDistributionConfiguration config, List<Language> languages, OrderType divergentOrderType){
430 440
            this.config = config;
431 441
            this.languages = languages;
442
            this.orderType = divergentOrderType != null? divergentOrderType : config.orderType;
432 443
        }
433 444

  
434 445
        @Override
......
443 454
            }else if (area2 == null){
444 455
                return 1;
445 456
            }else{
446
                if (config.orderType == OrderType.NATURAL) {
457
                if (orderType == OrderType.NATURAL) {
447 458
                    //- due to wrong ordering behavior in DefinedTerms
448 459
                    return - area1.compareTo(area2);
449 460
                }else{
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/geo/CondensedDistributionComposerFloraCubaTest.java
18 18
import org.junit.Test;
19 19

  
20 20
import eu.etaxonomy.cdm.api.service.dto.CondensedDistribution;
21
import eu.etaxonomy.cdm.ext.geo.CondensedDistributionComposer.SymbolUsage;
21 22
import eu.etaxonomy.cdm.model.description.Distribution;
22 23
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
23 24
import eu.etaxonomy.cdm.model.location.NamedArea;
......
115 116
        config = CondensedDistributionConfiguration.NewCubaInstance();
116 117
    }
117 118

  
118

  
119 119
// ********************* TESTS ******************************/
120 120

  
121 121
    @Test
......
172 172
                condensedDistribution.toString());
173 173

  
174 174
        //TODO work in progress
175

  
176
        //test against default configuration (E+M) to see if the result looks reasonable
177
        //this should better be done CondensedDistributionComposerEuroMedTest but we have the test data here, therefore we keep the test here
178
        config = CondensedDistributionConfiguration.NewDefaultInstance();
179
        config.statusSymbolField = SymbolUsage.Symbol1;
180
        condensedDistribution = composer.createCondensedDistribution(filteredDistributions, null, config);
181
        Assert.assertEquals("Condensed string for Cuba differs",
182
                "n (c)CuE -dCuW(<b>Art Hab* IJ Mat May PR*</b>) [(c)CuE(-cGu nHo)]" + config.outOfScopeAreasSeperator + "<b>Bah</b> ?VM",
183
                condensedDistribution.toString());
184
        //Note: CuE is handled as both native and introduced as (c) is not yet defined as "introduced" status. Currently
185
        //      introduced status are hardcoded in PresenceAbsence term. This will probably change in future by becoming an own attribute like "isPresent"
175 186
    }
176 187

  
177 188
    private static boolean makeAreas(){

Also available in: Unified diff