Project

General

Profile

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

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

    
13
import java.util.ArrayList;
14
import java.util.Iterator;
15
import java.util.List;
16
import java.util.UUID;
17

    
18
import org.apache.log4j.Logger;
19
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.stereotype.Service;
21
import org.springframework.transaction.annotation.Propagation;
22
import org.springframework.transaction.annotation.Transactional;
23

    
24
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
25
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
26
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
27
import eu.etaxonomy.cdm.model.common.TermVocabulary;
28
import eu.etaxonomy.cdm.model.description.AbsenceTerm;
29
import eu.etaxonomy.cdm.model.description.PresenceTerm;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
32
import eu.etaxonomy.cdm.model.location.NamedAreaType;
33
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
34
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;
35
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
36

    
37
/**
38
 * Quick and dirty implementation of a location service as needed by the editor
39
 *
40
 * @author n.hoffman
41
 * @created 08.04.2009
42
 * @version 1.0
43
 */
44
@Service
45
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
46
public class LocationServiceImpl extends ServiceBase<DefinedTermBase,IDefinedTermDao> implements ILocationService {
47

    
48
    private static final Logger logger = Logger.getLogger(LocationServiceImpl.class);
49

    
50
    @Autowired
51
    protected ITermVocabularyDao vocabularyDao;
52

    
53
    @Autowired
54
    protected IDefinedTermDao definedTermDao;
55

    
56
    @Autowired
57
    protected IOrderedTermVocabularyDao orderedVocabularyDao;
58

    
59
    /* (non-Javadoc)
60
     * @see eu.etaxonomy.cdm.api.service.ServiceBase#setDao(eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao)
61
     */
62
    @Override
63
    protected void setDao(IDefinedTermDao dao) {
64
        this.dao = dao;
65
    }
66

    
67
    /**
68
     *  (non-Javadoc)
69
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getAbsenceTerms()
70
     * FIXME Candidate for harmonization
71
     * is this method a duplicate of termService.getVocabulary(VocabularyEnum.AbsenceTerm)?
72
     */
73
    public OrderedTermVocabulary<AbsenceTerm> getAbsenceTermVocabulary() {
74
        String uuidString = "5cd438c8-a8a1-4958-842e-169e83e2ceee";
75
        UUID uuid = UUID.fromString(uuidString);
76
        OrderedTermVocabulary<AbsenceTerm> absenceTermVocabulary =
77
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
78
        return absenceTermVocabulary;
79
    }
80

    
81

    
82
    /**
83
     * (non-Javadoc)
84
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getPresenceTermVocabulary()
85
     * FIXME Candidate for harmonization
86
     * is this method a duplicate of termService.getVocabulary(VocabularyEnum.PresenceTerm)
87
     */
88
    public OrderedTermVocabulary<PresenceTerm> getPresenceTermVocabulary() {
89
        String uuidString = "adbbbe15-c4d3-47b7-80a8-c7d104e53a05";
90
        UUID uuid = UUID.fromString(uuidString);
91
        OrderedTermVocabulary<PresenceTerm> presenceTermVocabulary =
92
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
93
        return presenceTermVocabulary;
94
    }
95

    
96
    /* (non-Javadoc)
97
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaVocabularyTypes()
98
     */
99
    public List<NamedAreaVocabularyType> getNamedAreaVocabularyTypes() {
100
        List<NamedAreaVocabularyType> result = new ArrayList<NamedAreaVocabularyType>(3);
101
        result.add(NamedAreaVocabularyType.TDWG_AREA);
102
        result.add(NamedAreaVocabularyType.WATERBODY_OR_COUNTRY);
103
        result.add(NamedAreaVocabularyType.CONTINENT);
104
        return result;
105
    }
106

    
107
    /* (non-Javadoc)
108
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreas(java.lang.Object)
109
     */
110
    public OrderedTermVocabulary<NamedArea> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType) {
111

    
112
        UUID namedAreaVocabularyUuid = null;
113

    
114
        if(vocabularyType == NamedAreaVocabularyType.TDWG_AREA){
115
            namedAreaVocabularyUuid = UUID.fromString("1fb40504-d1d7-44b0-9731-374fbe6cac77");
116
        }
117
        if(vocabularyType == NamedAreaVocabularyType.CONTINENT){
118
            namedAreaVocabularyUuid = UUID.fromString("e72cbcb6-58f8-4201-9774-15d0c6abc128");
119
        }
120
        if(vocabularyType == NamedAreaVocabularyType.WATERBODY_OR_COUNTRY){
121
            namedAreaVocabularyUuid = UUID.fromString("006b1870-7347-4624-990f-e5ed78484a1a");
122
        }
123

    
124
        return (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(namedAreaVocabularyUuid);
125
    }
126

    
127
    /* (non-Javadoc)
128
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaLevelVocabulary()
129
     */
130
    public OrderedTermVocabulary<NamedAreaLevel> getNamedAreaLevelVocabulary() {
131
        // TODO return namedAreaLevel filtered by NamedAreaVocabularyType
132
        String uuidString = "49034253-27c8-4219-97e8-f8d987d3d122";
133
        UUID uuid = UUID.fromString(uuidString);
134
        OrderedTermVocabulary<NamedAreaLevel> namedAreaLevelVocabulary =
135
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
136
        return namedAreaLevelVocabulary;
137
    }
138

    
139
    /**
140
     * (non-Javadoc)
141
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaTypeVocabulary()
142
     * FIXME Candidate for harmonization
143
     * is this method a duplicate of termService.getVocabulary(VocabularyEnum.NamedAreaType)
144
     */
145
    public TermVocabulary<NamedAreaType> getNamedAreaTypeVocabulary() {
146
        String uuidString = "e51d52d6-965b-4f7d-900f-4ba9c6f5dd33";
147
        UUID uuid = UUID.fromString(uuidString);
148
        TermVocabulary<NamedAreaType> namedAreaTypeVocabulary =
149
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
150
        return namedAreaTypeVocabulary;
151
    }
152

    
153
    public List<NamedArea> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType){
154

    
155
        OrderedTermVocabulary<NamedArea> vocabulary = getNamedAreaVocabulary(vocabularyType);
156

    
157
        List<NamedArea> topLevelTerms = new ArrayList<NamedArea>();
158

    
159
//		for(NamedArea area : vocabulary){
160
        Iterator<NamedArea> it = vocabulary.iterator();
161
        while(it.hasNext()){
162

    
163
            NamedArea area =  HibernateProxyHelper.deproxy(it.next(), NamedArea.class);
164
            if(area.getPartOfWorkaround() == null){
165
                topLevelTerms.add(area);
166
            }
167
        }
168

    
169
        return topLevelTerms;
170
    }
171

    
172

    
173

    
174
}
(61-61/83)