Project

General

Profile

« Previous | Next » 

Revision 582a319d

Added by Patrick Plitzner over 4 years ago

ref #7095 use TaxonNodeFilter for specimen selection dialog

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
13 13
import java.util.HashSet;
14 14
import java.util.List;
15 15
import java.util.Set;
16
import java.util.UUID;
16 17

  
17 18
import org.eclipse.jface.dialogs.Dialog;
18 19
import org.eclipse.jface.viewers.ArrayContentProvider;
......
25 26
import org.eclipse.swt.widgets.Shell;
26 27

  
27 28
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28
import eu.etaxonomy.cdm.api.service.ITaxonService;
29
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
29
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
30
import eu.etaxonomy.cdm.filter.TaxonNodeFilter;
30 31
import eu.etaxonomy.cdm.model.description.WorkingSet;
31
import eu.etaxonomy.cdm.model.name.Rank;
32
import eu.etaxonomy.cdm.model.name.TaxonName;
33 32
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
34 33
import eu.etaxonomy.cdm.model.taxon.Taxon;
35 34
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
......
64 63
        //gather descriptions
65 64
        Set<TaxonNode> taxonNodes = workingSet.getTaxonSubtreeFilter();
66 65
        Set<SpecimenOrObservationBase> specimens = new HashSet<>();
67
        for (TaxonNode node : taxonNodes) {
68
            specimens.addAll(addSpecimensRecursively(node));
69
        }
70
        list.setInput(specimens);
71
        return composite;
72
    }
73 66

  
74
    private Collection<SpecimenOrObservationBase> addSpecimensRecursively(TaxonNode node){
75
        Collection<SpecimenOrObservationBase> specimens = new HashSet<>();
76
        if(node.getTaxon()!=null){
77
            Taxon taxon = HibernateProxyHelper.deproxy(node.getTaxon(), Taxon.class);
78
            TaxonName name = taxon.getName();
79
            //filter by Rank
80
            if(name!=null &&
81
                    (name.getRank().equals(workingSet.getMinRank())
82
                    || name.getRank().isHigher(workingSet.getMinRank())
83
                    || name.getRank().equals(workingSet.getMaxRank())
84
                    || name.getRank().isLower(workingSet.getMaxRank()))){
85
                IOccurrenceService service = CdmStore.getService(IOccurrenceService.class);
86
                //TODO extend FindOccurrencesConfigurator to support area and rank filter
87
                //            FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
88
                //            config.setAssociatedTaxonNameUuid(taxon.getUuid());
89
                //            service.findByTitle(config);
90

  
91
                specimens = service.listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null);
67
        //set filter parameters
68
        TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(workingSet.getMinRank(), workingSet.getMaxRank());
69
        workingSet.getGeoFilter().forEach(area -> filter.andArea(area.getUuid()));
70
        workingSet.getTaxonSubtreeFilter().forEach(node -> filter.andTaxonNode(node));
71

  
72
        ITaxonNodeService taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
73
        List<UUID> filteredNodes = taxonNodeService.uuidList(filter);
74
        for (UUID uuid : filteredNodes) {
75
            //TODO implement occurrence service for taxon nodes
76
            // let it return UUIDAndTitlechace
77
            Taxon taxon = taxonNodeService.load(uuid).getTaxon();
78
            if(taxon!=null){
79
                specimens.addAll(CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, taxon, null, null, null, null, null));
92 80
            }
93 81
        }
94
        List<TaxonNode> childNodes = node.getChildNodes();
95
        for (TaxonNode childNode : childNodes) {
96
            specimens.addAll(addSpecimensRecursively(childNode));
97
        }
98
        return specimens;
82

  
83
        list.setInput(specimens);
84
        return composite;
99 85
    }
100 86

  
101 87
    /**

Also available in: Unified diff