fixed a bug that occurred when executing operations on taxon nodes on root level
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / AnnotationService.java
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.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 @Autowired
34 protected void setDao(AnnotationDaoImpl dao) {
35 this.dao = dao;
36 }
37
38 public int count(Person commentator, MarkerType status) {
39 return dao.count(commentator, status);
40 }
41
42 public Pager<Annotation> list(Person commentator, MarkerType status,Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
43 Integer numberOfResults = dao.count(commentator, status);
44
45 List<Annotation> results = new ArrayList<Annotation>();
46 if(numberOfResults > 0) { // no point checking again
47 results = dao.list(commentator, status, pageSize, pageNumber, orderHints, propertyPaths);
48 }
49
50 return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
51 }
52 }