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
.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
;
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.
44 @Transactional(readOnly
= true)
45 public class LocationServiceImpl
extends ServiceBase
<DefinedTermBase
,IDefinedTermDao
> implements ILocationService
{
47 @SuppressWarnings("unused")
48 private static final Logger logger
= Logger
.getLogger(LocationServiceImpl
.class);
51 protected ITermVocabularyDao vocabularyDao
;
54 protected IDefinedTermDao definedTermDao
;
57 protected IOrderedTermVocabularyDao orderedVocabularyDao
;
60 * @see eu.etaxonomy.cdm.api.service.ServiceBase#setDao(eu.etaxonomy.cdm.persistence.dao.common.ICdmEntityDao)
63 protected void setDao(IDefinedTermDao dao
) {
70 * @see eu.etaxonomy.cdm.api.service.ILocationService#getPresenceTermVocabulary()
71 * FIXME Candidate for harmonization
72 * 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()
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
);
97 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreas(java.lang.Object)
100 public OrderedTermVocabulary
<NamedArea
> getNamedAreaVocabulary(NamedAreaVocabularyType vocabularyType
) {
102 UUID namedAreaVocabularyUuid
= null;
104 if(vocabularyType
== NamedAreaVocabularyType
.TDWG_AREA
){
105 namedAreaVocabularyUuid
= UUID
.fromString("1fb40504-d1d7-44b0-9731-374fbe6cac77");
107 if(vocabularyType
== NamedAreaVocabularyType
.CONTINENT
){
108 namedAreaVocabularyUuid
= UUID
.fromString("e72cbcb6-58f8-4201-9774-15d0c6abc128");
110 if(vocabularyType
== NamedAreaVocabularyType
.COUNTRY
){
111 namedAreaVocabularyUuid
= UUID
.fromString("006b1870-7347-4624-990f-e5ed78484a1a");
113 if(vocabularyType
== NamedAreaVocabularyType
.WATERBODY
){
114 namedAreaVocabularyUuid
= UUID
.fromString("35a62b25-f541-4f12-a7c7-17d90dec3e03");
116 return (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(namedAreaVocabularyUuid
);
120 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaLevelVocabulary()
123 public OrderedTermVocabulary
<NamedAreaLevel
> getNamedAreaLevelVocabulary() {
124 // TODO return namedAreaLevel filtered by NamedAreaVocabularyType
125 String uuidString
= "49034253-27c8-4219-97e8-f8d987d3d122";
126 UUID uuid
= UUID
.fromString(uuidString
);
127 OrderedTermVocabulary
<NamedAreaLevel
> namedAreaLevelVocabulary
=
128 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
129 return namedAreaLevelVocabulary
;
134 * @see eu.etaxonomy.cdm.api.service.ILocationService#getNamedAreaTypeVocabulary()
135 * FIXME Candidate for harmonization
136 * is this method a duplicate of termService.getVocabulary(VocabularyEnum.NamedAreaType)
139 public TermVocabulary
<NamedAreaType
> getNamedAreaTypeVocabulary() {
140 String uuidString
= "e51d52d6-965b-4f7d-900f-4ba9c6f5dd33";
141 UUID uuid
= UUID
.fromString(uuidString
);
142 TermVocabulary
<NamedAreaType
> namedAreaTypeVocabulary
=
143 (OrderedTermVocabulary
)orderedVocabularyDao
.findByUuid(uuid
);
144 return namedAreaTypeVocabulary
;
148 public List
<NamedArea
> getTopLevelNamedAreasByVocabularyType(NamedAreaVocabularyType vocabularyType
){
150 OrderedTermVocabulary
<NamedArea
> vocabulary
= getNamedAreaVocabulary(vocabularyType
);
152 List
<NamedArea
> topLevelTerms
= new ArrayList
<>();
154 // for(NamedArea area : vocabulary){
155 Iterator
<NamedArea
> it
= vocabulary
.getTerms().iterator();
158 NamedArea area
= HibernateProxyHelper
.deproxy(it
.next(), NamedArea
.class);
159 if(area
.getPartOfWorkaround() == null){
160 topLevelTerms
.add(area
);
164 return topLevelTerms
;