Project

General

Profile

Download (8.44 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
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.
8
 */
9

    
10
package eu.etaxonomy.cdm.api.service;
11

    
12
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
18
import org.springframework.beans.factory.annotation.Autowired;
19
import org.springframework.stereotype.Service;
20
import org.springframework.transaction.annotation.Transactional;
21

    
22
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
23
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
24
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
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.model.term.DefinedTerm;
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;
33

    
34

    
35
@Service
36
@Transactional(readOnly = true)
37
public class ReferenceServiceImpl extends IdentifiableServiceBase<Reference,IReferenceDao> implements IReferenceService {
38

    
39
    static Logger logger = LogManager.getLogger(ReferenceServiceImpl.class);
40

    
41
    /**
42
     * Constructor
43
     */
44
    public ReferenceServiceImpl(){
45
        if (logger.isDebugEnabled()) { logger.debug("Load ReferenceService Bean"); }
46
    }
47

    
48
    @Override
49
    @Transactional(readOnly = false)
50
    public UpdateResult updateCaches(Class<? extends Reference> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<Reference> cacheStrategy, IProgressMonitor monitor) {
51
        if (clazz == null){
52
            clazz = Reference.class;
53
        }
54
        return super.updateCachesImpl(clazz, stepSize, cacheStrategy, monitor);
55
    }
56

    
57
    @Override
58
    @Autowired
59
    protected void setDao(IReferenceDao dao) {
60
        this.dao = dao;
61
    }
62

    
63
    @Override
64
    public List<UuidAndTitleCache<Reference>> getUuidAndTitle() {
65
        return dao.getUuidAndTitle();
66
    }
67

    
68
    @Override
69
    public List<Reference> listReferencesForPublishing(){
70
        return dao.getAllNotNomenclaturalReferencesForPublishing();
71
    }
72

    
73
    @Override
74
    public List<Reference> listNomenclaturalReferences() {
75
        return dao.getAllNomenclaturalReferences();
76
    }
77

    
78
    @Override
79
    public List<TaxonBase> listCoveredTaxa(Reference reference, boolean includeSubordinateReferences, List<String> propertyPaths) {
80
        List<TaxonBase> taxonList = dao.listCoveredTaxa(reference, includeSubordinateReferences, null, propertyPaths);
81
        return taxonList;
82
    }
83

    
84
    @Override
85
    public DeleteResult delete(Reference reference) {
86
        //check whether the reference is used somewhere
87
        DeleteResult result = isDeletable(reference.getUuid(), null);
88

    
89
        if (result.isOk()){
90
            dao.delete(reference);
91
            result.addDeletedObject(reference);
92
        }
93

    
94
        return result;
95
    }
96

    
97
    @Override
98
    @Transactional(readOnly=false)
99
    public DeleteResult delete(UUID referenceUuid) {
100
        return delete(dao.load(referenceUuid));
101
    }
102

    
103
    @Override
104
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern) {
105
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, null);
106
    }
107

    
108
    @Override
109
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type) {
110
        ReferenceType inReferenceType = null;
111
        inReferenceType = getInReferenceType(type);
112
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, inReferenceType);
113
    }
114

    
115
    @Override
116
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCacheForAuthor(Integer limit, String pattern, ReferenceType type) {
117
        return dao.getUuidAndAbbrevTitleCacheForAuthor(limit, pattern, null);
118
    }
119
    
120
    @Override
121
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCacheForAuthorID(Integer limit, Integer authorID, ReferenceType type) {
122
        return dao.getUuidAndAbbrevTitleCacheForAuthorID(limit, authorID, null);
123
    }
124

    
125
    @Override
126
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType type) {
127
        ReferenceType inReferenceType = null;
128
        inReferenceType = getInReferenceType(type);
129
        return dao.getUuidAndTitleCache(limit, pattern, inReferenceType);
130
    }
131

    
132

    
133
    @Transactional(readOnly = true)
134
    @Override
