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
.media
.Media
;
37 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
38 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
39 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
40 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
41 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
42 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
43 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
45 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
46 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
47 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
48 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
49 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
50 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IReferencedEntityDao
;
51 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.IHomotypicalGroupDao
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.INomenclaturalStatusDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITypeDesignationDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
57 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
61 @Transactional(propagation
= Propagation
.SUPPORTS
, readOnly
= true)
62 public class NameServiceImpl
extends IdentifiableServiceBase
<TaxonNameBase
,ITaxonNameDao
> implements INameService
{
63 static private final Logger logger
= Logger
.getLogger(NameServiceImpl
.class);
66 protected ITermVocabularyDao vocabularyDao
;
68 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
70 @Qualifier("refEntDao")
71 protected IReferencedEntityDao
<ReferencedEntityBase
> referencedEntityDao
;
73 private INomenclaturalStatusDao nomStatusDao
;
75 private ITypeDesignationDao typeDesignationDao
;
77 private IHomotypicalGroupDao homotypicalGroupDao
;
82 public NameServiceImpl(){
83 if (logger
.isDebugEnabled()) { logger
.debug("Load NameService Bean"); }
86 //********************* METHODS ****************************************************************//
88 public List
getNamesByName(String name
){
89 return super.findCdmObjectsByTitle(name
);
92 public List
<NonViralName
> getNamesByNameCache(String nameCache
){
93 List result
= dao
.findByName(nameCache
, MatchMode
.EXACT
, null, null, null, null);
97 public List
getNamesByName(String name
, CdmBase sessionObject
){
98 return super.findCdmObjectsByTitle(name
, sessionObject
);
101 public List
findNamesByTitle(String title
){
102 return super.findCdmObjectsByTitle(title
);
105 public List
findNamesByTitle(String title
, CdmBase sessionObject
){
106 return super.findCdmObjectsByTitle(title
, sessionObject
);
109 public List
<TaxonNameBase
> findByTitle(IIdentifiableEntityServiceConfigurator config
) {
110 return super.findByTitle(config
);
113 @Transactional(readOnly
= false)
114 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
){
115 return homotypicalGroupDao
.saveAll(homotypicalGroups
);
118 @Transactional(readOnly
= false)
119 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
){
120 return typeDesignationDao
.saveAll(typeDesignationCollection
);
123 @Transactional(readOnly
= false)
124 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
){
125 return referencedEntityDao
.saveAll(referencedEntityCollection
);
128 public List
<TaxonNameBase
> getAllNames(int limit
, int start
){
129 return dao
.list(limit
, start
);
132 public List
<NomenclaturalStatus
> getAllNomenclaturalStatus(int limit
, int start
){
133 return nomStatusDao
.list(limit
, start
);
136 public List
<TypeDesignationBase
> getAllTypeDesignations(int limit
, int start
){
137 return typeDesignationDao
.getAllTypeDesignations(limit
, start
);
140 * FIXME Candidate for harmonization
141 * homotypicalGroupService.list
143 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
){
144 return homotypicalGroupDao
.list(limit
, start
);
148 * FIXME Candidate for harmonization
152 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
153 return dao
.getAllRelationships(limit
, start
);
157 * FIXME Candidate for harmonization
158 * is this the same as termService.getVocabulary(VocabularyEnum.Rank)
160 * @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
162 public OrderedTermVocabulary
<Rank
> getRankVocabulary() {
163 String uuidString
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
164 UUID uuid
= UUID
.fromString(uuidString
);
165 OrderedTermVocabulary
<Rank
> rankVocabulary
=
166 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
167 return rankVocabulary
;
171 * FIXME Candidate for harmonization
172 * is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
174 * @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
176 public TermVocabulary
<NameRelationshipType
> getNameRelationshipTypeVocabulary() {
177 String uuidString
= "6878cb82-c1a4-4613-b012-7e73b413c8cd";
178 UUID uuid
= UUID
.fromString(uuidString
);
179 TermVocabulary
<NameRelationshipType
> nameRelTypeVocabulary
=
180 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
181 return nameRelTypeVocabulary
;
185 * FIXME Candidate for harmonization
186 * is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
188 * @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
190 public TermVocabulary
<NomenclaturalStatusType
> getStatusTypeVocabulary() {
191 String uuidString
= "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
192 UUID uuid
= UUID
.fromString(uuidString
);
193 TermVocabulary
<NomenclaturalStatusType
> nomStatusTypeVocabulary
=
194 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
195 return nomStatusTypeVocabulary
;
199 * FIXME Candidate for harmonization
200 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
202 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
204 public TermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatusVocabulary() {
205 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
206 UUID uuid
= UUID
.fromString(uuidString
);
207 TermVocabulary
<SpecimenTypeDesignationStatus
> typeDesigStatusVocabulary
=
208 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
209 return typeDesigStatusVocabulary
;
213 * FIXME Candidate for harmonization
214 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
215 * and also seems to duplicate the above method, differing only in the DAO used and the return type
217 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
219 public OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationVocabulary() {
220 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
221 UUID uuid
= UUID
.fromString(uuidString
);
222 OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> typeDesignationVocabulary
=
223 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
224 return typeDesignationVocabulary
;
229 protected void setDao(ITaxonNameDao dao
) {
233 public Pager
<HybridRelationship
> getHybridNames(NonViralName name
, HybridRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
234 Integer numberOfResults
= dao
.countHybridNames(name
, type
);
236 List
<HybridRelationship
> results
= new ArrayList
<HybridRelationship
>();
237 if(numberOfResults
> 0) { // no point checking again
238 results
= dao
.getHybridNames(name
, type
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
241 return new DefaultPagerImpl
<HybridRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
244 public List
<NameRelationship
> listFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
245 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
247 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
248 if(numberOfResults
> 0) { // no point checking again
249 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
254 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
255 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
257 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
258 if(numberOfResults
> 0) { // no point checking again
259 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
261 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
264 public List
<NameRelationship
> listToNameRelationships(TaxonNameBase name
, NameRelationshipType type
,
265 Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
267 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
269 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
270 if (numberOfResults
> 0) { // no point checking again
271 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
272 orderHints
, propertyPaths
);
277 public Pager
<NameRelationship
> pageToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
278 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
);
280 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
281 if (numberOfResults
> 0) { // no point checking again
282 results
= dao
.getNameRelationships(name
, NameRelationship
.Direction
.relatedTo
, type
, pageSize
, pageNumber
,
283 orderHints
, propertyPaths
);
286 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
290 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
291 Integer pageSize
, Integer pageNumber
) {
292 return getTypeDesignations(name
, status
, pageSize
, pageNumber
, null);
295 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
296 Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
297 Integer numberOfResults
= dao
.countTypeDesignations(name
, status
);
299 List
<TypeDesignationBase
> results
= new ArrayList
<TypeDesignationBase
>();
300 if(numberOfResults
> 0) { // no point checking again
301 results
= dao
.getTypeDesignations(name
, status
, pageSize
, pageNumber
, propertyPaths
);
304 return new DefaultPagerImpl
<TypeDesignationBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
308 * FIXME Candidate for harmonization
311 public Pager
<TaxonNameBase
> searchNames(String uninomial
,String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
,
312 List
<String
> propertyPaths
) {
313 Integer numberOfResults
= dao
.countNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
315 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
316 if(numberOfResults
> 0) { // no point checking again
317 results
= dao
.searchNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
320 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
324 * @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
326 public List
<UuidAndTitleCache
> getUuidAndTitleCacheOfNames() {
327 return dao
.getUuidAndTitleCacheOfNames();
330 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
) {
331 Integer numberOfResults
= dao
.countByName(clazz
, queryString
, matchmode
, criteria
);
333 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
334 if(numberOfResults
> 0) { // no point checking again
335 results
= dao
.findByName(clazz
, queryString
, matchmode
, criteria
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
338 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
341 public HomotypicalGroup
findHomotypicalGroup(UUID uuid
) {
342 return homotypicalGroupDao
.findByUuid(uuid
);
347 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache()
350 public void updateTitleCache() {
351 Class
<TaxonNameBase
> clazz
= TaxonNameBase
.class;
352 super.updateTitleCache(clazz
, null, null);
356 protected void setOtherCachesNull(TaxonNameBase name
) {
357 if (name
.isInstanceOf(NonViralName
.class)){
358 NonViralName nvn
= CdmBase
.deproxy(name
, NonViralName
.class);
359 if (! nvn
.isProtectedNameCache()){
360 nvn
.setNameCache(null, false);
362 if (! nvn
.isProtectedAuthorshipCache()){
363 nvn
.setAuthorshipCache(null, false);
365 if (! nvn
.isProtectedFullTitleCache()){
366 nvn
.setFullTitleCache(null, false);