Project

General

Profile

Revision 5c025bd1

ID5c025bd1e0c7679eb65a68fc75c8a32a026580ab
Parent 6ff2e71e
Child e7df9bb1

Added by Patrick Plitzner almost 4 years ago

ref #7196 Check existing data value-wise

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
1 1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
2
 * Copyright (C) 2017 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9 9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10 10

  
11 11
import java.io.File;
......
140 140
 *
141 141
 */
142 142
public class CharacterMatrix implements IE4SavablePart, IPartContentHasDetails, IConversationEnabled, IDirtyMarkable,
143
        ICdmEntitySessionEnabled{
143
ICdmEntitySessionEnabled{
144 144

  
145 145
    private static final List<String> WS_PROPERTY_PATH = Arrays.asList(new String[] {
146 146
            "descriptions", //$NON-NLS-1$
......
257 257
             ^
258 258
        DataLayer
259 259

  
260
             *
260
         *
261 261

  
262 262
         */
263 263
        DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
......
327 327
        // delegates the sorting to the SortedList
328 328
        final SortHeaderLayer<SpecimenDescription> sortHeaderLayer = new SortHeaderLayer<>(
329 329
                columnHeaderLayer,
330
                        new GlazedListsSortModel<>(
331
                                sortedList,
332
                                columnPropertyAccessor,
333
                                configRegistry,
334
                                columnHeaderDataLayer));
330
                new GlazedListsSortModel<>(
331
                        sortedList,
332
                        columnPropertyAccessor,
333
                        configRegistry,
334
                        columnHeaderDataLayer));
335 335

  
336 336

  
337 337
        /**
......
372 372
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
373 373

  
374 374
        //FIXME: this is for DEBUG ONLY
375
//        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
375
        //        natTable.addConfiguration(new DebugMenuConfiguration(natTable));
376 376

  
377 377
        // override the default sort configuration and change the mouse bindings
378 378
        // to sort on a single click
......
617 617
        SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
618 618
        newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+": "+newDesription.generateTitle(), true);
619 619

  
620
        //check for equals description element (same feature and TODO: same values)
621
        matchingDescriptionElements.forEach(element ->
622
        {
623
            if(matchingDescriptionElements.contains(element)){
624
                MessagingUtils.informationDialog("Multiple data found",
625
                        String.format("Multiple description elements"
626
                                //                             + " with different values "
627
                                + "found for feature %s. "
628
                                + "Data will not be copied to new specimen description", element.getFeature().getLabel()));
620
        //check for equals description element (same feature and same values)
621
        Map<Feature, List<DescriptionElementBase>> featureToElementMap = new HashMap<>();
622
        for(DescriptionElementBase element:matchingDescriptionElements){
623
            List<DescriptionElementBase> list = featureToElementMap.get(element.getFeature());
624
            if(list==null){
625
                list = new ArrayList<>();
629 626
            }
627
            list.add(element);
628
            featureToElementMap.put(element.getFeature(), list);
629
        }
630
        Set<DescriptionElementBase> descriptionElementsToClone = new HashSet<>();
631
        for(Feature feature:featureToElementMap.keySet()){
632
            List<DescriptionElementBase> elements = featureToElementMap.get(feature);
633
            //no duplicate description elements found for this feature
634
            if(elements.size()==1){
635
                descriptionElementsToClone.add(elements.get(0));
636
            }
637
            //duplicates found -> check if all are equal
630 638
            else{
631
                DescriptionElementBase clone;
632
                try {
633
                    clone = element.clone(newDesription);
634
                    clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(element)));
635
                } catch (CloneNotSupportedException e) {
636
                    MessagingUtils.error(CharacterMatrix.class, e);
639
                DescriptionElementBase match = null;
640
                for (DescriptionElementBase descriptionElementBase : elements) {
641
                    if(match==null){
642
                        match = descriptionElementBase;
643
                    }
644
                    else if(!new DescriptionElementCompareWrapper(match).equals(new DescriptionElementCompareWrapper(descriptionElementBase))){
645
                        match = null;
646
                        MessagingUtils.informationDialog("Multiple data found",
647
                                String.format("Multiple description elements with different values "
648
                                        + "found for feature '%s'.\nData will not be copied to new specimen description.", feature.getLabel()));
649
                        break;
650
                    }
651
                }
652
                if(match!=null){
653
                    descriptionElementsToClone.add(match);
637 654
                }
638 655
            }
639
        });
656
        }
657
        //clone matching descriptionElements
658
        for (DescriptionElementBase descriptionElementBase : descriptionElementsToClone) {
659
            DescriptionElementBase clone;
660
            try {
661
                clone = descriptionElementBase.clone(newDesription);
662
                clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(descriptionElementBase)));
663
            } catch (CloneNotSupportedException e) {
664
                MessagingUtils.error(CharacterMatrix.class, e);
665
            }
666
        }
640 667
        return newDesription;
641 668

  
642 669
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/DescriptionElementCompareWrapper.java
1
/**
2
 * Copyright (C) 2018 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix;
10

  
11
import eu.etaxonomy.cdm.model.description.CategoricalData;
12
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
13
import eu.etaxonomy.cdm.model.description.QuantitativeData;
14

  
15
/**
16
 * @author pplitzner
17
 * @since Jan 18, 2018
18
 *
19
 */
20
public class DescriptionElementCompareWrapper {
21

  
22
    private DescriptionElementBase element;
23

  
24
    public DescriptionElementCompareWrapper(DescriptionElementBase element) {
25
        this.element = element;
26
    }
27

  
28
    public DescriptionElementBase unwrap() {
29
        return element;
30
    }
31

  
32
    public boolean equals(DescriptionElementCompareWrapper other) {
33
        DescriptionElementBase otherElement = other.unwrap();
34
        //TODO: Implement more elaborate equals() method
35
        if(element.isInstanceOf(CategoricalData.class) && otherElement instanceof CategoricalData){
36
            boolean equal = true;
37
            CategoricalData otherData = (CategoricalData)otherElement;
38
            CategoricalData elementData = (CategoricalData)element;
39
            equal &= elementData.getStatesOnly().equals(otherData.getStatesOnly());
40
            return equal;
41
        }
42
        if(element.isInstanceOf(QuantitativeData.class) && otherElement instanceof QuantitativeData){
43
            boolean equal = true;
44
            QuantitativeData otherData = (QuantitativeData)otherElement;
45
            QuantitativeData elementData = (QuantitativeData)element;
46
            if(elementData.getMin()!=null && otherData.getMin()==null){
47
                return false;
48
            }
49
            if(elementData.getMin()==null && otherData.getMin()!=null){
50
                return false;
51
            }
52
            if(elementData.getMax()==null && otherData.getMax()!=null){
53
                return false;
54
            }
55
            if(elementData.getMax()!=null && otherData.getMax()==null){
56
                return false;
57
            }
58
            if(elementData.getMin()!=null && otherData.getMin()!=null){
59
                equal &= elementData.getMin().equals(otherData.getMin());
60
            }
61
            if(elementData.getMax()!=null && otherData.getMax()!=null){
62
                equal &= elementData.getMax().equals(otherData.getMax());
63
            }
64
            return equal;
65
        }
66
        return false;
67
    }
68

  
69
}
70

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)