Project

General

Profile

« Previous | Next » 

Revision d221f578

Added by Patrick Plitzner about 6 years ago

ref #7095 Speed up specimen loading for working sets

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/WorkingSetService.java
16 16

  
17 17
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
18 18
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
19
import eu.etaxonomy.cdm.api.service.dto.SpecimenNodeWrapper;
19 20
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
20 21
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
21 22
import eu.etaxonomy.cdm.common.monitor.RemotingProgressMonitorThread;
......
100 101
            if(monitor.isCanceled()){
101 102
                return new ArrayList<>();
102 103
            }
103
            wrappers.add(createRowWrapper(null, description, workingSet));
104
            wrappers.add(createRowWrapper(null, description, null, workingSet));
104 105
            monitor.worked(1);
105 106
        }
106 107
	    return wrappers;
107 108
	}
108 109

  
109 110
    @Override
110
    public Collection<RowWrapperDTO> loadSpecimens(WorkingSet workingSet){
111
        List<RowWrapperDTO> specimenCache = new ArrayList<>();
111
    public Collection<SpecimenNodeWrapper> loadSpecimens(WorkingSet workingSet){
112

  
113
        List<SpecimenNodeWrapper> specimenCache = new ArrayList<>();
112 114
        //set filter parameters
113 115
        TaxonNodeFilter filter = TaxonNodeFilter.NewRankInstance(workingSet.getMinRank(), workingSet.getMaxRank());
114 116
        workingSet.getGeoFilter().forEach(area -> filter.orArea(area.getUuid()));
......
124 126
            if(taxon!=null){
125 127
                FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
126 128
                config.setAssociatedTaxonUuid(taxon.getUuid());
127
                List<SpecimenOrObservationBase> specimensForTaxon = occurrenceService.findByTitle(config).getRecords();
128
                specimensForTaxon.forEach(specimen -> specimenCache.add(createRowWrapper(specimen, null, workingSet)));
129
                List<UuidAndTitleCache<SpecimenOrObservationBase>> list = occurrenceService.findByTitleUuidAndTitleCache(config).getRecords();
130
                list.forEach(uuidAndTitleCache ->{
131
                    specimenCache.add(new SpecimenNodeWrapper(uuidAndTitleCache, taxonNode));
132
                });
129 133
            }
130 134
        }
131 135
        return specimenCache;
132 136
    }
133 137

  
134
	private RowWrapperDTO createRowWrapper(SpecimenOrObservationBase specimen, DescriptionBase description, WorkingSet workingSet){
138
    @Override
139
    public RowWrapperDTO createRowWrapper(DescriptionBase description, WorkingSet workingSet){
140
        return createRowWrapper(null, description, null, workingSet);
141
    }
142

  
143
    @Override
144
    public RowWrapperDTO createRowWrapper(SpecimenOrObservationBase specimen, WorkingSet workingSet){
145
        return createRowWrapper(specimen, null, null, workingSet);
146
    }
147

  
148
	private RowWrapperDTO createRowWrapper(SpecimenOrObservationBase specimen, DescriptionBase description, TaxonNode taxonNode, WorkingSet workingSet){
135 149
	    if(description!=null){
136 150
	        specimen = description.getDescribedSpecimenOrObservation();
137 151
	    }
138
        TaxonNode taxonNode = null;
139 152
        FieldUnit fieldUnit = null;
140 153
        String identifier = null;
141 154
        NamedArea country = null;
142 155
        //supplemental information
143 156
        if(specimen!=null){
144
            Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null,
145
                    Arrays.asList(new String[]{
146
                            "taxonNodes",
147
                            "taxonNodes.classification",
148
                            }));
149
            if(associatedTaxa!=null){
150
                //FIXME: what about multiple associated taxa
151
                Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter();
152
                if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
153
                    Taxon taxon = HibernateProxyHelper.deproxy(associatedTaxa.iterator().next(), Taxon.class);
154
                    taxonNode = taxon.getTaxonNode(taxonSubtreeFilter.iterator().next().getClassification());
157
            if(taxonNode==null){
158
                Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(specimen, null, null, null,
159
                        Arrays.asList(new String[]{
160
                                "taxonNodes",
161
                                "taxonNodes.classification",
162
                        }));
163
                if(associatedTaxa!=null){
164
                    //FIXME: what about multiple associated taxa
165
                    Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter();
166
                    if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
167
                        Taxon taxon = HibernateProxyHelper.deproxy(associatedTaxa.iterator().next(), Taxon.class);
168
                        taxonNode = taxon.getTaxonNode(taxonSubtreeFilter.iterator().next().getClassification());
169
                    }
155 170
                }
156 171
            }
157 172
            Collection<FieldUnit> fieldUnits = occurrenceService.getFieldUnits(specimen.getUuid(),

Also available in: Unified diff