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
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
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
.Transactional
;
26 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
27 import eu
.etaxonomy
.cdm
.api
.service
.config
.INameServiceConfigurator
;
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
.Annotation
;
31 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
33 import eu
.etaxonomy
.cdm
.model
.common
.ReferencedEntityBase
;
34 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
37 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
38 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
39 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
40 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
41 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
42 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
45 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
46 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
47 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
48 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
49 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
50 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IReferencedEntityDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.IHomotypicalGroupDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.INomenclaturalStatusDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
58 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITypeDesignationDao
;
59 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
60 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
64 @Transactional(readOnly
= true)
65 public class NameServiceImpl
extends IdentifiableServiceBase
<TaxonNameBase
,ITaxonNameDao
> implements INameService
{
66 static private final Logger logger
= Logger
.getLogger(NameServiceImpl
.class);
69 protected ITermVocabularyDao vocabularyDao
;
71 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
73 @Qualifier("refEntDao")
74 protected IReferencedEntityDao
<ReferencedEntityBase
> referencedEntityDao
;
76 private INomenclaturalStatusDao nomStatusDao
;
78 private ITypeDesignationDao typeDesignationDao
;
80 private IHomotypicalGroupDao homotypicalGroupDao
;
85 public NameServiceImpl(){
86 if (logger
.isDebugEnabled()) { logger
.debug("Load NameService Bean"); }
89 //********************* METHODS ****************************************************************//
91 public List
getNamesByName(String name
){
92 return super.findCdmObjectsByTitle(name
);
95 public List
<NonViralName
> getNamesByNameCache(String nameCache
){
96 List result
= dao
.findByName(nameCache
, MatchMode
.EXACT
, null, null, null, null);
100 public List
getNamesByName(String name
, CdmBase sessionObject
){
101 return super.findCdmObjectsByTitle(name
, sessionObject
);
104 public List
findNamesByTitle(String title
){
105 return super.findCdmObjectsByTitle(title
);
108 public List
findNamesByTitle(String title
, CdmBase sessionObject
){
109 return super.findCdmObjectsByTitle(title
, sessionObject
);
112 public List
<TaxonNameBase
> findByTitle(IIdentifiableEntityServiceConfigurator config
) {
113 return super.findByTitle(config
);
116 public TaxonNameBase
<?
,?
> getTaxonNameByUuid(UUID uuid
) {
117 return super.getCdmObjectByUuid(uuid
);
120 @Transactional(readOnly
= false)
121 public UUID
saveTaxonName(TaxonNameBase taxonName
) {
122 return super.saveCdmObject(taxonName
);
125 @Transactional(readOnly
= false)
126 public Map
<UUID
, TaxonNameBase
> saveTaxonNameAll(Collection
<?
extends TaxonNameBase
> taxonNameCollection
){
127 return saveCdmObjectAll(taxonNameCollection
);
130 @Transactional(readOnly
= false)
131 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
){
132 return homotypicalGroupDao
.saveAll(homotypicalGroups
);
135 @Transactional(readOnly
= false)
136 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
){
137 return typeDesignationDao
.saveAll(typeDesignationCollection
);
140 @Transactional(readOnly
= false)
141 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
){
142 return referencedEntityDao
.saveAll(referencedEntityCollection
);
145 @Transactional(readOnly
= false)
146 public UUID
removeTaxonName(TaxonNameBase taxonName
) {
147 return super.removeCdmObject(taxonName
);
150 public List
<TaxonNameBase
> getAllNames(int limit
, int start
){
151 return dao
.list(limit
, start
);
154 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
){
155 return nomStatusDao
.list(limit
, start
);
158 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
){
159 return typeDesignationDao
.getAllTypeDesignations(limit
, start
);
162 * FIXME Candidate for harmonization
163 * homotypicalGroupService.list
165 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
){
166 return homotypicalGroupDao
.list(limit
, start
);
170 * FIXME Candidate for harmonization
174 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
175 return dao
.getAllRelationships(limit
, start
);
179 * FIXME Candidate for harmonization
180 * is this the same as termService.getVocabulary(VocabularyEnum.Rank)
182 * @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
184 public OrderedTermVocabulary
<Rank
> getRankVocabulary() {
185 String uuidString
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
186 UUID uuid
= UUID
.fromString(uuidString
);
187 OrderedTermVocabulary
<Rank
> rankVocabulary
=
188 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
189 return rankVocabulary
;
193 * FIXME Candidate for harmonization
194 * is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
196 * @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
198 public TermVocabulary
<NameRelationshipType
> getNameRelationshipTypeVocabulary() {
199 String uuidString
= "6878cb82-c1a4-4613-b012-7e73b413c8cd";
200 UUID uuid
= UUID
.fromString(uuidString
);
201 TermVocabulary
<NameRelationshipType
> nameRelTypeVocabulary
=
202 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
203 return nameRelTypeVocabulary
;
207 * FIXME Candidate for harmonization
208 * is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
210 * @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
212 public TermVocabulary
<NomenclaturalStatusType
> getStatusTypeVocabulary() {
213 String uuidString
= "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
214 UUID uuid
= UUID
.fromString(uuidString
);
215 TermVocabulary
<NomenclaturalStatusType
> nomStatusTypeVocabulary
=
216 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
217 return nomStatusTypeVocabulary
;
221 * FIXME Candidate for harmonization
222 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
224 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
226 public TermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatusVocabulary() {
227 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
228 UUID uuid
= UUID
.fromString(uuidString
);
229 TermVocabulary
<SpecimenTypeDesignationStatus
> typeDesigStatusVocabulary
=
230 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
231 return typeDesigStatusVocabulary
;
235 * FIXME Candidate for harmonization
236 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
237 * and also seems to duplicate the above method, differing only in the DAO used and the return type
239 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
241 public OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationVocabulary() {
242 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
243 UUID uuid
= UUID
.fromString(uuidString
);
244 OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> typeDesignationVocabulary
=
245 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
246 return typeDesignationVocabulary
;
249 public void generateTitleCache() {
250 logger
.warn("Not yet implemented");
251 // TODO Auto-generated method stub
255 protected void setDao(ITaxonNameDao dao
) {
259 public Pager
<HybridRelationship
> getHybridNames(BotanicalName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
260 Integer numberOfResults
= dao
.countHybridNames(name
, type
);
262 List
<HybridRelationship
> results
= new ArrayList
<HybridRelationship
>();
263 if(numberOfResults
> 0) { // no point checking again
264 results
= dao
.getHybridNames(name
, type
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
267 return new DefaultPagerImpl
<HybridRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
270 public List
<NameRelationship
> listFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
271 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
273 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
274 if(numberOfResults
> 0) { // no point checking again
275 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
280 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
281 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
283 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
284 if(numberOfResults
> 0) { // no point checking again
285 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
287 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
290 public List
<NameRelationship
> listToNameRelationships(TaxonNameBase name
, NameRelationshipType type
,
291 Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
293 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
295 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
296 if (numberOfResults
> 0) { // no point checking again
297 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
298 orderHints
, propertyPaths
);
303 public Pager
<NameRelationship
> pageToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
304 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
306 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
307 if (numberOfResults
> 0) { // no point checking again
308 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
309 orderHints
, propertyPaths
);
312 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
316 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
317 Integer pageSize
, Integer pageNumber
) {
318 return getTypeDesignations(name
, status
, pageSize
, pageNumber
, null);
321 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
322 Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
323 Integer numberOfResults
= dao
.countTypeDesignations(name
, status
);
325 List
<TypeDesignationBase
> results
= new ArrayList
<TypeDesignationBase
>();
326 if(numberOfResults
> 0) { // no point checking again
327 results
= dao
.getTypeDesignations(name
, status
, pageSize
, pageNumber
, propertyPaths
);
330 return new DefaultPagerImpl
<TypeDesignationBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
334 * FIXME Candidate for harmonization
337 public Pager
<TaxonNameBase
> searchNames(String uninomial
,String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
,
338 List
<String
> propertyPaths
) {
339 Integer numberOfResults
= dao
.countNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
341 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
342 if(numberOfResults
> 0) { // no point checking again
343 results
= dao
.searchNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
346 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
349 public Pager
<TaxonNameBase
> search(Class
<?
extends TaxonNameBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
350 Integer numberOfResults
= dao
.count(clazz
,queryString
);
352 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
353 if(numberOfResults
> 0) { // no point checking again
354 results
= dao
.search(clazz
,queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
357 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
361 * @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
363 public Map
<UUID
, String
> getUuidAndTitleCacheOfNames() {
364 return dao
.getUuidAndTitleCacheOfNames();
368 * @see eu.etaxonomy.cdm.api.service.IService#list(java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
370 public <TYPE
extends TaxonNameBase
> Pager
<TYPE
> list(Class
<TYPE
> type
,
371 Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
,
372 List
<String
> propertyPaths
) {
373 // TODO Auto-generated method stub