135
    public List<IdentifiedEntityDTO<Reference>> listByIdentifierAbbrev(
136
            String identifier, DefinedTerm identifierType, MatchMode matchmode,
137
            Integer limit) {
138

    
139
        long numberOfResults = dao.countByIdentifier(Reference.class, identifier, identifierType, matchmode);
140
        List<Object[]> daoResults = new ArrayList<Object[]>();
141
        if(numberOfResults > 0) { // no point checking again
142
            daoResults = dao.findByIdentifierAbbrev( identifier, identifierType,
143
                    matchmode,  limit);
144
        }
145

    
146
        List<IdentifiedEntityDTO<Reference>> result = new ArrayList<>();
147
        for (Object[] daoObj : daoResults){
148
            result.add(new IdentifiedEntityDTO<Reference>((DefinedTerm)daoObj[0], (String)daoObj[1], (UUID)daoObj[2], (String)daoObj[3],(String)daoObj[4]));
149

    
150
        }
151
        return result;
152
    }
153

    
154
    @Transactional(readOnly = true)
155
    @Override
156
    public List<IdentifiedEntityDTO<Reference>> listByIdentifierAndTitleCacheAbbrev(
157
            String identifier, DefinedTerm identifierType, MatchMode matchmode,
158
            Integer limit) {
159

    
160
        long numberOfResults = dao.countByIdentifier(Reference.class, identifier, identifierType, matchmode);
161
        long numberOfResultsTitle = dao.countByTitle(identifier);
162
        List<Object[]> daoResults = new ArrayList<>();
163
        List<UuidAndTitleCache<Reference>> daoResultsTitle = new ArrayList();
164
        if(numberOfResults > 0) { // no point checking again
165
            daoResults = dao.findByIdentifierAbbrev( identifier, identifierType,
166
                    matchmode,  limit);
167
        }
168
        daoResultsTitle = dao.getUuidAndAbbrevTitleCache(100, identifier, null);
169

    
170
        List<IdentifiedEntityDTO<Reference>> result = new ArrayList<>();
171
        for (Object[] daoObj : daoResults){
172
            result.add(new IdentifiedEntityDTO<Reference>((DefinedTerm)daoObj[0], (String)daoObj[1], (UUID)daoObj[2], (String)daoObj[3],(String)daoObj[4]));
173

    
174
        }
175
        for (UuidAndTitleCache<Reference> uuidAndTitleCache: daoResultsTitle){
176
            result.add(new IdentifiedEntityDTO<>(null, null, uuidAndTitleCache.getUuid(), uuidAndTitleCache.getTitleCache(), uuidAndTitleCache.getAbbrevTitleCache()));
177
        }
178
        return result;
179
    }
180

    
181

    
182
    private ReferenceType getInReferenceType(ReferenceType type){
183
        ReferenceType inReferenceType = null;
184
        if (type.equals(ReferenceType.Article)){
185
            inReferenceType = ReferenceType.Journal;
186
        } else if (type.equals(ReferenceType.BookSection)){
187
            inReferenceType = ReferenceType.Book;
188
        } else if (type.equals(ReferenceType.InProceedings) ){
189
            inReferenceType = ReferenceType.Proceedings;
190
        } else if (type.equals(ReferenceType.Book) || type.equals(ReferenceType.Proceedings)){
191
            inReferenceType = ReferenceType.PrintSeries;
192
        } else if (type.equals(ReferenceType.Generic)){
193
            inReferenceType = ReferenceType.Generic;
194
        }
195
        return inReferenceType;
196
    }
197

    
198
    /**
199
     * {@inheritDoc}
200
     */
201
    @Override
202
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCacheForUUIDS(Set<UUID> uuids, ReferenceType refType ) {
203

    
204
        return dao.getUuidAndTitle(uuids, getInReferenceType(refType));
205

    
206
    }
207

    
208
    /**
209
     * {@inheritDoc}
210
     */
211
    @Override
212
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCacheForUUIDS(Set<UUID> uuids ) {
213
        return dao.getUuidAndTitle(uuids);
214

    
215
    }
216

    
217
    @Override
218
    public List<Reference> findByTitleAndAbbrevTitle(IIdentifiableEntityServiceConfigurator<Reference> config){
219
        return dao.findByTitleAndAbbrevTitle(config.getClazz(),config.getTitleSearchStringSqlized(), config.getMatchMode(), config.getCriteria(), config.getPageSize(), config.getPageNumber(), config.getOrderHints(), config.getPropertyPaths());
220
    }
221

    
222
}
(78-78/95)