Project

General

Profile

« Previous | Next » 

Revision d8f50ab8

Added by Andreas Müller over 6 years ago

ref #6730 remove some further redundant code in MediaServiceImpl.delete

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/TaxonName.java
75 75
import eu.etaxonomy.cdm.model.common.RelationshipBase;
76 76
import eu.etaxonomy.cdm.model.common.TermType;
77 77
import eu.etaxonomy.cdm.model.common.TermVocabulary;
78
import eu.etaxonomy.cdm.model.description.IDescribable;
78 79
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
79 80
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
80 81
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
......
185 186
            extends IdentifiableEntity<INameCacheStrategy>
186 187
            implements ITaxonNameBase, INonViralName, IViralName, IBacterialName, IZoologicalName,
187 188
                IBotanicalName, ICultivarPlantName, IFungusName,
188
                IParsable, IRelated, IMatchable, IIntextReferenceTarget, Cloneable {
189
                IParsable, IRelated, IMatchable, IIntextReferenceTarget, Cloneable,
190
                IDescribable<TaxonNameDescription>{
189 191

  
190 192
    private static final long serialVersionUID = -791164269603409712L;
191 193
    private static final Logger logger = Logger.getLogger(TaxonName.class);
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/MediaServiceImpl.java
27 27
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
28 28
import eu.etaxonomy.cdm.model.common.CdmBase;
29 29
import eu.etaxonomy.cdm.model.description.DescriptionBase;
30
import eu.etaxonomy.cdm.model.description.IDescribable;
30 31
import eu.etaxonomy.cdm.model.description.MediaKey;
31 32
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
32 33
import eu.etaxonomy.cdm.model.description.TaxonDescription;
......
119 120
                        } else if ( (config.isDeleteFromDescription() && config.getDeleteFrom() instanceof Taxon  && config.getDeleteFrom().getId() == desc.getTaxon().getId())|| config.isDeleteFromEveryWhere()){
120 121
                            Taxon taxon = desc.getTaxon();
121 122
                            updatedObject = taxon;
122

  
123
                            handleDeleteMedia(media, textData, desc);
124
                            if (desc.getElements().isEmpty()){
125
                                taxon.removeDescription(desc);
126
                            }
123
                            handleDeleteMedia(media, textData, desc, taxon);
127 124
                        } else {
128 125
                            // this should not be happen, because it is not deletable. see isDeletable
129 126
                            result.setAbort();
......
135 132
                        } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof SpecimenOrObservationBase  && config.getDeleteFrom().getId() == desc.getDescribedSpecimenOrObservation().getId())  || config.isDeleteFromEveryWhere()){
136 133
                            SpecimenOrObservationBase<?> specimen = desc.getDescribedSpecimenOrObservation();
137 134
                            updatedObject = specimen;
138
                            handleDeleteMedia(media, textData, desc);
139
                            if (desc.getElements().isEmpty()){
140
                                specimen.removeDescription(desc);
141
                            }
135
                            handleDeleteMedia(media, textData, desc, specimen);
142 136
                        } else {
143 137
                            // this should not be happen, because it is not deletable. see isDeletable
144 138
                            result.setAbort();
......
151 145
                        } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof TaxonName  && config.getDeleteFrom().getId() == desc.getTaxonName().getId())   || config.isDeleteFromEveryWhere()){
152 146
                            TaxonName name= desc.getTaxonName();
153 147
                            updatedObject = name;
154
                            handleDeleteMedia(media, textData, desc);
155
                            if (desc.getElements().isEmpty()){
156
                                name.removeDescription(desc);
157
                            }
148
                            handleDeleteMedia(media, textData, desc, name);
158 149
                        } else {
159 150
                            // this should not be happen, because it is not deletable. see isDeletable
160 151
                            result.setAbort();
......
196 187
     * @param media
197 188
     * @param textData
198 189
     * @param desc
190
     * @param taxon
199 191
     */
200
    private void handleDeleteMedia(Media media, TextData textData, DescriptionBase desc) {
192
    private <T extends DescriptionBase<?>> void handleDeleteMedia(Media media, TextData textData, T desc,
193
            IDescribable<T> describable) {
201 194
        while(textData.getMedia().contains(media)){
202 195
            textData.removeMedia(media);
203 196
        }
......
205 198
        if (textData.getMedia().isEmpty() && textData.getMultilanguageText().isEmpty()){
206 199
            desc.removeElement(textData);
207 200
        }
201
        if (desc.getElements().isEmpty()){
202
            describable.removeDescription(desc);
203
        }
208 204
    }
209 205

  
210 206

  

Also available in: Unified diff