3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.service
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Service
;
23 import org
.springframework
.transaction
.annotation
.Propagation
;
24 import org
.springframework
.transaction
.annotation
.Transactional
;
26 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
27 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
28 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
29 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
31 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
32 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
33 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
34 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
35 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.Scope
;
37 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
40 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
41 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
42 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
45 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
46 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
47 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
48 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureDao
;
49 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
50 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureTreeDao
;
51 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IStatisticalMeasurementValueDao
;
52 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
60 @Transactional(readOnly
= true, propagation
= Propagation
.SUPPORTS
)
61 public class DescriptionServiceImpl
extends IdentifiableServiceBase
<DescriptionBase
,IDescriptionDao
> implements IDescriptionService
{
63 private static final Logger logger
= Logger
.getLogger(DescriptionServiceImpl
.class);
65 protected IDescriptionElementDao descriptionElementDao
;
66 protected IFeatureTreeDao featureTreeDao
;
67 protected IFeatureNodeDao featureNodeDao
;
68 protected IFeatureDao featureDao
;
69 protected ITermVocabularyDao vocabularyDao
;
70 protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao
;
73 protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao
) {
74 this.featureTreeDao
= featureTreeDao
;
78 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
79 this.featureNodeDao
= featureNodeDao
;
83 protected void setFeatureDao(IFeatureDao featureDao
) {
84 this.featureDao
= featureDao
;
88 protected void setVocabularyDao(ITermVocabularyDao vocabularyDao
) {
89 this.vocabularyDao
= vocabularyDao
;
93 protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao
) {
94 this.statisticalMeasurementValueDao
= statisticalMeasurementValueDao
;
98 protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao
) {
99 this.descriptionElementDao
= descriptionElementDao
;
105 public DescriptionServiceImpl() {
106 logger
.debug("Load DescriptionService Bean");
110 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#generateTitleCache()
112 public void generateTitleCache() {
113 logger
.warn("generateTitleCache not yet implemented");
116 public TermVocabulary
<Feature
> getDefaultFeatureVocabulary(){
117 String uuidFeature
= "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
118 UUID featureUuid
= UUID
.fromString(uuidFeature
);
119 return (TermVocabulary
)vocabularyDao
.findByUuid(featureUuid
);
123 protected void setDao(IDescriptionDao dao
) {
127 public int count(Class
<?
extends DescriptionBase
> type
, Boolean hasImages
, Boolean hasText
,Set
<Feature
> feature
) {
128 return dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
132 * FIXME Candidate for harmonization
133 * rename -> getElements
135 public Pager
<DescriptionElementBase
> getDescriptionElements(DescriptionBase description
,
136 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
138 List
<DescriptionElementBase
> results
= listDescriptionElements(description
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
139 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, results
.size(), pageSize
, results
);
142 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
,
143 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
144 Integer numberOfResults
= dao
.countDescriptionElements(description
, features
, type
);
146 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
147 if(numberOfResults
> 0) { // no point checking again
148 results
= dao
.getDescriptionElements(description
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
152 public Pager
<Annotation
> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj
, MarkerType status
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
153 Integer numberOfResults
= descriptionElementDao
.countAnnotations(annotatedObj
, status
);
155 List
<Annotation
> results
= new ArrayList
<Annotation
>();
156 if(numberOfResults
> 0) { // no point checking again
157 results
= descriptionElementDao
.getAnnotations(annotatedObj
, status
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
160 return new DefaultPagerImpl
<Annotation
>(pageNumber
, numberOfResults
, pageSize
, results
);
165 public Pager
<Media
> getMedia(DescriptionElementBase descriptionElement
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
166 Integer numberOfResults
= descriptionElementDao
.countMedia(descriptionElement
);
168 List
<Media
> results
= new ArrayList
<Media
>();
169 if(numberOfResults
> 0) { // no point checking again
170 results
= descriptionElementDao
.getMedia(descriptionElement
, pageSize
, pageNumber
, propertyPaths
);
173 return new DefaultPagerImpl
<Media
>(pageNumber
, numberOfResults
, pageSize
, results
);
176 public Pager
<TaxonDescription
> getTaxonDescriptions(Taxon taxon
, Set
<Scope
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
177 Integer numberOfResults
= dao
.countTaxonDescriptions(taxon
, scopes
, geographicalScope
);
179 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
180 if(numberOfResults
> 0) { // no point checking again
181 results
= dao
.getTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
184 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
187 public NamedAreaTree
getOrderedDistributions(Set
<TaxonDescription
> taxonDescriptions
, Set
<NamedAreaLevel
> omitLevels
){
188 List
<NamedArea
> areaList
= new ArrayList
<NamedArea
>();
189 NamedAreaTree tree
= new NamedAreaTree();
190 //getting all the areas
191 for (TaxonDescription taxonDescription
: taxonDescriptions
) {
192 taxonDescription
= (TaxonDescription
) dao
.load(taxonDescription
.getUuid());
193 Set
<DescriptionElementBase
> elements
= taxonDescription
.getElements();
194 for (DescriptionElementBase element
: elements
) {
195 if(element
.isInstanceOf(Distribution
.class)){
196 Distribution distribution
= (Distribution
) element
;
197 areaList
.add(distribution
.getArea());
202 tree
.merge(areaList
, omitLevels
);
207 public DistributionTree
getOrderedDistributionsB(
208 Set
<TaxonDescription
> taxonDescriptions
,
209 Set
<NamedAreaLevel
> omitLevels
){
211 DistributionTree tree
= new DistributionTree();
212 List
<Distribution
> distList
= new ArrayList
<Distribution
>();
214 for (TaxonDescription taxonDescription
: taxonDescriptions
) {
215 taxonDescription
= (TaxonDescription
) dao
.load(taxonDescription
.getUuid());
216 Set
<DescriptionElementBase
> elements
= taxonDescription
.getElements();
217 for (DescriptionElementBase element
: elements
) {
218 if(element
.isInstanceOf(Distribution
.class)){
219 Distribution distribution
= (Distribution
) element
;
220 distList
.add(distribution
);
226 tree
.merge(distList
, omitLevels
);
231 public Pager
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase name
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
232 Integer numberOfResults
= dao
.countTaxonNameDescriptions(name
);
234 List
<TaxonNameDescription
> results
= new ArrayList
<TaxonNameDescription
>();
235 if(numberOfResults
> 0) { // no point checking again
236 results
= dao
.getTaxonNameDescriptions(name
, pageSize
, pageNumber
,propertyPaths
);
239 return new DefaultPagerImpl
<TaxonNameDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
243 public Pager
<DescriptionBase
> page(Class
<?
extends DescriptionBase
> type
, Boolean hasImages
, Boolean hasText
, Set
<Feature
> feature
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
244 Integer numberOfResults
= dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
246 List
<DescriptionBase
> results
= new ArrayList
<DescriptionBase
>();
247 if(numberOfResults
> 0) { // no point checking again
248 results
= dao
.listDescriptions(type
, hasImages
, hasText
, feature
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
251 return new DefaultPagerImpl
<DescriptionBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
255 * FIXME Candidate for harmonization
256 * Rename: searchByDistribution
258 public Pager
<TaxonDescription
> searchDescriptionByDistribution(Set
<NamedArea
> namedAreas
, PresenceAbsenceTermBase presence
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
259 Integer numberOfResults
= dao
.countDescriptionByDistribution(namedAreas
, presence
);
261 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
262 if(numberOfResults
> 0) { // no point checking again
263 results
= dao
.searchDescriptionByDistribution(namedAreas
, presence
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
266 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
270 * FIXME Candidate for harmonization
271 * move: descriptionElementService.search
273 public Pager
<DescriptionElementBase
> searchElements(Class
<?
extends DescriptionElementBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
274 Integer numberOfResults
= descriptionElementDao
.count(clazz
,queryString
);
276 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
277 if(numberOfResults
> 0) { // no point checking again
278 results
= descriptionElementDao
.search(clazz
, queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
281 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
285 * FIXME Candidate for harmonization
286 * descriptionElementService.find
288 public DescriptionElementBase
getDescriptionElementByUuid(UUID uuid
) {
289 return descriptionElementDao
.findByUuid(uuid
);
293 * FIXME Candidate for harmonization
294 * descriptionElementService.load
296 public DescriptionElementBase
loadDescriptionElement(UUID uuid
, List
<String
> propertyPaths
) {
297 return descriptionElementDao
.load(uuid
, propertyPaths
);
301 * FIXME Candidate for harmonization
302 * descriptionElementService.save
304 @Transactional(readOnly
= false)
305 public UUID
saveDescriptionElement(DescriptionElementBase descriptionElement
) {
306 return descriptionElementDao
.save(descriptionElement
);
310 * FIXME Candidate for harmonization
311 * descriptionElementService.save
313 @Transactional(readOnly
= false)
314 public Map
<UUID
, DescriptionElementBase
> saveDescriptionElement(Collection
<DescriptionElementBase
> descriptionElements
) {
315 return descriptionElementDao
.saveAll(descriptionElements
);
319 * FIXME Candidate for harmonization
320 * descriptionElementService.delete
322 public UUID
deleteDescriptionElement(DescriptionElementBase descriptionElement
) {
323 return descriptionElementDao
.delete(descriptionElement
);
326 public TermVocabulary
<Feature
> getFeatureVocabulary(UUID uuid
) {
327 return (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
330 public List
<DescriptionElementBase
> getDescriptionElementsForTaxon(
331 Taxon taxon
, Set
<Feature
> features
,
332 Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
,
333 Integer pageNumber
, List
<String
> propertyPaths
) {
334 return dao
.getDescriptionElementForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);