1
|
package eu.etaxonomy.cdm.api.service;
|
2
|
|
3
|
import java.util.ArrayList;
|
4
|
import java.util.Collection;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
import java.util.Set;
|
8
|
import java.util.UUID;
|
9
|
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.stereotype.Service;
|
12
|
import org.springframework.transaction.annotation.Transactional;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
15
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
16
|
import eu.etaxonomy.cdm.model.description.IdentificationKey;
|
17
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
18
|
import eu.etaxonomy.cdm.model.media.Media;
|
19
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
20
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.persistence.dao.media.IMediaDao;
|
23
|
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationDao;
|
24
|
import eu.etaxonomy.cdm.persistence.dao.media.IMediaRepresentationPartDao;
|
25
|
|
26
|
@Service
|
27
|
@Transactional
|
28
|
public class MediaServiceImpl extends AnnotatableServiceBase<Media,IMediaDao> implements IMediaService {
|
29
|
|
30
|
@Autowired
|
31
|
private IMediaRepresentationDao mediaRepresentationDao;
|
32
|
|
33
|
@Autowired
|
34
|
private IMediaRepresentationPartDao mediaRepresentationPartDao;
|
35
|
|
36
|
@Transactional(readOnly = false)
|
37
|
public Map<UUID, Media> saveMediaAll(Collection<Media> mediaCollection){
|
38
|
return saveCdmObjectAll(mediaCollection);
|
39
|
//TODO: Fix saveAll() types
|
40
|
// return mediaDao.saveAll(mediaCollection);
|
41
|
}
|
42
|
|
43
|
public List<Media> getAllMedia(int limit, int start){
|
44
|
return dao.list(limit, start);
|
45
|
}
|
46
|
|
47
|
public List<MediaRepresentation> getAllMediaRepresentations(int limit, int start){
|
48
|
return mediaRepresentationDao.list(limit, start);
|
49
|
}
|
50
|
|
51
|
public List<MediaRepresentationPart> getAllMediaRepresentationParts(int limit, int start){
|
52
|
return mediaRepresentationPartDao.list(limit, start);
|
53
|
}
|
54
|
|
55
|
@Autowired
|
56
|
protected void setDao(IMediaDao dao) {
|
57
|
this.dao = dao;
|
58
|
}
|
59
|
|
60
|
public Pager<IdentificationKey> getIdentificationKeys(Set<Taxon> taxonomicScope, Set<NamedArea> geoScopes, Integer pageSize, Integer pageNumber) {
|
61
|
Integer numberOfResults = dao.countIdentificationKeys(taxonomicScope, geoScopes);
|
62
|
|
63
|
List<IdentificationKey> results = new ArrayList<IdentificationKey>();
|
64
|
if(numberOfResults > 0) { // no point checking again
|
65
|
results = dao.getIdentificationKeys(taxonomicScope, geoScopes, pageSize, pageNumber);
|
66
|
}
|
67
|
|
68
|
return new DefaultPagerImpl<IdentificationKey>(pageNumber, numberOfResults, pageSize, results);
|
69
|
}
|
70
|
}
|