Change WaterbodyOrCountry name to Country #3700
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / service / LocationServiceImpl.java
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 * NOTE: Current implementation does not support the IService methods like {@link #save(DefinedTermBase)}
41 * as no base dao is loaded by autowiring.
42 *
43 * @author n.hoffman
44 * @created 08.04.2009
45 * @version 1.0
46 */
47 @Service
48 @Transactional(readOnly = true)
49 public class LocationServiceImpl extends ServiceBase<DefinedTermBase,IDefinedTermDao> implements ILocationService {
50
51 @SuppressWarnings("unused")
52 private static final Logger logger = Logger.getLogger(LocationServiceImpl.class);
53
54 @Autowired
55 protected ITermVocabularyDao vocabularyDao;
56
57 @Autowired
58 protected IDefinedTermDao definedTermDao;
59
60 @Autowired
61 protected IOrderedTermVocabularyDao orderedVocabularyDao;
62
63 /* (non-Javadoc)
64 * @see eu.etaxonomy.cdm.api.service.ServiceBase#setDao(eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao)
65 */
66 @Override
67 protected void setDao(IDefinedTermDao dao) {
68 this.dao = dao;
69 }
70
71 /**
72 * (non-Javadoc)
73 * @see eu.etaxonomy.cdm.api.service.ILocationService#getAbsenceTerms()
74 * FIXME Candidate for harmonization
75 * is this method a duplicate of termService.getVocabulary(VocabularyEnum.AbsenceTerm)?
76 */
77 public OrderedTermVocabulary<AbsenceTerm> getAbsenceTermVocabulary() {
78 String uuidString = "5cd438c8-a8a1-4958-842e-169e83e2ceee";
79 UUID uuid = UUID.fromString(uuidString);
80 OrderedTermVocabulary<AbsenceTerm> absenceTermVocabulary =
81 (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
82 return absenceTermVocabulary;
83 }
84
85
86 /**
87 * (non-Javadoc)
88 * @see eu.etaxonomy.cdm.api.service.ILocationService#getPresenceTermVocabulary()
89 * FIXME Candidate for harmonization
90 * is this method a duplicate of termService.getVocabulary(VocabularyEnum.PresenceTerm)
91 */
92 public OrderedTermVocabulary<PresenceTerm> getPresenceTermVocabulary() {
93 String uuidString = "adbbbe15-c4d3-47b7-80a8-c7d104e53a05";
94 UUID uuid = UUID.fromString(uuidString);
95 OrderedTermVocabulary<PresenceTerm> presenceTermVocabulary =
96 (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
97 return presenceTermVocabulary;
98 }
99
100 /* (non-Javadoc)
101 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaVocabularyTypes()
102 */
103 public List<NamedAreaVocabularyType> getNamedAreaVocabularyTypes() {
104 List<NamedAreaVocabularyType> result = new ArrayList<NamedAreaVocabularyType>(3);
105 result.add(NamedAreaVocabularyType.TDWG_AREA);
106 result.add(NamedAreaVocabularyType.COUNTRY);
107 result.add(NamedAreaVocabularyType.WATERBODY);
108 result.add(NamedAreaVocabularyType.CONTINENT);
109 return result;
110 }
111
112 /* (non-Javadoc)
113 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreas(java.lang.Object)
114 */
115 public OrderedTermVocabulary<NamedArea> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType) {
116
117 UUID namedAreaVocabularyUuid = null;
118
119 if(vocabularyType == NamedAreaVocabularyType.TDWG_AREA){
120 namedAreaVocabularyUuid = UUID.fromString("1fb40504-d1d7-44b0-9731-374fbe6cac77");
121 }
122 if(vocabularyType == NamedAreaVocabularyType.CONTINENT){
123 namedAreaVocabularyUuid = UUID.fromString("e72cbcb6-58f8-4201-9774-15d0c6abc128");
124 }
125 if(vocabularyType == NamedAreaVocabularyType.COUNTRY){
126 namedAreaVocabularyUuid = UUID.fromString("006b1870-7347-4624-990f-e5ed78484a1a");
127 }
128 if(vocabularyType == NamedAreaVocabularyType.WATERBODY){
129 namedAreaVocabularyUuid = UUID.fromString("35a62b25-f541-4f12-a7c7-17d90dec3e03");
130 }
131 return (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(namedAreaVocabularyUuid);
132 }
133
134 /* (non-Javadoc)
135 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaLevelVocabulary()
136 */
137 public OrderedTermVocabulary<NamedAreaLevel> getNamedAreaLevelVocabulary() {
138 // TODO return namedAreaLevel filtered by NamedAreaVocabularyType
139 String uuidString = "49034253-27c8-4219-97e8-f8d987d3d122";
140 UUID uuid = UUID.fromString(uuidString);
141 OrderedTermVocabulary<NamedAreaLevel> namedAreaLevelVocabulary =
142 (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
143 return namedAreaLevelVocabulary;
144 }
145
146 /**
147 * (non-Javadoc)
148 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaTypeVocabulary()
149 * FIXME Candidate for harmonization
150 * is this method a duplicate of termService.getVocabulary(VocabularyEnum.NamedAreaType)
151 */
152 public TermVocabulary<NamedAreaType> getNamedAreaTypeVocabulary() {
153 String uuidString = "e51d52d6-965b-4f7d-900f-4ba9c6f5dd33";
154 UUID uuid = UUID.fromString(uuidString);
155 TermVocabulary<NamedAreaType> namedAreaTypeVocabulary =
156 (OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
157 return namedAreaTypeVocabulary;
158 }
159
160 public List<NamedArea> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType){
161
162 OrderedTermVocabulary<NamedArea> vocabulary = getNamedAreaVocabulary(vocabularyType);
163
164 List<NamedArea> topLevelTerms = new ArrayList<NamedArea>();
165
166 // for(NamedArea area : vocabulary){
167 Iterator<NamedArea> it = vocabulary.iterator();
168 while(it.hasNext()){
169
170 NamedArea area = HibernateProxyHelper.deproxy(it.next(), NamedArea.class);
171 if(area.getPartOfWorkaround() == null){
172 topLevelTerms.add(area);
173 }
174 }
175
176 return topLevelTerms;
177 }
178
179
180
181 }