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
.List
;
15 import java
.util
.UUID
;
17 import org
.apache
.log4j
.Logger
;
18 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
19 import org
.springframework
.stereotype
.Service
;
20 import org
.springframework
.transaction
.annotation
.Transactional
;
22 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IdentifiedEntityDTO
;
23 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
24 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
28 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ICdmGenericDao
;
29 import eu
.etaxonomy
.cdm
.persistence
.dao
.reference
.IReferenceDao
;
30 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
31 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
32 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
36 @Transactional(readOnly
= true)
37 public class ReferenceServiceImpl
extends IdentifiableServiceBase
<Reference
,IReferenceDao
> implements IReferenceService
{
39 static Logger logger
= Logger
.getLogger(ReferenceServiceImpl
.class);
42 private ICdmGenericDao genericDao
;
46 public ReferenceServiceImpl(){
47 if (logger
.isDebugEnabled()) { logger
.debug("Load ReferenceService Bean"); }
51 @Transactional(readOnly
= false)
52 public void updateTitleCache(Class
<?
extends Reference
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<Reference
> cacheStrategy
, IProgressMonitor monitor
) {
54 clazz
= Reference
.class;
56 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
61 protected void setOtherCachesNull(Reference ref
) {
62 if (! ref
.isProtectedAbbrevTitleCache()){
63 ref
.setAbbrevTitleCache(null, false);
70 protected void setDao(IReferenceDao dao
) {
75 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitle() {
77 return dao
.getUuidAndTitle();
81 public List
<Reference
> getAllReferencesForPublishing(){
82 return dao
.getAllNotNomenclaturalReferencesForPublishing();
86 public List
<Reference
> getAllNomenclaturalReferences() {
88 return dao
.getAllNomenclaturalReferences();
92 public List
<TaxonBase
> listCoveredTaxa(Reference reference
, boolean includeSubordinateReferences
, List
<String
> propertyPaths
) {
94 List
<TaxonBase
> taxonList
= dao
.listCoveredTaxa(reference
, includeSubordinateReferences
, null, propertyPaths
);
100 public DeleteResult
delete(Reference reference
) {
101 //check whether the reference is used somewhere
102 DeleteResult result
= isDeletable(reference
.getUuid(), null);
105 dao
.delete(reference
);
106 result
.addDeletedObject(reference
);
113 @Transactional(readOnly
=false)
114 public DeleteResult
delete(UUID referenceUuid
) {
115 return delete(dao
.load(referenceUuid
));
119 * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
122 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCache(Integer limit
, String pattern
) {
123 return dao
.getUuidAndAbbrevTitleCache(limit
, pattern
, null);
127 * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
130 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCache(Integer limit
, String pattern
, ReferenceType type
) {
131 ReferenceType inReferenceType
= null;
132 inReferenceType
= getInReferenceType(type
);
133 return dao
.getUuidAndAbbrevTitleCache(limit
, pattern
, inReferenceType
);
137 * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
140 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCacheForAuthor(Integer limit
, String pattern
, ReferenceType type
) {
141 return dao
.getUuidAndAbbrevTitleCacheForAuthor(limit
, pattern
, null);
145 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitleCache(Integer limit
, String pattern
, ReferenceType type
) {
146 ReferenceType inReferenceType
= null;
147 inReferenceType
= getInReferenceType(type
);
148 return dao
.getUuidAndTitleCache(limit
, pattern
, inReferenceType
);
152 @Transactional(readOnly
= true)
154 public List
<IdentifiedEntityDTO
<Reference
>> listByIdentifierAbbrev(
155 String identifier
, DefinedTerm identifierType
, MatchMode matchmode
,
158 Integer numberOfResults
= dao
.countByIdentifier(Reference
.class, identifier
, identifierType
, matchmode
);
159 List
<Object
[]> daoResults
= new ArrayList
<Object
[]>();
160 if(numberOfResults
> 0) { // no point checking again
161 daoResults
= dao
.findByIdentifierAbbrev( identifier
, identifierType
,
165 List
<IdentifiedEntityDTO
<Reference
>> result
= new ArrayList
<IdentifiedEntityDTO
<Reference
>>();
166 for (Object
[] daoObj
: daoResults
){
167 result
.add(new IdentifiedEntityDTO
<Reference
>((DefinedTerm
)daoObj
[0], (String
)daoObj
[1], (UUID
)daoObj
[2], (String
)daoObj
[3],(String
)daoObj
[4]));
174 private ReferenceType
getInReferenceType(ReferenceType type
){
175 ReferenceType inReferenceType
= null;
176 if (type
.equals(ReferenceType
.Article
)){
177 inReferenceType
= ReferenceType
.Journal
;
178 } else if (type
.equals(ReferenceType
.BookSection
)){
179 inReferenceType
= ReferenceType
.Book
;
180 } else if (type
.equals(ReferenceType
.InProceedings
) ){
181 inReferenceType
= ReferenceType
.Proceedings
;
182 } else if (type
.equals(ReferenceType
.Book
) || type
.equals(ReferenceType
.Proceedings
)){
183 inReferenceType
= ReferenceType
.PrintSeries
;
184 } else if (type
.equals(ReferenceType
.Generic
)){
185 inReferenceType
= ReferenceType
.Generic
;
187 return inReferenceType
;
194 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitleCacheForUUIDS(Set
<UUID
> uuids
) {
195 return dao
.getUuidAndTitle(uuids
);