Project

General

Profile

Download (6.25 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.Transactional;
22

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

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

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

    
52
    @Autowired
53
    protected ITermVocabularyDao vocabularyDao;
54

    
55
    @Autowired
56
    protected IDefinedTermDao definedTermDao;
57

    
58
    @Autowired
59
    protected IOrderedTermVocabularyDao orderedVocabularyDao;
60

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

    
69

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

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

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

    
101
        UUID namedAreaVocabularyUuid = null;
102

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

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

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

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

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

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

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

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

    
160
        return topLevelTerms;
161
    }
162

    
163

    
164

    
165
}
(69-69/98)