2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.api
.service
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Iterator
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
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
;
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
;
35 * Quick and dirty implementation of a location service as needed by the editor.
37 * NOTE: Current implementation does not support the IService methods like {@link #save(DefinedTermBase)}
38 * as no base dao is loaded by autowiring.
45 @Transactional(readOnly
= true)
46 public class LocationServiceImpl
extends ServiceBase
<DefinedTermBase
,IDefinedTermDao
> implements ILocationService
{
48 @SuppressWarnings("unused")
49 private static final Logger logger
= Logger
.getLogger(LocationServiceImpl
.class);
52 protected ITermVocabularyDao vocabularyDao
;
55 protected IDefinedTermDao definedTermDao
;
58 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
61 * @see eu.etaxonomy.cdm.api.service.ServiceBase#setDao(eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao)
64 protected void setDao(IDefinedTermDao dao
) {
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)
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
;
84 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaVocabularyTypes()
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
);
96 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreas(java.lang.Object)
98 public OrderedTermVocabulary
<NamedArea
> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType
) {
100 UUID namedAreaVocabularyUuid
= null;
102 if(vocabularyType
== NamedAreaVocabularyType
.TDWG_AREA
){
103 namedAreaVocabularyUuid
= UUID
.fromString("1fb40504-d1d7-44b0-9731-374fbe6cac77");
105 if(vocabularyType
== NamedAreaVocabularyType
.CONTINENT
){
106 namedAreaVocabularyUuid
= UUID
.fromString("e72cbcb6-58f8-4201-9774-15d0c6abc128");
108 if(vocabularyType
== NamedAreaVocabularyType
.COUNTRY
){
109 namedAreaVocabularyUuid
= UUID
.fromString("006b1870-7347-4624-990f-e5ed78484a1a");
111 if(vocabularyType
== NamedAreaVocabularyType
.WATERBODY
){
112 namedAreaVocabularyUuid
= UUID
.fromString("35a62b25-f541-4f12-a7c7-17d90dec3e03");
114 return (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(namedAreaVocabularyUuid
);
118 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaLevelVocabulary()
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
;
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)
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
;
143 public List
<NamedArea
> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType
){
145 OrderedTermVocabulary
<NamedArea
> vocabulary
= getNamedAreaVocabulary(vocabularyType
);
147 List
<NamedArea
> topLevelTerms
= new ArrayList
<NamedArea
>();
149 // for(NamedArea area : vocabulary){
150 Iterator
<NamedArea
> it
= vocabulary
.iterator();
153 NamedArea area
= HibernateProxyHelper
.deproxy(it
.next(), NamedArea
.class);
154 if(area
.getPartOfWorkaround() == null){
155 topLevelTerms
.add(area
);
159 return topLevelTerms
;