Project

General

Profile

« Previous | Next » 

Revision e976ec34

Added by Andreas Kohlbecker about 10 years ago

corecting documentation, removing obsolete rule and adapting test accordingly - #3904 (EuroMed: Implement filtering rules for Distributions)

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/utility/DescriptionUtility.java
46 46
     * MarkerType.COMPUTED()}). This means if a entered or imported status
47 47
     * information exist for the same area for which computed data is available,
48 48
     * the computed data has to be given preference over other data.</li>
49
     * <li>In computed distributions, distributions in parent areas are
50
     * preferred over those for <i>direct sub areas</i> if they have the same
49
     * <li>NOTE: This rule is now replaced by the <i>Sub area preference rule</i>: In computed distributions, distributions in sub areas are
50
     * preferred over those for <i>parent areas</i> if they have the same
51 51
     * status</li>
52 52
     * <li><b>Status order preference rule</b>: In case of multiple distribution
53 53
     * status ({@link PresenceAbsenceTermBase}) for the same area the status
......
138 138
                otherDistributions.remove(keyComputed);
139 139
            }
140 140

  
141
            // 2.b) in computed distributions prefer parent areas over sub areas if they have the same status
142
            for(Distribution distribution : valuesOfAllInnerSets(computedDistributions.values())){
143
                if(distribution.getArea() != null){
144
                    NamedArea parentArea = distribution.getArea().getPartOf();
145
                    while(parentArea != null){
146
                        // get all distributions for the parent area
147
                        Set<Distribution> parentAreaDistributions = computedDistributions.get(parentArea);
148
                        if(parentAreaDistributions != null){
149
                            // check all computed distributions of the parent area
150
                            for(Distribution parentDistribution : parentAreaDistributions) {
151
                                if(parentDistribution != null && parentDistribution.getStatus().equals(distribution.getStatus())){
152
                                    removeCandidatesDistribution.add(parentDistribution);
153
                                }
154
                            }
155
                        }
156
                        parentArea = parentArea.getPartOf();
157
                    }
158
                }
159
            }
141
/* TODO remove the lines below
142
 * this filtering rule has now be implemented as subAreaPreference rule and does not need to be implemented twice
143
 * TODO also remove second rule from method documentation
144
 */
145
//            // 2.b) in computed distributions prefer parent areas over sub areas if they have the same status
146
//            for(Distribution distribution : valuesOfAllInnerSets(computedDistributions.values())){
147
//                if(distribution.getArea() != null){
148
//                    NamedArea parentArea = distribution.getArea().getPartOf();
149
//                    while(parentArea != null){
150
//                        // get all distributions for the parent area
151
//                        Set<Distribution> parentAreaDistributions = computedDistributions.get(parentArea);
152
//                        if(parentAreaDistributions != null){
153
//                            // check all computed distributions of the parent area
154
//                            for(Distribution parentDistribution : parentAreaDistributions) {
155
//                                if(parentDistribution != null && parentDistribution.getStatus().equals(distribution.getStatus())){
156
//                                    removeCandidatesDistribution.add(parentDistribution);
157
//                                }
158
//                            }
159
//                        }
160
//                        parentArea = parentArea.getPartOf();
161
//                    }
162
//                }
163
//            }
160 164
        }
161 165

  
162 166
        filteredDistributions = new HashMap<NamedArea, Set<Distribution>>(otherDistributions.size() + computedDistributions.size());
cdmlib-services/src/test/java/eu/etaxonomy/cdm/api/utility/DescriptionUtilityTest.java
115 115

  
116 116
        /*
117 117
         * Sub area preference rule: If there is an area with a direct sub area
118
         * and both areas have the same computed status only the information on
118
         * and both areas have the same status only the information on
119 119
         * the sub area should be reported, whereas the super area should be
120 120
         * ignored.
121 121
         */
......
128 128
        Assert.assertEquals(1, filteredDistributions.size());
129 129
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
130 130

  
131
        /*
132
         * NOTE: this rule only applies only to non computed areas, since the
133
         * second rule is applied first!.
134
         */
135

  
136 131
        // 1. Mixed situation
137 132
        distGermany.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
138 133
        filteredDistributions = DescriptionUtility.filterDistributions(distributions, subAreaPreference, statusOrderPreference, hideMarkedAreas);
139 134
        Assert.assertEquals(1, filteredDistributions.size());
140
        Assert.assertEquals("TODO even if distGermany is computed it will not be preferred, is this correct?", berlin, filteredDistributions.iterator().next().getArea());
135
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
141 136

  
142 137
        // all computed => subAreaPreference should have no effect?
143 138
        distBerlin.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
144 139
        filteredDistributions = DescriptionUtility.filterDistributions(distributions, subAreaPreference, statusOrderPreference, hideMarkedAreas);
145 140
        Assert.assertEquals(1, filteredDistributions.size());
146
        Assert.assertEquals(Country.GERMANY(), filteredDistributions.iterator().next().getArea());
141
        Assert.assertEquals(berlin, filteredDistributions.iterator().next().getArea());
147 142
    }
148 143

  
149 144
    @Test

Also available in: Unified diff