Project

General

Profile

Download (6.83 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.UUID;
15

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

    
21
import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
22
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
23
import eu.etaxonomy.cdm.model.common.DefinedTerm;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.model.reference.ReferenceType;
26
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
27
import eu.etaxonomy.cdm.persistence.dao.common.ICdmGenericDao;
28
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
29
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
30
import eu.etaxonomy.cdm.persistence.query.MatchMode;
31
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
32

    
33

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

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

    
40
    @Autowired
41
    private ICdmGenericDao genericDao;
42
    /**
43
     * Constructor
44
     */
45
    public ReferenceServiceImpl(){
46
        if (logger.isDebugEnabled()) { logger.debug("Load ReferenceService Bean"); }
47
    }
48

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

    
58

    
59
    @Override
60
    protected void setOtherCachesNull(Reference ref) {
61
        if (! ref.isProtectedAbbrevTitleCache()){
62
            ref.setAbbrevTitleCache(null, false);
63
        }
64
    }
65

    
66

    
67
    @Override
68
    @Autowired
69
    protected void setDao(IReferenceDao dao) {
70
        this.dao = dao;
71
    }
72

    
73
    @Override
74
    public List<UuidAndTitleCache<Reference>> getUuidAndTitle() {
75

    
76
        return dao.getUuidAndTitle();
77
    }
78

    
79
    @Override
80
    public List<Reference> getAllReferencesForPublishing(){
81
        return dao.getAllNotNomenclaturalReferencesForPublishing();
82
    }
83

    
84
    @Override
85
    public List<Reference> getAllNomenclaturalReferences() {
86

    
87
        return dao.getAllNomenclaturalReferences();
88
    }
89

    
90
    @Override
91
    public List<TaxonBase> listCoveredTaxa(Reference reference, boolean includeSubordinateReferences, List<String> propertyPaths) {
92

    
93
        List<TaxonBase> taxonList = dao.listCoveredTaxa(reference, includeSubordinateReferences, null, propertyPaths);
94

    
95
        return taxonList;
96
    }
97

    
98
    @Override
99
    public DeleteResult delete(Reference reference) {
100
        //check whether the reference is used somewhere
101
        DeleteResult result = isDeletable(reference.getUuid(), null);
102

    
103
        if (result.isOk()){
104
            dao.delete(reference);
105
            result.addDeletedObject(reference);
106
        }
107

    
108
        return result;
109
    }
110

    
111
    @Override
112
    @Transactional(readOnly=false)
113
    public DeleteResult delete(UUID referenceUuid) {
114
        return delete(dao.load(referenceUuid));
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
119
     */
120
    @Override
121
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern) {
122
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, null);
123
    }
124

    
125
    /* (non-Javadoc)
126
     * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
127
     */
128
    @Override
129
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCache(Integer limit, String pattern, ReferenceType type) {
130
        ReferenceType inReferenceType = null;
131
        inReferenceType = getInReferenceType(type);
132
        return dao.getUuidAndAbbrevTitleCache(limit, pattern, inReferenceType);
133
    }
134

    
135
    /* (non-Javadoc)
136
     * @see eu.etaxonomy.cdm.api.service.IReferenceService#getUuidAndAbbrevTitleCache(java.lang.Integer, java.lang.String)
137
     */
138
    @Override
139
    public List<UuidAndTitleCache<Reference>> getUuidAndAbbrevTitleCacheForAuthor(Integer limit, String pattern, ReferenceType type) {
140
        return dao.getUuidAndAbbrevTitleCacheForAuthor(limit, pattern, null);
141
    }
142

    
143
    @Override
144
    public List<UuidAndTitleCache<Reference>> getUuidAndTitleCache(Integer limit, String pattern, ReferenceType type) {
145
        ReferenceType inReferenceType = null;
146
        inReferenceType = getInReferenceType(type);
147
        return dao.getUuidAndTitleCache(limit, pattern, inReferenceType);
148
    }
149

    
150

    
151
    @Transactional(readOnly = true)
152
    @Override
153
    public List<IdentifiedEntityDTO<Reference>> listByIdentifierAbbrev(
154
            String identifier, DefinedTerm identifierType, MatchMode matchmode,
155
            Integer limit) {
156

    
157
        Integer numberOfResults = dao.countByIdentifier(Reference.class, identifier, identifierType, matchmode);
158
        List<Object[]> daoResults = new ArrayList<Object[]>();
159
        if(numberOfResults > 0) { // no point checking again
160
            daoResults = dao.findByIdentifierAbbrev( identifier, identifierType,
161
                    matchmode,  limit);
162
        }
163

    
164
        List<IdentifiedEntityDTO<Reference>> result = new ArrayList<IdentifiedEntityDTO<Reference>>();
165
        for (Object[] daoObj : daoResults){
166
            result.add(new IdentifiedEntityDTO<Reference>((DefinedTerm)daoObj[0], (String)daoObj[1], (UUID)daoObj[2], (String)daoObj[3],(String)daoObj[4]));
167

    
168
        }
169
        return result;
170
    }
171

    
172

    
173
    private ReferenceType getInReferenceType(ReferenceType type){
174
        ReferenceType inReferenceType = null;
175
        if (type.equals(ReferenceType.Article)){
176
            inReferenceType = ReferenceType.Journal;
177
        } else if (type.equals(ReferenceType.BookSection)){
178
            inReferenceType = ReferenceType.Book;
179
        } else if (type.equals(ReferenceType.InProceedings) ){
180
            inReferenceType = ReferenceType.Proceedings;
181
        } else if (type.equals(ReferenceType.Book) || type.equals(ReferenceType.Proceedings)){
182
            inReferenceType = ReferenceType.PrintSeries;
183
        } else if (type.equals(ReferenceType.Generic)){
184
            inReferenceType = ReferenceType.Generic;
185
        }
186
        return inReferenceType;
187
    }
188

    
189
}
(88-88/105)