Project

General

Profile

Download (2.77 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
 * Copyright (C) 2007 EDIT
4
 * European Distributed Institute of Taxonomy 
5
 * http://www.e-taxonomy.eu
6
 * 
7
 * 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
package eu.etaxonomy.cdm.api.service;
12

    
13
import java.util.ArrayList;
14
import java.util.List;
15

    
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.stereotype.Service;
18
import org.springframework.transaction.annotation.Propagation;
19
import org.springframework.transaction.annotation.Transactional;
20

    
21
import eu.etaxonomy.cdm.api.service.pager.Pager;
22
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.common.Annotation;
25
import eu.etaxonomy.cdm.model.common.MarkerType;
26
import eu.etaxonomy.cdm.model.common.User;
27
import eu.etaxonomy.cdm.persistence.dao.hibernate.common.AnnotationDaoImpl;
28
import eu.etaxonomy.cdm.persistence.query.OrderHint;
29

    
30
@Service
31
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
32
public class AnnotationService extends AnnotatableServiceBase<Annotation, AnnotationDaoImpl> implements
33
		IAnnotationService {
34

    
35
	@Autowired
36
	protected void setDao(AnnotationDaoImpl dao) {
37
		this.dao = dao;
38
	}
39

    
40
	public int count(Person commentator, MarkerType status) {
41
		return dao.count(commentator, status);
42
	}
43

    
44
	public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
45
		Integer numberOfResults = dao.count(commentator, status);
46
		
47
		List<Annotation> results = new ArrayList<Annotation>();
48
		if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
49
			results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths);
50
		}
51
		
52
		return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
53
	}
54

    
55
	public int count(User creator, MarkerType status) {
56
		return dao.count(creator, status);
57
	}
58

    
59
	public Pager<Annotation> list(User creator, MarkerType status,	Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
60
			List<String> propertyPaths) {
61
        Integer numberOfResults = dao.count(creator, status);
62
		
63
		List<Annotation> results = new ArrayList<Annotation>();
64
		if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
65
			results = dao.list(creator, status, pageSize, pageNumber, orderHints, propertyPaths);
66
		}
67
		
68
		return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
69
	}
70
}
(5-5/76)