Project

General

Profile

Revision b8cf1412

IDb8cf1412d19e27ce8882b0df4b8f3ec8716adca2
Parent 62ae3f4e
Child 7ecc92ea

Added by Andreas Müller about 2 years ago

ref #6730 cleanup

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/MediaServiceImpl.java
48 48
@Transactional(readOnly=true)
49 49
public class MediaServiceImpl extends IdentifiableServiceBase<Media,IMediaDao> implements IMediaService {
50 50

  
51
	@Override
51
    @Override
52 52
    @Autowired
53 53
	protected void setDao(IMediaDao dao) {
54 54
		this.dao = dao;
55 55
	}
56 56

  
57
	 @Autowired
58
	 private IDescriptionService descriptionService;
59

  
60
	 @Autowired
61
     private IOccurrenceService specimenService;
62
	 @Autowired
63
     private ITaxonService taxonService;
64
	 @Autowired
65
     private INameService nameService;
57
	@Autowired
58
    private IOccurrenceService specimenService;
59
	@Autowired
60
    private ITaxonService taxonService;
61
	@Autowired
62
    private INameService nameService;
66 63

  
67 64
	@Override
68 65
    public Pager<MediaKey> getMediaKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
......
88 85
		return new DefaultPagerImpl<Rights>(pageNumber, numberOfResults, pageSize, results);
89 86
	}
90 87

  
91
	/* (non-Javadoc)
92
	 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
93
	 */
94 88
	@Override
95 89
	@Transactional(readOnly = false)
96 90
    public void updateTitleCache(Class<? extends Media> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Media> cacheStrategy, IProgressMonitor monitor) {
......
101 95
		super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
102 96
	}
103 97

  
104
    /* (non-Javadoc)
105
     * @see eu.etaxonomy.cdm.api.service.IMediaService#delete(java.util.UUID, eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator)
106
     */
107 98
    @Override
108 99
    @Transactional(readOnly=false)
