merge for cdmlib-services
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / AnnotatableServiceBase.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.transaction.annotation.Transactional;
17
18 import eu.etaxonomy.cdm.api.service.pager.Pager;
19 import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
20 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
21 import eu.etaxonomy.cdm.model.common.Annotation;
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 @Transactional(readOnly = true)
27 public abstract class AnnotatableServiceBase<T extends AnnotatableEntity,DAO extends IAnnotatableDao<T>> extends VersionableServiceBase<T, DAO>
28 implements IAnnotatableService<T> {
29
30 public Pager<Annotation> getAnnotations(T annotatedObj, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
31 Integer numberOfResults = dao.countAnnotations(annotatedObj, status);
32
33 List<Annotation> results = new ArrayList<Annotation>();
34 if(numberOfResults > 0) { // no point checking again
35 results = dao.getAnnotations(annotatedObj, status, pageSize, pageNumber, orderHints, propertyPaths);
36 }
37
38 return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
39 }
40 }