1 |
b46b4c40
|
Andreas Müller
|
/**
|
2 |
|
|
* Copyright (C) 2007 EDIT
|
3 |
|
|
* European Distributed Institute of Taxonomy
|
4 |
|
|
* http://www.e-taxonomy.eu
|
5 |
|
|
*
|
6 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8 |
|
|
*/
|
9 |
|
|
|
10 |
|
|
package eu.etaxonomy.cdm.api.service;
|
11 |
|
|
|
12 |
|
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.List;
|
14 |
|
|
|
15 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
|
|
import org.springframework.stereotype.Service;
|
17 |
|
|
import org.springframework.transaction.annotation.Transactional;
|
18 |
|
|
|
19 |
|
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
20 |
|
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
21 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
22 |
|
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
23 |
|
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
24 |
|
|
import eu.etaxonomy.cdm.model.common.User;
|
25 |
|
|
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotationDaoImpl;
|
26 |
|
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
27 |
|
|
|
28 |
|
|
@Service
|
29 |
|
|
@Transactional(readOnly = true)
|
30 |
|
|
public class AnnotationService extends AnnotatableServiceBase<Annotation, AnnotationDaoImpl> implements
|
31 |
|
|
IAnnotationService {
|
32 |
|
|
|
33 |
|
|
@Override
|
34 |
|
|
@Autowired
|
35 |
|
|
protected void setDao(AnnotationDaoImpl dao) {
|
36 |
|
|
this.dao = dao;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
@Override
|
40 |
2a4c4dd0
|
Andreas Müller
|
public long count(Person commentator, MarkerType status) {
|
41 |
b46b4c40
|
Andreas Müller
|
return dao.count(commentator, status);
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
@Override
|
45 |
|
|
public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
46 |
2a4c4dd0
|
Andreas Müller
|
Long numberOfResults = dao.count(commentator, status);
|
47 |
b46b4c40
|
Andreas Müller
|
|
48 |
|
|
List<Annotation> results = new ArrayList<Annotation>();
|
49 |
|
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
50 |
|
|
results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths);
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
@Override
|
57 |
2a4c4dd0
|
Andreas Müller
|
public long count(User creator, MarkerType status) {
|
58 |
b46b4c40
|
Andreas Müller
|
return dao.count(creator, status);
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
@Override
|
62 |
|
|
public Pager<Annotation> list(User creator, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
|
63 |
|
|
List<String> propertyPaths) {
|
64 |
2a4c4dd0
|
Andreas Müller
|
long numberOfResults = dao.count(creator, status);
|
65 |
b46b4c40
|
Andreas Müller
|
|
66 |
2a4c4dd0
|
Andreas Müller
|
List<Annotation> results = new ArrayList<>();
|
67 |
b46b4c40
|
Andreas Müller
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
68 |
|
|
results = dao.list(creator, status, pageSize, pageNumber, orderHints, propertyPaths);
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
|
72 |
|
|
}
|
73 |
|
|
}
|