3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.springframework
.transaction
.annotation
.Transactional
;
19 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
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
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.ISourceable
;
24 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
25 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
26 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
28 import eu
.etaxonomy
.cdm
.model
.media
.Rights
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IIdentifiableDao
;
32 @Transactional(readOnly
= true)
33 public abstract class IdentifiableServiceBase
<T
extends IdentifiableEntity
,DAO
extends IIdentifiableDao
<T
>> extends AnnotatableServiceBase
<T
,DAO
>
34 implements IIdentifiableEntityService
<T
>{
35 @SuppressWarnings("unused")
36 private static final Logger logger
= Logger
.getLogger(IdentifiableServiceBase
.class);
39 public Pager
<Rights
> getRights(T t
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
40 Integer numberOfResults
= dao
.countRights(t
);
42 List
<Rights
> results
= new ArrayList
<Rights
>();
43 if(numberOfResults
> 0) { // no point checking again
44 results
= dao
.getRights(t
, pageSize
, pageNumber
,propertyPaths
);
47 return new DefaultPagerImpl
<Rights
>(pageNumber
, numberOfResults
, pageSize
, results
);
50 public Pager
<IdentifiableSource
> getSources(T t
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
51 Integer numberOfResults
= dao
.countSources(t
);
53 List
<IdentifiableSource
> results
= new ArrayList
<IdentifiableSource
>();
54 if(numberOfResults
> 0) { // no point checking again
55 results
= dao
.getSources(t
, pageSize
, pageNumber
,propertyPaths
);
58 return new DefaultPagerImpl
<IdentifiableSource
>(pageNumber
, numberOfResults
, pageSize
, results
);
61 protected List
<T
> findByTitle(IIdentifiableEntityServiceConfigurator config
){
62 return ((IIdentifiableDao
)dao
).findByTitle(config
.getTitleSearchString(),
63 config
.getMatchMode(), 0, -1, null);
64 // TODO: Implement parameters pageSize, pageNumber, and criteria
67 * FIXME Candidate for harmonization
68 * Given that this method is strongly typed, and generic, could we not simply expose it as
69 * List<T> findByTitle(String title) as it is somewhat less cumbersome. Admittedly, I don't
70 * understand what is going on with the configurators etc. so maybe there is a good reason for
71 * the design of this method.
75 protected List
<T
> findCdmObjectsByTitle(String title
){
76 return ((IIdentifiableDao
)dao
).findByTitle(title
);
79 protected List
<T
> findCdmObjectsByTitle(String title
, Class
<T
> clazz
){
80 return ((IIdentifiableDao
)dao
).findByTitleAndClass(title
, clazz
);
82 protected List
<T
> findCdmObjectsByTitle(String title
, CdmBase sessionObject
){
83 return ((IIdentifiableDao
)dao
).findByTitle(title
, sessionObject
);
87 * TODO - Migrated from CommonServiceBase
89 * @see eu.etaxonomy.cdm.api.service.ICommonService#getSourcedObjectById(java.lang.String, java.lang.String)
91 public ISourceable
getSourcedObjectByIdInSource(Class clazz
, String idInSource
, String idNamespace
) {
92 ISourceable result
= null;
94 List
<T
> list
= dao
.findOriginalSourceByIdInSource(idInSource
, idNamespace
);
95 if (! list
.isEmpty()){
102 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#getUuidAndTitleCache()
104 public List
<UuidAndTitleCache
<T
>> getUuidAndTitleCache() {
105 return dao
.getUuidAndTitleCache();