Project

General

Profile

« Previous | Next » 

Revision 92a6aa38

Added by Andreas Kohlbecker almost 8 years ago

#4366 aggregation of distribution sources implemented for by area aggregation

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/description/TransmissionEngineDistribution.java
48 48
import eu.etaxonomy.cdm.model.common.MarkerType;
49 49
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
50 50
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
51
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
51 52
import eu.etaxonomy.cdm.model.description.Distribution;
52 53
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
53 54
import eu.etaxonomy.cdm.model.description.TaxonDescription;
......
232 233
    }
233 234

  
234 235
    /**
235
     * Compares the PresenceAbsenceTermBase terms <code>a</code> and <code>b</code> after
236
     * the priority as stored in the statusPriorityMap. The PresenceAbsenceTermBase with
237
     * the higher priority is returned. a well be returned if a == b,
238
     * If either a or b are null b or a is returned.
236
     * Compares the PresenceAbsenceTermBase terms contained in <code>a.status</code> and <code>b.status</code> after
237
     * the priority as stored in the statusPriorityMap. The StatusAndSources object with
238
     * the higher priority is returned. In the case of <code>a == b</code> the sources of b will be added to the sources
239
     * of a.
240
     *
241
     * If either a or b or the status are null b or a is returned.
239 242
     *
240 243
     * @see initializeStatusPriorityMap()
241 244
     *
......
243 246
     * @param b
244 247
     * @return
245 248
     */
246
    private PresenceAbsenceTerm choosePreferred(PresenceAbsenceTerm a, PresenceAbsenceTerm b){
249
    private StatusAndSources choosePreferred(StatusAndSources a, StatusAndSources b){
247 250

  
248 251
        if (statusPriorityMap == null) {
249 252
            initializeStatusPriorityMap();
250 253
        }
251 254

  
252
        if (b == null) {
255
        if (b == null || b.status == null) {
253 256
            return a;
254 257
        }
255
        if (a == null) {
258
        if (a == null || a.status == null) {
256 259
            return b;
257 260
        }
258 261

  
259
        if (statusPriorityMap.get(a) == null) {
260
            logger.warn("No priority found in map for " + a.getLabel());
262
        if (statusPriorityMap.get(a.status) == null) {
263
            logger.warn("No priority found in map for " + a.status.getLabel());
261 264
            return b;
262 265
        }
263
        if (statusPriorityMap.get(b) == null) {
264
            logger.warn("No priority found in map for " + b.getLabel());
266
        if (statusPriorityMap.get(b.status) == null) {
267
            logger.warn("No priority found in map for " + b.status.getLabel());
265 268
            return a;
266 269
        }
267
        if(statusPriorityMap.get(a) < statusPriorityMap.get(b)){
270
        if(statusPriorityMap.get(a.status) < statusPriorityMap.get(b.status)){
268 271
            return b;
272
        } else if (statusPriorityMap.get(a.status) == statusPriorityMap.get(b.status)){
273
            a.sources.addAll(b.sources);
274
            return a;
269 275
        } else {
270 276
            return a;
271 277
        }
......
456 462
                for (NamedArea superArea : superAreaList){
457 463

  
458 464
                    // accumulate all sub area status
459
                    PresenceAbsenceTerm accumulatedStatus = null;
465
                    StatusAndSources accumulatedStatusAndSources = null;
460 466
                    // TODO consider using the TermHierarchyLookup (only in local branch a.kohlbecker)
461 467
                    Set<NamedArea> subAreas = getSubAreasFor(superArea);
462 468
                    for(NamedArea subArea : subAreas){
......
474 480
                                if (getByAreaIgnoreStatusList().contains(status)){
475 481
                                    continue;
476 482
                                }
477
                                accumulatedStatus = choosePreferred(accumulatedStatus, status);
483
                                StatusAndSources subStatusAndSources = new StatusAndSources(status, distribution.getSources());
484
                                accumulatedStatusAndSources = choosePreferred(accumulatedStatusAndSources, subStatusAndSources);
478 485
                            }
479 486
                        }
480 487
                    } // next sub area
481
                    if (accumulatedStatus != null) {
488
                    if (accumulatedStatusAndSources != null) {
482 489
                        if(logger.isDebugEnabled()){
483
                            logger.debug("accumulateByArea() - \t >> " + termToString(superArea) + ": " + termToString(accumulatedStatus));
490
                            logger.debug("accumulateByArea() - \t >> " + termToString(superArea) + ": " + termToString(accumulatedStatusAndSources.status));
484 491
                        }
485 492
                        // store new distribution element for superArea in taxon description
486
                        Distribution newDistribitionElement = Distribution.NewInstance(superArea, accumulatedStatus);
493
                        Distribution newDistribitionElement = Distribution.NewInstance(superArea, accumulatedStatusAndSources.status);
487 494
                        newDistribitionElement.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
488 495
                        description.addElement(newDistribitionElement);
489 496
                    }
......
595 602
                    }
596 603

  
597 604
                    // Step through direct taxonomic children for accumulation
598
                    Map<NamedArea, PresenceAbsenceTerm> accumulatedStatusMap = new HashMap<NamedArea, PresenceAbsenceTerm>();
605
                    Map<NamedArea, StatusAndSources> accumulatedStatusMap = new HashMap<NamedArea, StatusAndSources>();
599 606

  
600 607
                    Set<Integer> childTaxonIds = classificationLookupDao.getChildTaxonMap().get(taxon.getId());
601 608
                    if(childTaxonIds != null && !childTaxonIds.isEmpty()) {
......
615 622
                                if (status == null || getByRankIgnoreStatusList().contains(status)){
616 623
                                  continue;
617 624
                                }
618
                                accumulatedStatusMap.put(area, choosePreferred(accumulatedStatusMap.get(area), status));
625

  
626
                                StatusAndSources subStatusAndSources = new StatusAndSources(status, distribution.getSources());
627
                                accumulatedStatusMap.put(area, choosePreferred(accumulatedStatusMap.get(area), subStatusAndSources));
619 628
                             }
620 629
                        }
621 630

  
......
623 632
                            TaxonDescription description = findComputedDescription(taxon, doClearDescriptions);
624 633
                            for (NamedArea area : accumulatedStatusMap.keySet()) {
625 634
                                // store new distribution element in new Description
626
                                Distribution newDistribitionElement = Distribution.NewInstance(area, accumulatedStatusMap.get(area));
635
                                Distribution newDistribitionElement = Distribution.NewInstance(area, accumulatedStatusMap.get(area).status);
627 636
                                newDistribitionElement.addMarker(Marker.NewInstance(MarkerType.COMPUTED(), true));
628 637
                                description.addElement(newDistribitionElement);
629 638
                            }
......
924 933
        byAreasAndRanks
925 934

  
926 935
    }
936

  
937
    private class StatusAndSources {
938

  
939
        PresenceAbsenceTerm status;
940

  
941
        Set<DescriptionElementSource> sources = new HashSet<>();
942

  
943
        public StatusAndSources(PresenceAbsenceTerm status, Set<DescriptionElementSource> sources) {
944
            this.status = status;
945
            this.sources = sources;
946
        }
947
    }
927 948
}

Also available in: Unified diff