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