1 |
c2f269f9
|
Andreas Kohlbecker
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2007 EDIT
|
4 |
d9f134f9
|
Katja Luther
|
* European Distributed Institute of Taxonomy
|
5 |
c2f269f9
|
Andreas Kohlbecker
|
* http://www.e-taxonomy.eu
|
6 |
d9f134f9
|
Katja Luther
|
*
|
7 |
c2f269f9
|
Andreas Kohlbecker
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
|
11 |
fdf5453b
|
a.babadshanjan
|
package eu.etaxonomy.cdm.api.service;
|
12 |
|
|
|
13 |
d57c0df0
|
ben.clark
|
import java.util.ArrayList;
|
14 |
fdf5453b
|
a.babadshanjan
|
import java.util.List;
|
15 |
d57c0df0
|
ben.clark
|
import java.util.Set;
|
16 |
d9f134f9
|
Katja Luther
|
import java.util.UUID;
|
17 |
fdf5453b
|
a.babadshanjan
|
|
18 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
|
|
import org.springframework.stereotype.Service;
|
20 |
|
|
import org.springframework.transaction.annotation.Transactional;
|
21 |
|
|
|
22 |
d9f134f9
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.config.DeleteConfiguratorBase;
|
23 |
|
|
import eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator;
|
24 |
|
|
import eu.etaxonomy.cdm.api.service.exception.ReferencedObjectUndeletableException;
|
25 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
26 |
|
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
27 |
79c0eaa0
|
Andreas Müller
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
28 |
d9f134f9
|
Katja Luther
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
29 |
|
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
30 |
|
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
31 |
0f7d0d42
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.MediaKey;
|
32 |
d9f134f9
|
Katja Luther
|
import eu.etaxonomy.cdm.model.description.SpecimenDescription;
|
33 |
|
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
34 |
|
|
import eu.etaxonomy.cdm.model.description.TextData;
|
35 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
36 |
fdf5453b
|
a.babadshanjan
|
import eu.etaxonomy.cdm.model.media.Media;
|
37 |
d44277a9
|
ben.clark
|
import eu.etaxonomy.cdm.model.media.Rights;
|
38 |
d57c0df0
|
ben.clark
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
39 |
fdf5453b
|
a.babadshanjan
|
import eu.etaxonomy.cdm.persistence.dao.media.IMediaDao;
|
40 |
b17d9121
|
Andreas Müller
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
41 |
fdf5453b
|
a.babadshanjan
|
|
42 |
|
|
@Service
|
43 |
77b4a247
|
Andreas Kohlbecker
|
@Transactional(readOnly=true)
|
44 |
c4e812bc
|
ben.clark
|
public class MediaServiceImpl extends IdentifiableServiceBase<Media,IMediaDao> implements IMediaService {
|
45 |
d57c0df0
|
ben.clark
|
|
46 |
d9f134f9
|
Katja Luther
|
@Override
|
47 |
|
|
@Autowired
|
48 |
d57c0df0
|
ben.clark
|
protected void setDao(IMediaDao dao) {
|
49 |
|
|
this.dao = dao;
|
50 |
|
|
}
|
51 |
|
|
|
52 |
d9f134f9
|
Katja Luther
|
@Autowired
|
53 |
|
|
private IDescriptionService descriptionService;
|
54 |
|
|
|
55 |
|
|
@Override
|
56 |
|
|
public Pager<MediaKey> getMediaKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
57 |
0f7d0d42
|
h.fradin
|
Integer numberOfResults = dao.countMediaKeys(taxonomicScope, geoScopes);
|
58 |
d9f134f9
|
Katja Luther
|
|
59 |
0f7d0d42
|
h.fradin
|
List<MediaKey> results = new ArrayList<MediaKey>();
|
60 |
76de813f
|
Andreas Kohlbecker
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
61 |
d9f134f9
|
Katja Luther
|
results = dao.getMediaKeys(taxonomicScope, geoScopes, pageSize, pageNumber, propertyPaths);
|
62 |
d57c0df0
|
ben.clark
|
}
|
63 |
d9f134f9
|
Katja Luther
|
|
64 |
0f7d0d42
|
h.fradin
|
return new DefaultPagerImpl<MediaKey>(pageNumber, numberOfResults, pageSize, results);
|
65 |
d57c0df0
|
ben.clark
|
}
|
66 |
d9f134f9
|
Katja Luther
|
|
67 |
|
|
@Override
|
68 |
|
|
public Pager<Rights> getRights(Media t, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
69 |
d44277a9
|
ben.clark
|
Integer numberOfResults = dao.countRights(t);
|
70 |
d9f134f9
|
Katja Luther
|
|
71 |
d44277a9
|
ben.clark
|
List<Rights> results = new ArrayList<Rights>();
|
72 |
76de813f
|
Andreas Kohlbecker
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
73 |
d9f134f9
|
Katja Luther
|
results = dao.getRights(t, pageSize, pageNumber,propertyPaths);
|
74 |
d44277a9
|
ben.clark
|
}
|
75 |
d9f134f9
|
Katja Luther
|
|
76 |
d44277a9
|
ben.clark
|
return new DefaultPagerImpl<Rights>(pageNumber, numberOfResults, pageSize, results);
|
77 |
|
|
}
|
78 |
c4e812bc
|
ben.clark
|
|
79 |
b17d9121
|
Andreas Müller
|
/* (non-Javadoc)
|
80 |
f197a589
|
Andreas Müller
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
81 |
b17d9121
|
Andreas Müller
|
*/
|
82 |
|
|
@Override
|
83 |
4116e48b
|
Andreas Müller
|
@Transactional(readOnly = false)
|
84 |
|
|
public void updateTitleCache(Class<? extends Media> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Media> cacheStrategy, IProgressMonitor monitor) {
|
85 |
b17d9121
|
Andreas Müller
|
//IIdentifiableEntityCacheStrategy<Media> cacheStrategy = MediaDefaultCacheStrategy();
|
86 |
f197a589
|
Andreas Müller
|
if (clazz == null){
|
87 |
|
|
clazz = Media.class;
|
88 |
|
|
}
|
89 |
|
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
90 |
b17d9121
|
Andreas Müller
|
}
|
91 |
d9f134f9
|
Katja Luther
|
|
92 |
|
|
/* (non-Javadoc)
|
93 |
|
|
* @see eu.etaxonomy.cdm.api.service.IMediaService#delete(java.util.UUID, eu.etaxonomy.cdm.api.service.config.MediaDeletionConfigurator)
|
94 |
|
|
*/
|
95 |
|
|
@Override
|
96 |
|
|
public DeleteResult delete(UUID mediaUuid, MediaDeletionConfigurator config) {
|
97 |
|
|
DeleteResult result = new DeleteResult();
|
98 |
|
|
Media media = this.load(mediaUuid);
|
99 |
|
|
|
100 |
|
|
result = isDeletable(media, config);
|
101 |
|
|
|
102 |
|
|
if (result.isOk()){
|
103 |
|
|
dao.delete(media);
|
104 |
|
|
}
|
105 |
|
|
return result;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
@Override
|
109 |
|
|
public DeleteResult isDeletable(Media media, DeleteConfiguratorBase config){
|
110 |
|
|
DeleteResult result = new DeleteResult();
|
111 |
|
|
Set<CdmBase> references = commonService.getReferencingObjectsForDeletion(media);
|
112 |
|
|
String message = null;
|
113 |
|
|
for (CdmBase ref: references){
|
114 |
|
|
if (ref instanceof TextData){
|
115 |
|
|
TextData textData = HibernateProxyHelper.deproxy(ref, TextData.class);
|
116 |
|
|
DescriptionBase description = textData.getInDescription();
|
117 |
|
|
if (description.isImageGallery()){
|
118 |
|
|
if (description instanceof TaxonDescription){
|
119 |
|
|
TaxonDescription desc = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
|
120 |
|
|
if (desc.getTaxon() == null){
|
121 |
|
|
continue;
|
122 |
|
|
} else{
|
123 |
|
|
message = "The media can't be deleted because it is referenced by a taxon. ("+desc.getTaxon().getTitleCache()+")";
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
} else if (description instanceof SpecimenDescription){
|
127 |
|
|
SpecimenDescription desc = HibernateProxyHelper.deproxy(description, SpecimenDescription.class);
|
128 |
|
|
if (desc.getDescribedSpecimenOrObservation() == null){
|
129 |
|
|
continue;
|
130 |
|
|
} else{
|
131 |
|
|
message = "The media can't be deleted because it is referenced by a specimen or observation. ("+desc.getDescribedSpecimenOrObservation().getTitleCache()+")";
|
132 |
|
|
}
|
133 |
|
|
}
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
if (message != null){
|
137 |
|
|
result.addException(new ReferencedObjectUndeletableException(message));
|
138 |
|
|
result.addRelatedObject(ref);
|
139 |
|
|
result.setAbort();
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
return result;
|
146 |
|
|
|
147 |
|
|
}
|
148 |
fdf5453b
|
a.babadshanjan
|
}
|