Project

General

Profile

Revision 577e8a82

ID577e8a823f4bf4f659feb2045e47b69e1feaa579
Parent 1844c796
Child 84881b9c

Added by Patrick Plitzner over 2 years ago

ref #7095 Speed up specimen loading for working sets

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
20 20
import java.util.Properties;
21 21
import java.util.Set;
22 22
import java.util.UUID;
23
import java.util.stream.Collectors;
24 23

  
25 24
import org.apache.commons.collections4.map.LinkedMap;
26 25
import org.eclipse.core.runtime.ICoreRunnable;
......
122 121
import ca.odell.glazedlists.TreeList;
123 122
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
124 123
import eu.etaxonomy.cdm.api.service.IDescriptionService;
124
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
125 125
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
126 126
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
127 127
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
128
import eu.etaxonomy.cdm.api.service.dto.SpecimenNodeWrapper;
128 129
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
129 130
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
130 131
import eu.etaxonomy.cdm.model.description.Feature;
......
134 135
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
135 136
import eu.etaxonomy.cdm.model.description.State;
136 137
import eu.etaxonomy.cdm.model.description.WorkingSet;
138
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
137 139
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
138 140
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataCellEditor;
139 141
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.categorical.CategoricalDataDisplayConverter;
......
178 180

  
179 181
    private EventList<Object> descriptions;
180 182

  
181
    private List<RowWrapperDTO> specimenCache = null;
183
    private Collection<SpecimenNodeWrapper> specimenCache = null;
182 184

  
183 185
    private ListDataProvider<Object> bodyDataProvider;
184 186

  
......
398 400
            public void widgetSelected(SelectionEvent e) {
399 401
                SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(natTable.getShell(), CharacterMatrix.this);
400 402
                if(dialog.open()==Window.OK){
401
                    Collection<RowWrapperDTO> wrappers = dialog.getSpecimen();
402
                    for (RowWrapperDTO wrapper : wrappers) {
403
                        SpecimenDescription description = getDescriptionForWorkingSet(wrapper);
403
                    Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
404
                    for (SpecimenNodeWrapper wrapper : wrappers) {
405
                        SpecimenOrObservationBase specimen = CdmStore.getService(IOccurrenceService.class).load(wrapper.getUuidAndTitleCache().getUuid());
406
                        SpecimenDescription description = getDescriptionForWorkingSet(specimen);
404 407
                        //description elements
405 408
                        Map<Feature, DescriptionElementBase> featureToElementMap = new HashMap<>();
406 409
                        Set<DescriptionElementBase> elements = description.getElements();
......
408 411
                            Feature feature = descriptionElementBase.getFeature();
409 412
                            featureToElementMap.put(feature, descriptionElementBase);
410 413
                        }
411
                        wrapper.setDescription(description);
412
                        CharacterMatrix.this.descriptions.add(wrapper);
414
                        RowWrapperDTO rowWrapper = CdmStore.getService(IWorkingSetService.class).createRowWrapper(description, workingSet);
415
                        CharacterMatrix.this.descriptions.add(rowWrapper);
413 416
                        workingSet.addDescription(description);
414 417
                        setDirty();
415 418
                    }
......
869 872
        }
870 873
    }
871 874

  
872
    private SpecimenDescription getDescriptionForWorkingSet(RowWrapperDTO wrapper){
875
    private SpecimenDescription getDescriptionForWorkingSet(SpecimenOrObservationBase specimen){
873 876
        Set<Feature> wsFeatures = workingSet.getDescriptiveSystem().getDistinctFeatures();
874 877
        List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
875 878

  
876
        for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) wrapper.getSpecimen().getDescriptions()) {
879
        for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
877 880
            specimenDescription = (SpecimenDescription) CdmStore.getService(IDescriptionService.class).load(specimenDescription.getUuid());
878 881
            Set<Feature> specimenDescriptionFeatures = new HashSet<>();
879 882
            //gather specimen description features and check for match with WS features
......
891 894
        }
892 895
        //Create new specimen description if no match was found
893 896
        setDirty();
894
        SpecimenDescription newDesription = SpecimenDescription.NewInstance(wrapper.getSpecimen());
897
        SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
895 898
        newDesription.setTitleCache(Messages.CharacterMatrix_WORKING_SET+workingSet.getLabel()+": "+newDesription.generateTitle(), true); //$NON-NLS-2$
896 899

  
897 900
        //check for equals description element (same feature and same values)
......
1060 1063
        return workingSet;
1061 1064
    }
