Project

General

Profile

« Previous | Next » 

Revision d19ffefd

Added by Patrick Plitzner over 4 years ago

ref #8539 Performance and session handling fixes

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrixBottomToolbar.java
12 12
import java.util.Collection;
13 13
import java.util.List;
14 14
import java.util.Map;
15
import java.util.Optional;
16 15
import java.util.UUID;
17 16

  
18 17
import org.eclipse.core.runtime.ICoreRunnable;
......
34 33

  
35 34
import eu.etaxonomy.cdm.api.application.CdmApplicationState;
36 35
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService;
37
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
38 36
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
39
import eu.etaxonomy.cdm.api.service.ITaxonService;
40 37
import eu.etaxonomy.cdm.api.service.UpdateResult;
41 38
import eu.etaxonomy.cdm.api.service.config.DescriptionAggregationConfiguration;
42 39
import eu.etaxonomy.cdm.api.service.config.IdentifiableServiceConfiguratorImpl;
......
45 42
import eu.etaxonomy.cdm.common.CdmUtils;
46 43
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
47 44
import eu.etaxonomy.cdm.model.description.CategoricalData;
48
import eu.etaxonomy.cdm.model.description.DescriptionType;
49 45
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
50 46
import eu.etaxonomy.cdm.model.description.Feature;
51
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
52 47
import eu.etaxonomy.cdm.model.description.PolytomousKey;
53 48
import eu.etaxonomy.cdm.model.description.QuantitativeData;
54
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
55
import eu.etaxonomy.cdm.model.description.TaxonDescription;
56
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
57
import eu.etaxonomy.cdm.model.taxon.Taxon;
58 49
import eu.etaxonomy.cdm.persistence.dto.SpecimenNodeWrapper;
59 50
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGenerator;
60 51
import eu.etaxonomy.cdm.strategy.generate.PolytomousKeyGeneratorConfigurator;
......
99 90
                if(StoreUtil.promptCheckIsDirty(matrix.getPart())){
100 91
                    return;
101 92
                }
102
                String error = ""; //$NON-NLS-1$
103 93
                SpecimenSelectionDialog dialog = new SpecimenSelectionDialog(matrix.getShell(), matrix);
104 94
                if(dialog.open()==Window.OK){
105 95
                    Collection<SpecimenNodeWrapper> wrappers = dialog.getSpecimen();
106
                    if(wrappers.stream().anyMatch(wrapper->wrapper.getTaxonDescription()==null)
96
                    if(wrappers.stream().anyMatch(wrapper->wrapper.getTaxonDescriptionUuid()==null)
107 97
                            && !MessagingUtils.confirmDialog(
108 98
                                    "Create Taxon Association",
109 99
                                    "Some specimens are not linked with taxon via IndividualsAssociation yet.\n"
110 100
                                    + "Do you want to create this association?")){
111 101
                        return;
112 102
                    }
103
                    String error = ""; //$NON-NLS-1$
113 104
                    for (SpecimenNodeWrapper wrapper : wrappers) {
114
                        TaxonDescription taxonDescription = wrapper.getTaxonDescription();
115
                        if(taxonDescription==null){
116
                            Optional<TaxonDescription> associationDescriptionOptional = wrapper.getTaxonNode().getTaxon().getDescriptions().stream()
117
                            .filter(desc->desc.getTypes().contains(DescriptionType.INDIVIDUALS_ASSOCIATION))
118
                            .findFirst();
119
                            Taxon taxon = wrapper.getTaxonNode().getTaxon();
120
                            if(!associationDescriptionOptional.isPresent()){
121
                                taxonDescription = TaxonDescription.NewInstance(taxon);
122
                            }
123
                            else{
124
                                taxonDescription = associationDescriptionOptional.get();
125
                            }
126

  
127
                            SpecimenOrObservationBase specimen = CdmStore.getService(IOccurrenceService.class).load(wrapper.getUuidAndTitleCache().getUuid());
128
                            IndividualsAssociation association = IndividualsAssociation.NewInstance(specimen);
129
                            taxonDescription.addElement(association);
130
                            CdmStore.getService(ITaxonService.class).saveOrUpdate(wrapper.getTaxonNode().getTaxon());
131
                        }
132
                        SpecimenDescription specimenDescription = CdmStore.getService(IDescriptiveDataSetService.class)
133
                                .findSpecimenDescription(matrix.getDescriptiveDataSet().getUuid(),
134
                                        wrapper.getUuidAndTitleCache().getUuid(), true);
135 105
                        SpecimenRowWrapperDTO rowWrapper = CdmStore.getService(IDescriptiveDataSetService.class)
136
                                .createSpecimenRowWrapper(specimenDescription, matrix.getDescriptiveDataSet());
106
                                .addRowWrapperToDataset(wrapper, matrix.getDescriptiveDataSet().getUuid());
137 107
                        if(rowWrapper==null){
138
                            error += specimenDescription+"\n";
108
                            error += wrapper.getUuidAndTitleCache().getTitleCache();
109
                            error += "\n";
139 110
                            continue;
140 111
                        }
112

  
141 113
                        //add wrapper to matrix
142 114
                        matrix.getDescriptions().add(rowWrapper);
143
                        //add specimen description to data set
144
                        matrix.getDescriptiveDataSet().addDescription(specimenDescription);
145
                        //add taxon description with IndividualsAssociation to the specimen to data set
146
                        matrix.getDescriptiveDataSet().addDescription(taxonDescription);
147
                        matrix.getCdmEntitiySession().load(specimenDescription, true);
148
                        matrix.getCdmEntitiySession().load(taxonDescription, true);
115
//                        matrix.getCdmEntitiySession().load(specimenDescription, true);
116
//                        matrix.getCdmEntitiySession().load(taxonDescription, true);
149 117

  
150 118
                        matrix.setDirty();
151 119
                        matrix.getSpecimenCache().remove(wrapper);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/SpecimenSelectionDialog.java
247 247
        @Override
248 248
        public String getToolTipText(Object element) {
249 249
            if(element instanceof SpecimenNodeWrapper
250
                    && ((SpecimenNodeWrapper) element).getTaxonDescription()==null){
250
                    && ((SpecimenNodeWrapper) element).getTaxonDescriptionUuid()==null){
251 251
                return "Does not have and IndividualsAssociation with the taxon";
252 252
            }
253 253
            return null;
......
256 256
        @Override
257 257
        public Image getColumnImage(Object element, int columnIndex) {
258 258
            if(element instanceof SpecimenNodeWrapper && columnIndex == 2
259
                    && ((SpecimenNodeWrapper) element).getTaxonDescription()==null){
259
                    && ((SpecimenNodeWrapper) element).getTaxonDescriptionUuid()==null){
260 260
                return ImageResources.getImage(ImageResources.WARNING_ICON);
261 261
            }
262 262
            return null;

Also available in: Unified diff