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
.logging
.log4j
.LogManager
;
18 import org
.apache
.logging
.log4j
.Logger
;
19 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
20 import org
.springframework
.stereotype
.Service
;
21 import org
.springframework
.transaction
.annotation
.Transactional
;
23 import eu
.etaxonomy
.cdm
.api
.service
.config
.IIdentifiableEntityServiceConfigurator
;
24 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IdentifiedEntityDTO
;
25 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
29 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
30 import eu
.etaxonomy
.cdm
.persistence
.dao
.reference
.IReferenceDao
;
31 import eu
.etaxonomy
.cdm
.persistence
.dto
.UuidAndTitleCache
;
32 import eu
.etaxonomy
.cdm
.persistence
.query
.MatchMode
;
33 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
37 @Transactional(readOnly
= true)
38 public class ReferenceServiceImpl
extends IdentifiableServiceBase
<Reference
,IReferenceDao
> implements IReferenceService
{
40 private static final Logger logger
= LogManager
.getLogger();
42 public ReferenceServiceImpl(){
43 if (logger
.isDebugEnabled()) { logger
.debug("Load ReferenceService Bean"); }
47 @Transactional(readOnly
= false)
48 public UpdateResult
updateCaches(Class
<?
extends Reference
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<Reference
> cacheStrategy
, IProgressMonitor monitor
) {
50 clazz
= Reference
.class;
52 return super.updateCachesImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
57 protected void setDao(IReferenceDao dao
) {
62 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitle() {
63 return dao
.getUuidAndTitle();
67 public List
<Reference
> listReferencesForPublishing(){
68 return dao
.getAllNotNomenclaturalReferencesForPublishing();
72 public List
<Reference
> listNomenclaturalReferences() {
73 return dao
.getAllNomenclaturalReferences();
77 public List
<TaxonBase
> listCoveredTaxa(Reference reference
, boolean includeSubordinateReferences
, List
<String
> propertyPaths
) {
78 List
<TaxonBase
> taxonList
= dao
.listCoveredTaxa(reference
, includeSubordinateReferences
, null, propertyPaths
);
83 public DeleteResult
delete(Reference reference
) {
84 //check whether the reference is used somewhere
85 DeleteResult result
= isDeletable(reference
.getUuid(), null);
88 dao
.delete(reference
);
89 result
.addDeletedObject(reference
);
96 @Transactional(readOnly
=false)
97 public DeleteResult
delete(UUID referenceUuid
) {
98 return delete(dao
.load(referenceUuid
));
102 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCache(Integer limit
, String pattern
) {
103 return dao
.getUuidAndAbbrevTitleCache(limit
, pattern
, null);
107 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCache(Integer limit
, String pattern
, ReferenceType type
) {
108 ReferenceType inReferenceType
= null;
109 inReferenceType
= getInReferenceType(type
);
110 return dao
.getUuidAndAbbrevTitleCache(limit
, pattern
, inReferenceType
);
114 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCacheForAuthor(Integer limit
, String pattern
, ReferenceType type
) {
115 return dao
.getUuidAndAbbrevTitleCacheForAuthor(limit
, pattern
, null);
119 public List
<UuidAndTitleCache
<Reference
>> getUuidAndAbbrevTitleCacheForAuthorID(Integer limit
, Integer authorID
, ReferenceType type
) {
120 return dao
.getUuidAndAbbrevTitleCacheForAuthorID(limit
, authorID
, null);
124 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitleCache(Integer limit
, String pattern
, ReferenceType type
) {
125 ReferenceType inReferenceType
= null;
126 inReferenceType
= getInReferenceType(type
);
127 return dao
.getUuidAndTitleCache(limit
, pattern
, inReferenceType
);
131 @Transactional(readOnly
= true)
133 public List
<IdentifiedEntityDTO
<Reference
>> listByIdentifierAbbrev(
134 String identifier
, DefinedTerm identifierType
, MatchMode matchmode
,
137 long numberOfResults
= dao
.countByIdentifier(Reference
.class, identifier
, identifierType
, matchmode
);
138 List
<Object
[]> daoResults
= new ArrayList
<Object
[]>();
139 if(numberOfResults
> 0) { // no point checking again
140 daoResults
= dao
.findByIdentifierAbbrev( identifier
, identifierType
,
144 List
<IdentifiedEntityDTO
<Reference
>> result
= new ArrayList
<>();
145 for (Object
[] daoObj
: daoResults
){
146 result
.add(new IdentifiedEntityDTO
<Reference
>((DefinedTerm
)daoObj
[0], (String
)daoObj
[1], (UUID
)daoObj
[2], (String
)daoObj
[3],(String
)daoObj
[4]));
152 @Transactional(readOnly
= true)
154 public List
<IdentifiedEntityDTO
<Reference
>> listByIdentifierAndTitleCacheAbbrev(
155 String identifier
, DefinedTerm identifierType
, MatchMode matchmode
,
158 long numberOfResults
= dao
.countByIdentifier(Reference
.class, identifier
, identifierType
, matchmode
);
159 long numberOfResultsTitle
= dao
.countByTitle(identifier
);
160 List
<Object
[]> daoResults
= new ArrayList
<>();
161 List
<UuidAndTitleCache
<Reference
>> daoResultsTitle
= new ArrayList();
162 if(numberOfResults
> 0) { // no point checking again
163 daoResults
= dao
.findByIdentifierAbbrev( identifier
, identifierType
,
166 daoResultsTitle
= dao
.getUuidAndAbbrevTitleCache(100, identifier
, null);
168 List
<IdentifiedEntityDTO
<Reference
>> result
= new ArrayList
<>();
169 for (Object
[] daoObj
: daoResults
){
170 result
.add(new IdentifiedEntityDTO
<Reference
>((DefinedTerm
)daoObj
[0], (String
)daoObj
[1], (UUID
)daoObj
[2], (String
)daoObj
[3],(String
)daoObj
[4]));
173 for (UuidAndTitleCache
<Reference
> uuidAndTitleCache
: daoResultsTitle
){
174 result
.add(new IdentifiedEntityDTO
<>(null, null, uuidAndTitleCache
.getUuid(), uuidAndTitleCache
.getTitleCache(), uuidAndTitleCache
.getAbbrevTitleCache()));
180 private ReferenceType
getInReferenceType(ReferenceType type
){
181 ReferenceType inReferenceType
= null;
182 if (type
.equals(ReferenceType
.Article
)){
183 inReferenceType
= ReferenceType
.Journal
;
184 } else if (type
.equals(ReferenceType
.BookSection
)){
185 inReferenceType
= ReferenceType
.Book
;
186 } else if (type
.equals(ReferenceType
.InProceedings
) ){
187 inReferenceType
= ReferenceType
.Proceedings
;
188 } else if (type
.equals(ReferenceType
.Book
) || type
.equals(ReferenceType
.Proceedings
)){
189 inReferenceType
= ReferenceType
.PrintSeries
;
190 } else if (type
.equals(ReferenceType
.Generic
)){
191 inReferenceType
= ReferenceType
.Generic
;
193 return inReferenceType
;
197 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitleCacheForUUIDS(Set
<UUID
> uuids
, ReferenceType refType
) {
198 return dao
.getUuidAndTitle(uuids
, getInReferenceType(refType
));
202 public List
<UuidAndTitleCache
<Reference
>> getUuidAndTitleCacheForUUIDS(Set
<UUID
> uuids
) {
203 return dao
.getUuidAndTitle(uuids
);
207 public List
<Reference
> findByTitleAndAbbrevTitle(IIdentifiableEntityServiceConfigurator
<Reference
> config
){
208 return dao
.findByTitleAndAbbrevTitle(config
.getClazz(),config
.getTitleSearchStringSqlized(), config
.getMatchMode(), config
.getCriteria(), config
.getPageSize(), config
.getPageNumber(), config
.getOrderHints(), config
.getPropertyPaths());