109 100
    public DeleteResult delete(UUID mediaUuid, MediaDeletionConfigurator config) {
......
114 105
        CdmBase updatedObject = null;
115 106
        if (result.isOk()){
116 107
            Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(media);
117
            String message = null;
118 108
            for (CdmBase ref: references){
119 109

  
120 110
               if (ref instanceof TextData){
121 111

  
122 112
                    TextData textData = HibernateProxyHelper.deproxy(ref, TextData.class);
123
                    DescriptionBase description = HibernateProxyHelper.deproxy(textData.getInDescription(), DescriptionBase.class);
124

  
125

  
126
                        if (description instanceof TaxonDescription){
127
                            TaxonDescription desc = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
128
                            if (desc.getTaxon() == null ){
129
                                continue;
130
                            } else if ( (config.isDeleteFromDescription() && config.getDeleteFrom() instanceof Taxon  && config.getDeleteFrom().getId() == desc.getTaxon().getId())|| config.isDeleteFromEveryWhere()){
131
                                Taxon taxon = desc.getTaxon();
132
                                updatedObject = taxon;
133

  
134
                                while(textData.getMedia().contains(media)){
135
                                    textData.removeMedia(media);
136
                                }
137
                                if (textData.getMedia().isEmpty()){
138
                                    desc.removeElement(textData);
139
                                }
140
                                if (desc.getElements().isEmpty()){
141
                                    taxon.removeDescription(desc);
142
                                }
143

  
144
                            } else {
145
                                // this should not be happen, because it is not deletable. see isDeletable
146
                                result.setAbort();
113
                    DescriptionBase<?> description = HibernateProxyHelper.deproxy(textData.getInDescription(), DescriptionBase.class);
147 114

  
115
                    if (description instanceof TaxonDescription){
116
                        TaxonDescription desc = (TaxonDescription)description;
117
                        if (desc.getTaxon() == null ){
118
                            continue;
119
                        } else if ( (config.isDeleteFromDescription() && config.getDeleteFrom() instanceof Taxon  && config.getDeleteFrom().getId() == desc.getTaxon().getId())|| config.isDeleteFromEveryWhere()){
120
                            Taxon taxon = desc.getTaxon();
121
                            updatedObject = taxon;
148 122

  
149
                            }
150
                        } else if (description instanceof SpecimenDescription){
151
                            SpecimenDescription desc = HibernateProxyHelper.deproxy(description, SpecimenDescription.class);
152
                            if (desc.getDescribedSpecimenOrObservation() == null ){
153
                                continue;
154
                            } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof SpecimenOrObservationBase  && config.getDeleteFrom().getId() == desc.getDescribedSpecimenOrObservation().getId())  || config.isDeleteFromEveryWhere()){
155
                                SpecimenOrObservationBase<?> specimen = desc.getDescribedSpecimenOrObservation();
156
                                updatedObject = specimen;
157
                                desc.removeElement(textData);
123
                            while(textData.getMedia().contains(media)){
158 124
                                textData.removeMedia(media);
159
                                if (desc.getElements().isEmpty()){
160
                                    specimen.removeDescription(desc);
161
                                }
162
                            } else {
163
                                result.setAbort();
164

  
165 125
                            }
166
                        }else if (description instanceof TaxonNameDescription){
167
                            TaxonNameDescription desc = HibernateProxyHelper.deproxy(description, TaxonNameDescription.class);
168

  
169
                            if (desc.getTaxonName() == null ){
170
                                continue;
171
                            } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof TaxonName  && config.getDeleteFrom().getId() == desc.getTaxonName().getId())   || config.isDeleteFromEveryWhere()){
172
                                TaxonName name= desc.getTaxonName();
173
                                updatedObject = name;
126
                            if (textData.getMedia().isEmpty()){
174 127
                                desc.removeElement(textData);
175
                                textData.removeMedia(media);
176
                                if (desc.getElements().isEmpty()){
177
                                    name.removeDescription(desc);
178
                                }
179
                            } else {
180

  
181
                                result.setAbort();
182

  
183

  
184 128
                            }
129
                            if (desc.getElements().isEmpty()){
130
                                taxon.removeDescription(desc);
131
                            }
132
                        } else {
133
                            // this should not be happen, because it is not deletable. see isDeletable
134
                            result.setAbort();
135
                        }
136
                    } else if (description instanceof SpecimenDescription){
137
                        SpecimenDescription desc = (SpecimenDescription)description;
138
                        if (desc.getDescribedSpecimenOrObservation() == null ){
139
                            continue;
140
                        } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof SpecimenOrObservationBase  && config.getDeleteFrom().getId() == desc.getDescribedSpecimenOrObservation().getId())  || config.isDeleteFromEveryWhere()){
141
                            SpecimenOrObservationBase<?> specimen = desc.getDescribedSpecimenOrObservation();
142
                            updatedObject = specimen;
143
                            desc.removeElement(textData);
144
                            textData.removeMedia(media);
145
                            if (desc.getElements().isEmpty()){
146
                                specimen.removeDescription(desc);
147
                            }
148
                        } else {
149
                            // this should not be happen, because it is not deletable. see isDeletable
150
                            result.setAbort();
151
                        }
152
                    }else if (description instanceof TaxonNameDescription){
153
                        TaxonNameDescription desc = (TaxonNameDescription)description;
154

  
155
                        if (desc.getTaxonName() == null ){
156
                            continue;
157
                        } else if ((config.isDeleteFromDescription() && config.getDeleteFrom() instanceof TaxonName  && config.getDeleteFrom().getId() == desc.getTaxonName().getId())   || config.isDeleteFromEveryWhere()){
158
                            TaxonName name= desc.getTaxonName();
159
                            updatedObject = name;
160
                            desc.removeElement(textData);
161
                            textData.removeMedia(media);
162
                            if (desc.getElements().isEmpty()){
163
                                name.removeDescription(desc);
164
                            }
165
                        } else {
166
                            // this should not be happen, because it is not deletable. see isDeletable
167
                            result.setAbort();
185 168
                        }
169
                    }
186 170

  
187 171
                } else if ((ref instanceof MediaSpecimen && config.getDeleteFrom().getId() == ref.getId() && config.getDeleteFrom() instanceof MediaSpecimen)
188 172
                        || (ref instanceof MediaSpecimen && config.isDeleteFromEveryWhere())){
......
195 179
                    continue;
196 180

  
197 181
                }else {
198

  
199 182
                    result.setAbort();
200

  
201

  
202 183
                }
203

  
204 184
            }
205 185
            if (result.isOk()){
206 186
                dao.delete(media);
207 187
            }
208
                if (updatedObject instanceof
209
                         TaxonBase){
210
                    taxonService.update((TaxonBase)updatedObject);
211
                    result.addUpdatedObject(updatedObject);
212
                }
213
                if (updatedObject instanceof
214
                        TaxonName){
215
                   nameService.update((TaxonName)updatedObject);
216
               }
217
                if (updatedObject instanceof
218
                        SpecimenOrObservationBase){
219
                   specimenService.update((SpecimenOrObservationBase)updatedObject);
220
               }
221

  
188
            if (updatedObject instanceof TaxonBase){
189
                taxonService.update((TaxonBase)updatedObject);
190
                result.addUpdatedObject(updatedObject);
191
            }else if (updatedObject instanceof TaxonName){
192
                nameService.update((TaxonName)updatedObject);
193
            }else if (updatedObject instanceof SpecimenOrObservationBase){
194
                specimenService.update((SpecimenOrObservationBase)updatedObject);
195
            }
222 196
        }
223 197
        return result;
224 198
    }
......
282 256

  
283 257
        }
284 258

  
285

  
286 259
        return result;
287

  
288 260
    }
289 261
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)