Project

General

Profile

« Previous | Next » 

Revision 09d274c7

Added by Patrick Plitzner about 6 years ago

ref #7196 Check existing data when adding specimens to matrix

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/matrix/CharacterMatrix.java
123 123
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataCellEditor;
124 124
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.quantitative.QuantitativeDataDisplayConverter;
125 125
import eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo.SupplementalInfoDisplayConverter;
126
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
126 127
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
127 128
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
128 129
import eu.etaxonomy.taxeditor.model.ImageResources;
......
591 592
    }
592 593

  
593 594
    private SpecimenDescription getDescriptionForWorkingSet(SpecimenOrObservationBase specimen){
594
        Set<SpecimenDescription> descriptions = specimen.getDescriptions();
595
        if(descriptions!=null){
596
            Set<Feature> features = workingSet.getDescriptiveSystem().getDistinctFeatures();
597
            for (SpecimenDescription specimenDescription : descriptions) {
598
                Set<Feature> specimenDescriptionFeatures = new HashSet<>();
599
                for (DescriptionElementBase descriptionElementBase : specimenDescription.getElements()) {
600
                    specimenDescriptionFeatures.add(descriptionElementBase.getFeature());
601
                }
602
                if(specimenDescriptionFeatures.containsAll(features)){
603
                    return specimenDescription;
595
        Set<Feature> wsFeatures = workingSet.getDescriptiveSystem().getDistinctFeatures();
596
        List<DescriptionElementBase> matchingDescriptionElements = new ArrayList<>();
597

  
598
        for (SpecimenDescription specimenDescription : (Set<SpecimenDescription>) specimen.getDescriptions()) {
599
            Set<Feature> specimenDescriptionFeatures = new HashSet<>();
600
            //gather specimen description features and check for match with WS features
601
            for (DescriptionElementBase specimenDescriptionElement : specimenDescription.getElements()) {
602
                Feature feature = specimenDescriptionElement.getFeature();
603
                specimenDescriptionFeatures.add(feature);
604
                if(wsFeatures.contains(feature)){
605
                    matchingDescriptionElements.add(specimenDescriptionElement);
604 606
                }
605 607
            }
608
            //if description with the exact same features is found return the description
609
            if(specimenDescriptionFeatures.equals(wsFeatures)){
610
                return specimenDescription;
611
            }
606 612
        }
607 613
        //Create new specimen description if no match was found
608 614
        setDirty();
609 615
        SpecimenDescription newDesription = SpecimenDescription.NewInstance(specimen);
610
        newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+" "+newDesription.generateTitle(), true);
616
        newDesription.setTitleCache("WorkingSet "+workingSet.getLabel()+": "+newDesription.generateTitle(), true);
617

  
618
        //check for equals description element (same feature and TODO: same values)
619
        matchingDescriptionElements.forEach(element ->
620
        {
621
            if(matchingDescriptionElements.contains(element)){
622
                MessagingUtils.informationDialog("Multiple data found",
623
                        String.format("Multiple description elements"
624
                                //                             + " with different values "
625
                                + "found for feature %s. "
626
                                + "Data will not be copied to new specimen description", element.getFeature().getLabel()));
627
            }
628
            else{
629
                DescriptionElementBase clone;
630
                try {
631
                    clone = element.clone(newDesription);
632
                    clone.getSources().forEach(source -> source.setOriginalNameString(DescriptionHelper.getLabel(element)));
633
                } catch (CloneNotSupportedException e) {
634
                    MessagingUtils.error(CharacterMatrix.class, e);
635
                }
636
            }
637
        });
611 638
        return newDesription;
612 639

  
613 640
    }

Also available in: Unified diff