1062 1065

  
1063
    public List<RowWrapperDTO> getSpecimenCache() {
1066
    public Collection<SpecimenNodeWrapper> getSpecimenCache() {
1064 1067
        return specimenCache;
1065 1068
    }
1066 1069

  
1067
    public void setSpecimenCache(Collection<RowWrapperDTO> specimenCache) {
1068
        this.specimenCache =
1069
                specimenCache.stream().filter(wrapper ->
1070
        wrapper.getSpecimen().getDescriptions().stream().noneMatch(description ->
1071
        workingSet.getDescriptions().contains(description)))
1072
        .collect(Collectors.toList());
1070
    public void setSpecimenCache(Collection<SpecimenNodeWrapper> specimenCache) {
1071
        //TODO: filter out already added descriptions
1072
        this.specimenCache = specimenCache;
1073
//                specimenCache.stream().filter(wrapper ->
1074
//        wrapper.getSpecimen().getDescriptions().stream().noneMatch(description ->
1075
//        workingSet.getDescriptions().contains(description)))
1076
//        .collect(Collectors.toList());
1073 1077
    }
1074 1078

  
1075 1079
    public Properties getNatTableState() {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/SpecimenSelectionDialog.java
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.Arrays;
13 12
import java.util.Collection;
14
import java.util.List;
15 13
import java.util.stream.Collectors;
16 14
import java.util.stream.Stream;
17 15

  
......
40 38
import org.eclipse.swt.widgets.Text;
41 39

  
42 40
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
43
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
41
import eu.etaxonomy.cdm.api.service.dto.SpecimenNodeWrapper;
44 42
import eu.etaxonomy.cdm.common.CdmUtils;
45 43
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
46 44
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
58 56
 */
59 57
public class SpecimenSelectionDialog extends Dialog {
60 58

  
61
    private static final List<String> NODE_PROPERTY_PATH = Arrays.asList(new String[] {
62
            "taxon",
63
            "taxon.name",
64
    });
65

  
66 59
    private static String TEXT_FILTER_DEFAULT = "Enter text filter";
67 60

  
68 61
    private TableViewer list;
69 62

  
70
    private Collection<RowWrapperDTO> selectedSpecimens = new ArrayList<>();
63
    private Collection<SpecimenNodeWrapper> selectedSpecimens = new ArrayList<>();
71 64
    private CharacterMatrix matrix;
72 65
    private Text txtTextFilter;
73 66

  
......
161 154
    }
162 155

  
163 156
    private void applyFilter(){
164
        Stream<RowWrapperDTO> filteredWrappers =matrix.getSpecimenCache().stream();
157
        Stream<SpecimenNodeWrapper> filteredWrappers = matrix.getSpecimenCache().stream();
165 158
        if(comboTaxon.getSelection()!=null){
166 159
            filteredWrappers =
167 160
                    filteredWrappers
......
171 164
                &&!CdmUtils.isBlank(txtTextFilter.getText())){
172 165
            filteredWrappers =
173 166
                    filteredWrappers
174
                    .filter(wrapper->wrapper.getSpecimen().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()));
167
                    .filter(wrapper->wrapper.getUuidAndTitleCache().getTitleCache().toLowerCase().contains(txtTextFilter.getText().toLowerCase()));
175 168
        }
176 169
        list.setInput(filteredWrappers.collect(Collectors.toList()));
177 170
    }
178 171

  
179 172
    private void loadSpecimens(){
180
        Collection<RowWrapperDTO> specimenCache = CdmStore.getService(IWorkingSetService.class).loadSpecimens(matrix.getWorkingSet());
173
        Collection<SpecimenNodeWrapper> specimenCache = CdmStore.getService(IWorkingSetService.class).loadSpecimens(matrix.getWorkingSet());
181 174
        matrix.setSpecimenCache(specimenCache);
182 175
    }
183 176

  
......
200 193
        return true;
201 194
    }
202 195

  
203
    public Collection<RowWrapperDTO> getSpecimen(){
196
    public Collection<SpecimenNodeWrapper> getSpecimen(){
204 197
        return selectedSpecimens;
205 198
    }
206 199

  
......
213 206

  
214 207
        @Override
215 208
        public String getColumnText(Object element, int columnIndex) {
216
            if(element instanceof RowWrapperDTO){
217
                RowWrapperDTO wrapper = (RowWrapperDTO)element;
209
            if(element instanceof SpecimenNodeWrapper){
210
                SpecimenNodeWrapper wrapper = (SpecimenNodeWrapper)element;
218 211
                switch (columnIndex) {
219 212
                case 0:
220 213
                    return wrapper.getTaxonNode().getTaxon().getName().getTitleCache();
221 214
                case 1:
222
                    return wrapper.getSpecimen().getTitleCache();
215
                    return wrapper.getUuidAndTitleCache().getTitleCache();
223 216
                default:
224 217
                    break;
225 218
                }

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)