1 package eu
.etaxonomy
.cdm
.api
.service
;
3 import java
.util
.ArrayList
;
6 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
7 import org
.springframework
.stereotype
.Service
;
8 import org
.springframework
.transaction
.annotation
.Propagation
;
9 import org
.springframework
.transaction
.annotation
.Transactional
;
11 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
12 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.AbstractPagerImpl
;
13 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
14 import eu
.etaxonomy
.cdm
.model
.description
.IIdentificationKey
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
16 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IIdentificationKeyDao
;
19 @Transactional(readOnly
= true, propagation
= Propagation
.SUPPORTS
)
20 public class IdentificationKeyServiceImpl
implements IIdentificationKeyService
{
22 IIdentificationKeyDao dao
;
25 public void setDao(IIdentificationKeyDao dao
) {
29 public Pager
<IIdentificationKey
> page(Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
30 Integer numberOfResults
= dao
.count();
31 List
<IIdentificationKey
> results
= new ArrayList
<IIdentificationKey
>();
32 pageNumber
= pageNumber
== null ?
0 : pageNumber
;
33 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
34 Integer start
= pageSize
== null ?
0 : pageSize
* pageNumber
;
35 results
= dao
.list(pageSize
, start
, propertyPaths
);
37 return new DefaultPagerImpl
<IIdentificationKey
>(pageNumber
, numberOfResults
, pageSize
, results
);
41 public <T
extends IIdentificationKey
> Pager
<T
> findKeysConvering(TaxonBase taxon
,
42 Class
<T
> type
, Integer pageSize
,
43 Integer pageNumber
, List
<String
> propertyPaths
) {
45 Integer numberOfResults
= dao
.countByTaxonomicScope(taxon
, type
).intValue();
46 List
<T
> results
= new ArrayList
<T
>();
47 if(AbstractPagerImpl
.hasResultsInRange(numberOfResults
, pageNumber
, pageSize
)){
48 results
= dao
.findByTaxonomicScope(taxon
, type
, pageSize
, pageNumber
, propertyPaths
);
50 return new DefaultPagerImpl
<T
>(pageNumber
, numberOfResults
, pageSize
, results
);