Project

General

Profile

Download (6.24 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.Iterator;
14
import java.util.List;
15
import java.util.UUID;
16

    
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;
21

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

    
34
/**
35
 * Quick and dirty implementation of a location service as needed by the editor.
36
 * 
37
 * NOTE: Current implementation does not support the IService methods like {@link #save(DefinedTermBase)}
38
 * as no base dao is loaded by autowiring.
39
 *
40
 * @author n.hoffman
41
 * @created 08.04.2009
42
 * @version 1.0
43
 */
44
@Service
45
@Transactional(readOnly = true)
46
public class LocationServiceImpl extends ServiceBase<DefinedTermBase,IDefinedTermDao> implements ILocationService {
47

    
48
    @SuppressWarnings("unused")
49
	private static final Logger logger = Logger.getLogger(LocationServiceImpl.class);
50

    
51
    @Autowired
52
    protected ITermVocabularyDao vocabularyDao;
53

    
54
    @Autowired
55
    protected IDefinedTermDao definedTermDao;
56

    
57
    @Autowired
58
    protected IOrderedTermVocabularyDao orderedVocabularyDao;
59

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

    
68

    
69
    /**
70
     * (non-Javadoc)
71
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getPresenceTermVocabulary()
72
     * FIXME Candidate for harmonization
73
     * is this method a duplicate of termService.getVocabulary(VocabularyEnum.PresenceTerm)
74
     */
75
    public OrderedTermVocabulary<PresenceAbsenceTerm> getPresenceAbsenceTermVocabulary() {
76
        String uuidString = "adbbbe15-c4d3-47b7-80a8-c7d104e53a05";
77
        UUID uuid = UUID.fromString(uuidString);
78
        OrderedTermVocabulary<PresenceAbsenceTerm> presenceTermVocabulary =
79
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
80
        return presenceTermVocabulary;
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaVocabularyTypes()
85
     */
86
    public List<NamedAreaVocabularyType> getNamedAreaVocabularyTypes() {
87
        List<NamedAreaVocabularyType> result = new ArrayList<NamedAreaVocabularyType>(3);
88
        result.add(NamedAreaVocabularyType.TDWG_AREA);
89
        result.add(NamedAreaVocabularyType.COUNTRY);
90
        result.add(NamedAreaVocabularyType.WATERBODY);
91
        result.add(NamedAreaVocabularyType.CONTINENT);
92
        return result;
93
    }
94

    
95
    /* (non-Javadoc)
96
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreas(java.lang.Object)
97
     */
98
    public OrderedTermVocabulary<NamedArea> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType) {
99

    
100
        UUID namedAreaVocabularyUuid = null;
101

    
102
        if(vocabularyType == NamedAreaVocabularyType.TDWG_AREA){
103
            namedAreaVocabularyUuid = UUID.fromString("1fb40504-d1d7-44b0-9731-374fbe6cac77");
104
        }
105
        if(vocabularyType == NamedAreaVocabularyType.CONTINENT){
106
            namedAreaVocabularyUuid = UUID.fromString("e72cbcb6-58f8-4201-9774-15d0c6abc128");
107
        }
108
        if(vocabularyType == NamedAreaVocabularyType.COUNTRY){
109
            namedAreaVocabularyUuid = UUID.fromString("006b1870-7347-4624-990f-e5ed78484a1a");
110
        }
111
        if(vocabularyType == NamedAreaVocabularyType.WATERBODY){
112
            namedAreaVocabularyUuid = UUID.fromString("35a62b25-f541-4f12-a7c7-17d90dec3e03");
113
        }
114
        return (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(namedAreaVocabularyUuid);
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaLevelVocabulary()
119
     */
120
    public OrderedTermVocabulary<NamedAreaLevel> getNamedAreaLevelVocabulary() {
121
        // TODO return namedAreaLevel filtered by NamedAreaVocabularyType
122
        String uuidString = "49034253-27c8-4219-97e8-f8d987d3d122";
123
        UUID uuid = UUID.fromString(uuidString);
124
        OrderedTermVocabulary<NamedAreaLevel> namedAreaLevelVocabulary =
125
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
126
        return namedAreaLevelVocabulary;
127
    }
128

    
129
    /**
130
     * (non-Javadoc)
131
     * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaTypeVocabulary()
132
     * FIXME Candidate for harmonization
133
     * is this method a duplicate of termService.getVocabulary(VocabularyEnum.NamedAreaType)
134
     */
135
    public TermVocabulary<NamedAreaType> getNamedAreaTypeVocabulary() {
136
        String uuidString = "e51d52d6-965b-4f7d-900f-4ba9c6f5dd33";
137
        UUID uuid = UUID.fromString(uuidString);
138
        TermVocabulary<NamedAreaType> namedAreaTypeVocabulary =
139
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
140
        return namedAreaTypeVocabulary;
141
    }
142

    
143
    public List<NamedArea> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType){
144

    
145
        OrderedTermVocabulary<NamedArea> vocabulary = getNamedAreaVocabulary(vocabularyType);
146

    
147
        List<NamedArea> topLevelTerms = new ArrayList<NamedArea>();
148

    
149
//		for(NamedArea area : vocabulary){
150
        Iterator<NamedArea> it = vocabulary.iterator();
151
        while(it.hasNext()){
152

    
153
            NamedArea area =  HibernateProxyHelper.deproxy(it.next(), NamedArea.class);
154
            if(area.getPartOfWorkaround() == null){
155
                topLevelTerms.add(area);
156
            }
157
        }
158

    
159
        return topLevelTerms;
160
    }
161

    
162

    
163

    
164
}
(71-71/101)