2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.beans
.factory
.annotation
.Qualifier
;
21 import org
.springframework
.stereotype
.Service
;
22 import org
.springframework
.transaction
.annotation
.Transactional
;
24 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
25 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
27 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
29 import eu
.etaxonomy
.cdm
.model
.common
.ReferencedEntityBase
;
30 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
31 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
32 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
33 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
34 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
35 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
36 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
37 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
38 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
39 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
40 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
41 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
43 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatus
;
44 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
45 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IReferencedEntityDao
;
46 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
47 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.IHomotypicalGroupDao
;
48 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.INomenclaturalStatusDao
;
49 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
50 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITypeDesignationDao
;
54 @Transactional(readOnly
= true)
55 public class NameServiceImpl
extends IdentifiableServiceBase
<TaxonNameBase
,ITaxonNameDao
> implements INameService
{
56 static private final Logger logger
= Logger
.getLogger(NameServiceImpl
.class);
59 protected ITermVocabularyDao vocabularyDao
;
61 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
63 @Qualifier("refEntDao")
64 protected IReferencedEntityDao
<ReferencedEntityBase
> referencedEntityDao
;
66 private INomenclaturalStatusDao nomStatusDao
;
68 private ITypeDesignationDao typeDesignationDao
;
70 private IHomotypicalGroupDao homotypicalGroupDao
;
75 public NameServiceImpl(){
76 logger
.debug("Load NameService Bean");
79 //********************* METHODS ****************************************************************//
81 public List
getNamesByName(String name
){
82 return super.findCdmObjectsByTitle(name
);
85 public List
getNamesByName(String name
, CdmBase sessionObject
){
86 return super.findCdmObjectsByTitle(name
, sessionObject
);
89 public List
findNamesByTitle(String title
){
90 return super.findCdmObjectsByTitle(title
);
93 public List
findNamesByTitle(String title
, CdmBase sessionObject
){
94 return super.findCdmObjectsByTitle(title
, sessionObject
);
97 public TaxonNameBase
<?
,?
> getTaxonNameByUuid(UUID uuid
) {
98 return super.getCdmObjectByUuid(uuid
);
101 @Transactional(readOnly
= false)
102 public UUID
saveTaxonName(TaxonNameBase taxonName
) {
103 return super.saveCdmObject(taxonName
);
106 @Transactional(readOnly
= false)
107 public Map
<UUID
, TaxonNameBase
> saveTaxonNameAll(Collection
<?
extends TaxonNameBase
> taxonNameCollection
){
108 return saveCdmObjectAll(taxonNameCollection
);
111 @Transactional(readOnly
= false)
112 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
){
113 return homotypicalGroupDao
.saveAll(homotypicalGroups
);
116 @Transactional(readOnly
= false)
117 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
){
118 return typeDesignationDao
.saveAll(typeDesignationCollection
);
121 @Transactional(readOnly
= false)
122 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
){
123 return referencedEntityDao
.saveAll(referencedEntityCollection
);
126 @Transactional(readOnly
= false)
127 public UUID
removeTaxonName(TaxonNameBase taxonName
) {
128 return super.removeCdmObject(taxonName
);
131 public List
<TaxonNameBase
> getAllNames(int limit
, int start
){
132 return dao
.list(limit
, start
);
135 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
){
136 return nomStatusDao
.list(limit
, start
);
139 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
){
140 return typeDesignationDao
.getAllTypeDesignations(limit
, start
);
143 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
){
144 return homotypicalGroupDao
.list(limit
, start
);
148 * @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
150 public OrderedTermVocabulary
<Rank
> getRankVocabulary() {
151 String uuidString
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
152 UUID uuid
= UUID
.fromString(uuidString
);
153 OrderedTermVocabulary
<Rank
> rankVocabulary
=
154 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
155 return rankVocabulary
;
159 * @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
161 public TermVocabulary
<NameRelationshipType
> getNameRelationshipTypeVocabulary() {
162 String uuidString
= "6878cb82-c1a4-4613-b012-7e73b413c8cd";
163 UUID uuid
= UUID
.fromString(uuidString
);
164 TermVocabulary
<NameRelationshipType
> nameRelTypeVocabulary
=
165 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
166 return nameRelTypeVocabulary
;
170 * @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
172 public TermVocabulary
<NomenclaturalStatusType
> getStatusTypeVocabulary() {
173 String uuidString
= "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
174 UUID uuid
= UUID
.fromString(uuidString
);
175 TermVocabulary
<NomenclaturalStatusType
> nomStatusTypeVocabulary
=
176 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
177 return nomStatusTypeVocabulary
;
181 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
183 public TermVocabulary
<TypeDesignationStatus
> getTypeDesignationStatusVocabulary() {
184 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
185 UUID uuid
= UUID
.fromString(uuidString
);
186 TermVocabulary
<TypeDesignationStatus
> typeDesigStatusVocabulary
=
187 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
191 public void generateTitleCache() {
192 logger
.warn("Not yet implemented");
193 // TODO Auto-generated method stub
197 protected void setDao(ITaxonNameDao dao
) {
201 public Pager
<HybridRelationship
> getHybridNames(BotanicalName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
) {
202 Integer numberOfResults
= dao
.countHybridNames(name
, type
);
204 List
<HybridRelationship
> results
= new ArrayList
<HybridRelationship
>();
205 if(numberOfResults
> 0) { // no point checking again
206 results
= dao
.getHybridNames(name
, type
, pageSize
, pageNumber
);
209 return new DefaultPagerImpl
<HybridRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
212 public Pager
<NameRelationship
> getRelatedNames(TaxonNameBase name
,NameRelationshipType type
, Integer pageSize
, Integer pageNumber
) {
213 Integer numberOfResults
= dao
.countRelatedNames(name
, type
);
215 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
216 if(numberOfResults
> 0) { // no point checking again
217 results
= dao
.getRelatedNames(name
, type
, pageSize
, pageNumber
);
220 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
223 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
,TypeDesignationStatus status
, Integer pageSize
, Integer pageNumber
) {
224 Integer numberOfResults
= dao
.countTypeDesignations(name
, status
);
226 List
<TypeDesignationBase
> results
= new ArrayList
<TypeDesignationBase
>();
227 if(numberOfResults
> 0) { // no point checking again
228 results
= dao
.getTypeDesignations(name
, status
, pageSize
, pageNumber
);
231 return new DefaultPagerImpl
<TypeDesignationBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
234 public Pager
<TaxonNameBase
> searchNames(String uninomial
,String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
) {
235 Integer numberOfResults
= dao
.countNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
237 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
238 if(numberOfResults
> 0) { // no point checking again
239 results
= dao
.searchNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
);
242 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);