1
|
/**
|
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.transaction.annotation.Transactional;
|
16
|
|
17
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
18
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
19
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
20
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
21
|
import eu.etaxonomy.cdm.model.common.Marker;
|
22
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
23
|
import eu.etaxonomy.cdm.persistence.dao.common.IAnnotatableDao;
|
24
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
25
|
|
26
|
public abstract class AnnotatableServiceBase<T extends AnnotatableEntity,DAO extends IAnnotatableDao<T>>
|
27
|
extends VersionableServiceBase<T, DAO>
|
28
|
implements IAnnotatableService<T> {
|
29
|
|
30
|
@Override
|
31
|
@Transactional(readOnly = true)
|
32
|
public Pager<Annotation> getAnnotations(T annotatedObj, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
33
|
long numberOfResults = dao.countAnnotations(annotatedObj, status);
|
34
|
|
35
|
List<Annotation> results = new ArrayList<>();
|
36
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
37
|
results = dao.getAnnotations(annotatedObj, status, pageSize, pageNumber, orderHints, propertyPaths);
|
38
|
}
|
39
|
|
40
|
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
@Transactional(readOnly = true)
|
45
|
public Pager<Marker> getMarkers(T annotatableEntity, Boolean technical, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
46
|
long numberOfResults = dao.countMarkers(annotatableEntity, technical);
|
47
|
|
48
|
List<Marker> results = new ArrayList<>();
|
49
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
50
|
results = dao.getMarkers(annotatableEntity, technical, pageSize, pageNumber, orderHints, propertyPaths);
|
51
|
}
|
52
|
|
53
|
return new DefaultPagerImpl<>(pageNumber, numberOfResults, pageSize, results);
|
54
|
}
|
55
|
|
56
|
|
57
|
@Override
|
58
|
@Transactional(readOnly = true)
|
59
|
public List<Object[]> groupMarkers(Class<? extends T> clazz, Boolean technical, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
60
|
return dao.groupMarkers(clazz, technical, pageSize, pageNumber, propertyPaths);
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
@Transactional(readOnly = true)
|
65
|
public int countMarkers(Class<? extends T> clazz, Boolean technical) {
|
66
|
return dao.countMarkers(clazz, technical);
|
67
|
}
|
68
|
|
69
|
|
70
|
|
71
|
|
72
|
}
|