Project

General

Profile

Revision 35fc9327

ID35fc9327071d776439eee990f4fd7c5aeeb586a3
Parent 0a8972e2
Child 7a33ea3e

Added by Patrick Plitzner about 7 years ago

  • fixed case where a DerivedUnit is given as method parameter -> needed also to check for parent FieldUnits

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
798 798

  
799 799
        //FieldUnit
800 800
        if(specimen instanceof FieldUnit){
801
            FieldUnit fieldUnit = (FieldUnit)specimen;
802
            GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
803
            if(gatheringEvent!=null){
804
                //country
805
                if(gatheringEvent.getCountry()!=null){
806
                    nonCascadedCdmEntities.add(gatheringEvent.getCountry());
807
                }
808
                //collecting areas
809
                for (NamedArea namedArea : gatheringEvent.getCollectingAreas()) {
810
                    nonCascadedCdmEntities.add(namedArea);
811
                }
812
            }
813
            for (DerivationEvent derivationEvent : fieldUnit.getDerivationEvents()) {
814
                for (DerivedUnit derivedUnit : derivationEvent.getDerivatives()) {
815
                    nonCascadedCdmEntities.addAll(getNonCascadedAssociatedElements(derivedUnit));
816
                }
817
            }
801
            nonCascadedCdmEntities.addAll(getNonCascadedAssociatedElements((FieldUnit)specimen));
818 802
        }
819

  
820 803
        //DerivedUnit
821 804
        else if(specimen instanceof DerivedUnit){
822 805
            DerivedUnit derivedUnit = (DerivedUnit)specimen;
823
            if(derivedUnit.getCollection()!=null && derivedUnit.getCollection().getInstitute()!=null){
824
                for (DefinedTerm type : derivedUnit.getCollection().getInstitute().getTypes()) {
825
                    nonCascadedCdmEntities.add(type);
806
            if(derivedUnit.getDerivedFrom()!=null){
807
                Collection<FieldUnit> fieldUnits = new ArrayList<FieldUnit>();
808
                getFieldUnits(derivedUnit, fieldUnits);
809
                for(FieldUnit fieldUnit:fieldUnits){
810
                    nonCascadedCdmEntities.addAll(getNonCascadedAssociatedElements(fieldUnit));
826 811
                }
827 812
            }
828
            if(derivedUnit.getPreservation()!=null && derivedUnit.getPreservation().getMedium()!=null){
829
                nonCascadedCdmEntities.add(derivedUnit.getPreservation().getMedium());
813
        }
814
        return nonCascadedCdmEntities;
815
    }
816

  
817
    private Collection<ICdmBase> getNonCascadedAssociatedElements(FieldUnit fieldUnit){
818
        Collection<ICdmBase> nonCascadedCdmEntities = new HashSet<ICdmBase>();
819
        GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
820
        if(gatheringEvent!=null){
821
            //country
822
            if(gatheringEvent.getCountry()!=null){
823
                nonCascadedCdmEntities.add(gatheringEvent.getCountry());
830 824
            }
831
            if(derivedUnit.getStoredUnder()!=null){
832
                nonCascadedCdmEntities.add(derivedUnit.getStoredUnder());
825
            //collecting areas
826
            for (NamedArea namedArea : gatheringEvent.getCollectingAreas()) {
827
                nonCascadedCdmEntities.add(namedArea);
828
            }
829
        }
830
        for (DerivationEvent derivationEvent : fieldUnit.getDerivationEvents()) {
831
            for (DerivedUnit derivedUnit : derivationEvent.getDerivatives()) {
832
                nonCascadedCdmEntities.addAll(getNonCascadedAssociatedElements(derivedUnit));
833 833
            }
834 834
        }
835 835
        return nonCascadedCdmEntities;
836 836
    }
837 837

  
838
    private Collection<ICdmBase> getNonCascadedAssociatedElements(DerivedUnit derivedUnit){
839
        Collection<ICdmBase> nonCascadedCdmEntities = new HashSet<ICdmBase>();
840
        if(derivedUnit.getCollection()!=null && derivedUnit.getCollection().getInstitute()!=null){
841
            for (DefinedTerm type : derivedUnit.getCollection().getInstitute().getTypes()) {
842
                nonCascadedCdmEntities.add(type);
843
            }
844
        }
845
        if(derivedUnit.getPreservation()!=null && derivedUnit.getPreservation().getMedium()!=null){
846
            nonCascadedCdmEntities.add(derivedUnit.getPreservation().getMedium());
847
        }
848
        if(derivedUnit.getStoredUnder()!=null){
849
            nonCascadedCdmEntities.add(derivedUnit.getStoredUnder());
850
        }
851
        return nonCascadedCdmEntities;
852
    }
853

  
854

  
838 855
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)