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
.AbstractPagerImpl
;
30 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
31 import eu
.etaxonomy
.cdm
.common
.IProgressMonitor
;
32 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.OrderedTermVocabulary
;
34 import eu
.etaxonomy
.cdm
.model
.common
.ReferencedEntityBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
37 import eu
.etaxonomy
.cdm
.model
.common
.UuidAndTitleCache
;
38 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
.Direction
;
39 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
40 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
41 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
42 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
43 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationshipType
;
44 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
45 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationshipType
;
46 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
47 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
48 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
49 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
50 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignationStatus
;
51 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
52 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IOrderedTermVocabularyDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IReferencedEntityDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.IHomotypicalGroupDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.INomenclaturalStatusDao
;
58 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITaxonNameDao
;
59 import eu
.etaxonomy
.cdm
.persistence
.dao
.name
.ITypeDesignationDao
;
60 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
61 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
62 import eu
.etaxonomy
.cdm
.strategy
.TaggedText
;
63 import eu
.etaxonomy
.cdm
.strategy
.TaggedTextGenerator
;
64 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
68 @Transactional(propagation
= Propagation
.SUPPORTS
, readOnly
= true)
69 public class NameServiceImpl
extends IdentifiableServiceBase
<TaxonNameBase
,ITaxonNameDao
> implements INameService
{
70 static private final Logger logger
= Logger
.getLogger(NameServiceImpl
.class);
73 protected ITermVocabularyDao vocabularyDao
;
75 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
77 @Qualifier("refEntDao")
78 protected IReferencedEntityDao
<ReferencedEntityBase
> referencedEntityDao
;
80 private INomenclaturalStatusDao nomStatusDao
;
82 private ITypeDesignationDao typeDesignationDao
;
84 private IHomotypicalGroupDao homotypicalGroupDao
;
89 public NameServiceImpl(){
90 if (logger
.isDebugEnabled()) { logger
.debug("Load NameService Bean"); }
93 //********************* METHODS ****************************************************************//
95 public List
getNamesByName(String name
){
96 return super.findCdmObjectsByTitle(name
);
99 public List
<NonViralName
> getNamesByNameCache(String nameCache
){
100 List result
= dao
.findByName(nameCache
, MatchMode
.EXACT
, null, null, null, null);
104 public List
getNamesByName(String name
, CdmBase sessionObject
){
105 return super.findCdmObjectsByTitle(name
, sessionObject
);
108 public List
findNamesByTitle(String title
){
109 return super.findCdmObjectsByTitle(title
);
112 public List
findNamesByTitle(String title
, CdmBase sessionObject
){
113 return super.findCdmObjectsByTitle(title
, sessionObject
);
116 @Transactional(readOnly
= false)
117 public Map
<UUID
, HomotypicalGroup
> saveAllHomotypicalGroups(Collection
<HomotypicalGroup
> homotypicalGroups
){
118 return homotypicalGroupDao
.saveAll(homotypicalGroups
);
121 @Transactional(readOnly
= false)
122 public Map
<UUID
, TypeDesignationBase
> saveTypeDesignationAll(Collection
<TypeDesignationBase
> typeDesignationCollection
){
123 return typeDesignationDao
.saveAll(typeDesignationCollection
);
126 @Transactional(readOnly
= false)
127 public Map
<UUID
, ReferencedEntityBase
> saveReferencedEntitiesAll(Collection
<ReferencedEntityBase
> referencedEntityCollection
){
128 return referencedEntityDao
.saveAll(referencedEntityCollection
);
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 * FIXME Candidate for harmonization
144 * homotypicalGroupService.list
146 public List
<HomotypicalGroup
> getAllHomotypicalGroups(int limit
, int start
){
147 return homotypicalGroupDao
.list(limit
, start
);
151 * FIXME Candidate for harmonization
155 public List
<RelationshipBase
> getAllRelationships(int limit
, int start
){
156 return dao
.getRelationships(limit
, start
);
160 * FIXME Candidate for harmonization
161 * is this the same as termService.getVocabulary(VocabularyEnum.Rank)
163 * @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
165 public OrderedTermVocabulary
<Rank
> getRankVocabulary() {
166 String uuidString
= "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
167 UUID uuid
= UUID
.fromString(uuidString
);
168 OrderedTermVocabulary
<Rank
> rankVocabulary
=
169 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
170 return rankVocabulary
;
174 * FIXME Candidate for harmonization
175 * is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
177 * @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
179 public TermVocabulary
<NameRelationshipType
> getNameRelationshipTypeVocabulary() {
180 String uuidString
= "6878cb82-c1a4-4613-b012-7e73b413c8cd";
181 UUID uuid
= UUID
.fromString(uuidString
);
182 TermVocabulary
<NameRelationshipType
> nameRelTypeVocabulary
=
183 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
184 return nameRelTypeVocabulary
;
188 * FIXME Candidate for harmonization
189 * is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
191 * @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
193 public TermVocabulary
<NomenclaturalStatusType
> getStatusTypeVocabulary() {
194 String uuidString
= "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
195 UUID uuid
= UUID
.fromString(uuidString
);
196 TermVocabulary
<NomenclaturalStatusType
> nomStatusTypeVocabulary
=
197 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
198 return nomStatusTypeVocabulary
;
202 * FIXME Candidate for harmonization
203 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
205 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
207 public TermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationStatusVocabulary() {
208 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
209 UUID uuid
= UUID
.fromString(uuidString
);
210 TermVocabulary
<SpecimenTypeDesignationStatus
> typeDesigStatusVocabulary
=
211 (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
212 return typeDesigStatusVocabulary
;
216 * FIXME Candidate for harmonization
217 * is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
218 * and also seems to duplicate the above method, differing only in the DAO used and the return type
220 * @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
222 public OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> getSpecimenTypeDesignationVocabulary() {
223 String uuidString
= "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
224 UUID uuid
= UUID
.fromString(uuidString
);
225 OrderedTermVocabulary
<SpecimenTypeDesignationStatus
> typeDesignationVocabulary
=
226 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
227 return typeDesignationVocabulary
;
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(AbstractPagerImpl
.hasResultsInRange(numberOfResults
, pageNumber
, pageSize
)) { // no point checking again
241 results
= dao
.getHybridNames(name
, type
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
244 return new DefaultPagerImpl
<HybridRelationship
>(pageNumber
, numberOfResults
, pageSize
, results
);
248 * @see eu.etaxonomy.cdm.api.service.INameService#listNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
251 public List
<NameRelationship
> listNameRelationships(TaxonNameBase name
, Direction direction
, NameRelationshipType type
, Integer pageSize
,
252 Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
254 Integer numberOfResults
= dao
.countNameRelationships(name
, NameRelationship
.Direction
.relatedFrom
, type
);
256 List
<NameRelationship
> results
= new ArrayList
<NameRelationship
>();
257 if (AbstractPagerImpl
.hasResultsInRange(numberOfResults
, pageNumber
, pageSize
)) { // no point checking again
258 results
= dao
.getNameRelationships(name
, direction
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
264 * @see eu.etaxonomy.cdm.api.service.INameService#pageNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
267 public Pager
<NameRelationship
> pageNameRelationships(TaxonNameBase name
, Direction direction
, NameRelationshipType type
, Integer pageSize
,
268 Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
269 List
<NameRelationship
> results
= listNameRelationships(name
, direction
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
270 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, results
.size(), pageSize
, results
);
273 public List
<NameRelationship
> listFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
274 return listNameRelationships(name
, Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
277 public Pager
<NameRelationship
> pageFromNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
278 List
<NameRelationship
> results
= listNameRelationships(name
, Direction
.relatedFrom
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
279 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, results
.size(), pageSize
, results
);
282 public List
<NameRelationship
> listToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
283 return listNameRelationships(name
, Direction
.relatedTo
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
286 public Pager
<NameRelationship
> pageToNameRelationships(TaxonNameBase name
, NameRelationshipType type
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
287 List
<NameRelationship
> results
= listNameRelationships(name
, Direction
.relatedTo
, type
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
288 return new DefaultPagerImpl
<NameRelationship
>(pageNumber
, results
.size(), pageSize
, results
);
291 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
292 Integer pageSize
, Integer pageNumber
) {
293 return getTypeDesignations(name
, status
, pageSize
, pageNumber
, null);
296 public Pager
<TypeDesignationBase
> getTypeDesignations(TaxonNameBase name
, SpecimenTypeDesignationStatus status
,
297 Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
298 Integer numberOfResults
= dao
.countTypeDesignations(name
, status
);
300 List
<TypeDesignationBase
> results
= new ArrayList
<TypeDesignationBase
>();
301 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
302 results
= dao
.getTypeDesignations(name
, status
, pageSize
, pageNumber
, propertyPaths
);
305 return new DefaultPagerImpl
<TypeDesignationBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
309 * FIXME Candidate for harmonization
312 public Pager
<TaxonNameBase
> searchNames(String uninomial
,String infraGenericEpithet
, String specificEpithet
, String infraspecificEpithet
, Rank rank
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
,
313 List
<String
> propertyPaths
) {
314 Integer numberOfResults
= dao
.countNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
);
316 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
317 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
318 results
= dao
.searchNames(uninomial
, infraGenericEpithet
, specificEpithet
, infraspecificEpithet
, rank
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
321 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
325 * @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
327 public List
<UuidAndTitleCache
> getUuidAndTitleCacheOfNames() {
328 return dao
.getUuidAndTitleCacheOfNames();
331 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
) {
332 Integer numberOfResults
= dao
.countByName(clazz
, queryString
, matchmode
, criteria
);
334 List
<TaxonNameBase
> results
= new ArrayList
<TaxonNameBase
>();
335 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
336 results
= dao
.findByName(clazz
, queryString
, matchmode
, criteria
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
339 return new DefaultPagerImpl
<TaxonNameBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
342 public HomotypicalGroup
findHomotypicalGroup(UUID uuid
) {
343 return homotypicalGroupDao
.findByUuid(uuid
);
348 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
351 public void updateTitleCache(Class
<?
extends TaxonNameBase
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<TaxonNameBase
> cacheStrategy
, IProgressMonitor monitor
) {
353 clazz
= TaxonNameBase
.class;
355 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
360 protected void setOtherCachesNull(TaxonNameBase name
) {
361 if (name
.isInstanceOf(NonViralName
.class)){
362 NonViralName nvn
= CdmBase
.deproxy(name
, NonViralName
.class);
363 if (! nvn
.isProtectedNameCache()){
364 nvn
.setNameCache(null, false);
366 if (! nvn
.isProtectedAuthorshipCache()){
367 nvn
.setAuthorshipCache(null, false);
369 if (! nvn
.isProtectedFullTitleCache()){
370 nvn
.setFullTitleCache(null, false);
376 * @see eu.etaxonomy.cdm.api.service.INameService#getTaggedName(eu.etaxonomy.cdm.model.name.TaxonNameBase)
379 public List
<TaggedText
> getTaggedName(UUID uuid
) {
380 TaxonNameBase taxonNameBase
= dao
.load(uuid
);
381 return TaggedTextGenerator
.getTaggedName(taxonNameBase
);