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
.Collection
;
15 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.hibernate
.criterion
.Criterion
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.beans
.factory
.annotation
.Qualifier
;
23 import org
.springframework
.stereotype
.Service
;
24 import org
.springframework
.transaction
.annotation
.Propagation
;
25 import org
.springframework
.transaction
.annotation
.Transactional
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
28 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
29 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
30 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
32 import eu
.etaxonomy
.cdm
.model
.common
.ReferencedEntityBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
35 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
36 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
37 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
38 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
39 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
40 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
41 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
42 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
44 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
45 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
46 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
47 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
48 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
49 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IReferencedEntityDao
;
50 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
51 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.IHomotypicalGroupDao
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.INomenclaturalStatusDao
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITypeDesignationDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
56 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
60 @Transactional(propagation
= Propagation
.SUPPORTS
, readOnly
= true)
61 public class NameServiceImpl
extends IdentifiableServiceBase
<TaxonNameBase
,ITaxonNameDao
> implements INameService
{
62 static private final Logger logger
= Logger
.getLogger(NameServiceImpl
.class);
65 protected ITermVocabularyDao vocabularyDao
;
67 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
69 @Qualifier("refEntDao")
70 protected IReferencedEntityDao
<ReferencedEntityBase
> referencedEntityDao
;
72 private INomenclaturalStatusDao nomStatusDao
;
74 private ITypeDesignationDao typeDesignationDao
;
76 private IHomotypicalGroupDao homotypicalGroupDao
;
81 public NameServiceImpl(){
82 if (logger
.isDebugEnabled()) { logger
.debug("Load NameService Bean"); }
85 //********************* METHODS ****************************************************************//
87 public List
getNamesByName(String name
){
88 return super.findCdmObjectsByTitle(name
);
91 public List
<NonViralName
> getNamesByNameCache(String nameCache
){
92 List result
= dao
.findByName(nameCache
, MatchMode
.EXACT
, null, null, null, null);
96 public List
getNamesByName(String name
, CdmBase sessionObject
){
97 return super.findCdmObjectsByTitle(name
, sessionObject
);
100 public List
findNamesByTitle(String title
){
101 return super.findCdmObjectsByTitle(title
);
104 public List
findNamesByTitle(String title
, CdmBase sessionObject
){
105 return super.findCdmObjectsByTitle(title
, sessionObject
);
108 public List
<TaxonNameBase
> findByTitle(IIdentifiableEntityServiceConfigurator config
) {
109 return super.findByTitle(config
);
112 @Transactional(readOnly
= false)
113 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
){
114 return homotypicalGroupDao
.saveAll(homotypicalGroups
);
117 @Transactional(readOnly
= false)
118 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
){
119 return typeDesignationDao
.saveAll(typeDesignationCollection
);
122 @Transactional(readOnly
= false)
123 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
){
124 return referencedEntityDao
.saveAll(referencedEntityCollection
);
127 public List
<TaxonNameBase
> getAllNames(int limit
, int start
){
128 return dao
.list(limit
, start
);
131 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
){
132 return nomStatusDao
.list(limit
, start
);
135 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
){
136 return typeDesignationDao
.getAllTypeDesignations(limit
, start
);
139 * FIXME Candidate for harmonization
140 * homotypicalGroupService.list
142 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
){
143 return homotypicalGroupDao
.list(limit
, start
);
147 * FIXME Candidate for harmonization
151 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
152 return dao
.getAllRelationships(limit
, start
);
156 * FIXME Candidate for harmonization
157 * is this the same as termService.getVocabulary(VocabularyEnum.Rank)
159 * @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
161 public OrderedTermVocabulary
<Rank
> getRankVocabulary() {
162 String uuidString
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
163 UUID uuid
= UUID
.fromString(uuidString
);
164 OrderedTermVocabulary
<Rank
> rankVocabulary
=
165 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
166 return rankVocabulary
;
170 * FIXME Candidate for harmonization
171 * is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
173 * @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
175 public TermVocabulary
<NameRelationshipType
> getNameRelationshipTypeVocabulary() {
176 String uuidString
= "6878cb82-c1a4-4613-b012-7e73b413c8cd";
177 UUID uuid
= UUID
.fromString(uuidString
);
178 TermVocabulary
<NameRelationshipType
> nameRelTypeVocabulary
=
179 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
180 return nameRelTypeVocabulary
;
184 * FIXME Candidate for harmonization
185 * is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
187 * @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
189 public TermVocabulary
<NomenclaturalStatusType
> getStatusTypeVocabulary() {
190 String uuidString
= "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
191 UUID uuid
= UUID
.fromString(uuidString
);
192 TermVocabulary
<NomenclaturalStatusType
> nomStatusTypeVocabulary
=
193 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
194 return nomStatusTypeVocabulary
;
198 * FIXME Candidate for harmonization
199 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
201 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
203 public TermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatusVocabulary() {
204 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
205 UUID uuid
= UUID
.fromString(uuidString
);
206 TermVocabulary
<SpecimenTypeDesignationStatus
> typeDesigStatusVocabulary
=
207 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
208 return typeDesigStatusVocabulary
;
212 * FIXME Candidate for harmonization
213 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
214 * and also seems to duplicate the above method, differing only in the DAO used and the return type
216 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
218 public OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationVocabulary() {
219 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
220 UUID uuid
= UUID
.fromString(uuidString
);
221 OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> typeDesignationVocabulary
=
222 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
223 return typeDesignationVocabulary
;
226 public void generateTitleCache() {
227 logger
.warn("Not yet implemented");
228 // TODO Auto-generated method stub
232 protected void setDao(ITaxonNameDao dao
) {
236 public Pager
<HybridRelationship
> getHybridNames(NonViralName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
237 Integer numberOfResults
= dao
.countHybridNames(name
, type
);
239 List
<HybridRelationship
> results
= new ArrayList
<HybridRelationship
>();
240 if(numberOfResults
> 0) { // no point checking again
241 results
= dao
.getHybridNames(name
, type
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
244 return new DefaultPagerImpl
<HybridRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
247 public List
<NameRelationship
> listFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
248 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
250 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
251 if(numberOfResults
> 0) { // no point checking again
252 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
257 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
258 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
260 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
261 if(numberOfResults
> 0) { // no point checking again
262 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
264 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
267 public List
<NameRelationship
> listToNameRelationships(TaxonNameBase name
, NameRelationshipType type
,
268 Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
270 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
272 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
273 if (numberOfResults
> 0) { // no point checking again
274 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
275 orderHints
, propertyPaths
);
280 public Pager
<NameRelationship
> pageToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
281 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
283 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
284 if (numberOfResults
> 0) { // no point checking again
285 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
286 orderHints
, propertyPaths
);
289 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
293 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
294 Integer pageSize
, Integer pageNumber
) {
295 return getTypeDesignations(name
, status
, pageSize
, pageNumber
, null);
298 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
299 Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
300 Integer numberOfResults
= dao
.countTypeDesignations(name
, status
);
302 List
<TypeDesignationBase
> results
= new ArrayList
<TypeDesignationBase
>();
303 if(numberOfResults
> 0) { // no point checking again
304 results
= dao
.getTypeDesignations(name
, status
, pageSize
, pageNumber
, propertyPaths
);
307 return new DefaultPagerImpl
<TypeDesignationBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
311 * FIXME Candidate for harmonization
314 public Pager
<TaxonNameBase
> searchNames(String uninomial
,String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
,
315 List
<String
> propertyPaths
) {
316 Integer numberOfResults
= dao
.countNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
318 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
319 if(numberOfResults
> 0) { // no point checking again
320 results
= dao
.searchNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
323 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
327 * @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
329 public List
<UuidAndTitleCache
> getUuidAndTitleCacheOfNames() {
330 return dao
.getUuidAndTitleCacheOfNames();
333 public Pager
<TaxonNameBase
> findByName(Class
<?
extends TaxonNameBase
> clazz
, String queryString
, MatchMode matchmode
, List
<Criterion
> criteria
, Integer pageSize
,Integer pageNumber
, List
<OrderHint
> orderHints
,List
<String
> propertyPaths
) {
334 Integer numberOfResults
= dao
.countByName(clazz
, queryString
, matchmode
, criteria
);
336 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
337 if(numberOfResults
> 0) { // no point checking again
338 results
= dao
.findByName(clazz
, queryString
, matchmode
, criteria
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
341 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);