Project

General

Profile

Download (2.66 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.Transactional;
19

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

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

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

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

    
45
	@Override
46
    public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
47
		Integer numberOfResults = dao.count(commentator, status);
48

    
49
		List<Annotation> results = new ArrayList<Annotation>();
50
		if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
51
			results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths);
52
		}
53

    
54
		return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
55
	}
56

    
57
	@Override
58
    public int count(User creator, MarkerType status) {
59
		return dao.count(creator, status);
60
	}
61

    
62
	@Override
63
    public Pager<Annotation> list(User creator, MarkerType status,	Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
64
			List<String> propertyPaths) {
65
        Integer numberOfResults = dao.count(creator, status);
66

    
67
		List<Annotation> results = new ArrayList<Annotation>();
68
		if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
69
			results = dao.list(creator, status, pageSize, pageNumber, orderHints, propertyPaths);
70
		}
71

    
72
		return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
73
	}
74
}
(5-5/97)