Project

General

Profile

Download (5.88 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.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.hibernate.HibernateProxyHelper;
23
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
24
import eu.etaxonomy.cdm.model.location.NamedArea;
25
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
26
import eu.etaxonomy.cdm.model.location.NamedAreaType;
27
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
28
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
29
import eu.etaxonomy.cdm.model.term.TermVocabulary;
30
import eu.etaxonomy.cdm.persistence.dao.term.IDefinedTermDao;
31
import eu.etaxonomy.cdm.persistence.dao.term.IOrderedTermVocabularyDao;
32
import eu.etaxonomy.cdm.persistence.dao.term.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
 * @since 08.04.2009
42
 */
43
@Service
44
@Transactional(readOnly = true)
45
public class LocationServiceImpl extends ServiceBase<DefinedTermBase,IDefinedTermDao> implements ILocationService {
46

    
47
    @SuppressWarnings("unused")
48
	private static final Logger logger = LogManager.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
    @Override
60
    protected void setDao(IDefinedTermDao dao) {
61
        this.dao = dao;
62
    }
63

    
64

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

    
81
    @Override
82
    public List<NamedAreaVocabularyType> getNamedAreaVocabularyTypes() {
83
        List<NamedAreaVocabularyType> result = new ArrayList<NamedAreaVocabularyType>(3);
84
        result.add(NamedAreaVocabularyType.TDWG_AREA);
85
        result.add(NamedAreaVocabularyType.COUNTRY);
86
        result.add(NamedAreaVocabularyType.WATERBODY);
87
        result.add(NamedAreaVocabularyType.CONTINENT);
88
        return result;
89
    }
90

    
91
    @Override
92
    public OrderedTermVocabulary<NamedArea> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType) {
93

    
94
        UUID namedAreaVocabularyUuid = null;
95

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

    
111
    @Override
112
    public OrderedTermVocabulary<NamedAreaLevel> getNamedAreaLevelVocabulary() {
113
        // TODO return namedAreaLevel filtered by NamedAreaVocabularyType
114
        String uuidString = "49034253-27c8-4219-97e8-f8d987d3d122";
115
        UUID uuid = UUID.fromString(uuidString);
116
        OrderedTermVocabulary<NamedAreaLevel> namedAreaLevelVocabulary =
117
            (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
118
        return namedAreaLevelVocabulary;
119
    }
120

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

    
136
    @Override
137
    public List<NamedArea> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType){
138

    
139
        OrderedTermVocabulary<NamedArea> vocabulary = getNamedAreaVocabulary(vocabularyType);
140

    
141
        List<NamedArea> topLevelTerms = new ArrayList<>();
142

    
143
//		for(NamedArea area : vocabulary){
144
        Iterator<NamedArea> it = vocabulary.getTerms().iterator();
145
        while(it.hasNext()){
146

    
147
            NamedArea area =  HibernateProxyHelper.deproxy(it.next(), NamedArea.class);
148
            if(area.getPartOfWorkaround() == null){
149
                topLevelTerms.add(area);
150
            }
151
        }
152

    
153
        return topLevelTerms;
154
    }
155

    
156

    
157

    
158
}
(66-66/95)