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
.Transactional
;
25 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
26 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
27 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
28 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
30 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
31 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
32 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
33 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
34 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.Scope
;
36 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasurementValue
;
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
.media
.Media
;
41 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
42 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
44 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
45 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
46 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
47 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureDao
;
48 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
49 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureTreeDao
;
50 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IStatisticalMeasurementValueDao
;
51 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
59 @Transactional(readOnly
= true)
60 public class DescriptionServiceImpl
extends IdentifiableServiceBase
<DescriptionBase
,IDescriptionDao
> implements IDescriptionService
{
62 private static final Logger logger
= Logger
.getLogger(DescriptionServiceImpl
.class);
64 protected IDescriptionElementDao descriptionElementDao
;
65 protected IFeatureTreeDao featureTreeDao
;
66 protected IFeatureNodeDao featureNodeDao
;
67 protected IFeatureDao featureDao
;
68 protected ITermVocabularyDao vocabularyDao
;
69 protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao
;
72 protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao
) {
73 this.featureTreeDao
= featureTreeDao
;
77 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
78 this.featureNodeDao
= featureNodeDao
;
82 protected void setFeatureDao(IFeatureDao featureDao
) {
83 this.featureDao
= featureDao
;
87 protected void setVocabularyDao(ITermVocabularyDao vocabularyDao
) {
88 this.vocabularyDao
= vocabularyDao
;
92 protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao
) {
93 this.statisticalMeasurementValueDao
= statisticalMeasurementValueDao
;
97 protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao
) {
98 this.descriptionElementDao
= descriptionElementDao
;
104 public DescriptionServiceImpl() {
105 logger
.debug("Load DescriptionService Bean");
109 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getDescriptionBaseByUuid(java.util.UUID)
110 * FIXME Candidate for harmonization
113 public DescriptionBase
getDescriptionBaseByUuid(UUID uuid
) {
114 return super.getCdmObjectByUuid(uuid
);
118 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveDescription(eu.etaxonomy.cdm.model.description.DescriptionBase)
119 * FIXME Candidate for harmonization
122 @Transactional(readOnly
= false)
123 public UUID
saveDescription(DescriptionBase description
) {
124 return super.saveCdmObject(description
);
128 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveDescription(eu.etaxonomy.cdm.model.description.DescriptionBase)
129 * FIXME Candidate for harmonization
130 * Given that statistcal measurement values are wholy owned by their parent QuantitativeData, do we need this method? could we not
131 * save / update statistical measurement values as part of descriptionElementService.update or descriptionElementService.save?
133 @Transactional(readOnly
= false)
134 public UUID
saveStatisticalMeasurementValue(StatisticalMeasurementValue statisticalMeasurementValue
) {
135 return statisticalMeasurementValueDao
.saveOrUpdate(statisticalMeasurementValue
);
139 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#generateTitleCache()
141 public void generateTitleCache() {
142 logger
.warn("generateTitleCache not yet implemented");
146 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveFeatureTree(eu.etaxonomy.cdm.model.description.FeatureTree)
147 * FIXME Candidate for harmonization
148 * featureTreeService.save
150 @Transactional(readOnly
= false)
151 public UUID
saveFeatureTree(FeatureTree tree
) {
152 return featureTreeDao
.saveOrUpdate(tree
);
157 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#saveFeatureDataAll(java.util.Collection)
158 * FIXME Candidate for harmonization
160 * featureTreeService.save(FeatureTree f) and this cascades to child nodes or does this not work?
161 * CDM Xml now only has a list of FeatureTrees, and calls saveFeatureTreeAll(featureTrees);
163 @Transactional(readOnly
= false)
164 public void saveFeatureDataAll(Collection
<VersionableEntity
> featureData
) {
166 List
<FeatureTree
> trees
= new ArrayList
<FeatureTree
>();
167 List
<FeatureNode
> nodes
= new ArrayList
<FeatureNode
>();
169 for ( VersionableEntity featureItem
: featureData
) {
170 if (featureItem
instanceof FeatureTree
) {
171 trees
.add((FeatureTree
)featureItem
);
172 } else if (featureItem
instanceof FeatureNode
) {
173 nodes
.add((FeatureNode
)featureItem
);
175 logger
.error("Entry of wrong type: " + featureItem
.toString());
179 if (trees
.size() > 0) { saveFeatureTreeAll(trees
); }
180 if (nodes
.size() > 0) { saveFeatureNodeAll(nodes
); }
184 * FIXME Candidate for harmonization
185 * featureTreeService.save(Set<FeatureTree> featureTrees)
187 @Transactional(readOnly
= false)
188 public Map
<UUID
, FeatureTree
> saveFeatureTreeAll(Collection
<FeatureTree
> trees
) {
189 return featureTreeDao
.saveAll(trees
);
193 * FIXME Candidate for harmonization
196 @Transactional(readOnly
= false)
197 public Map
<UUID
, FeatureNode
> saveFeatureNodeAll(Collection
<FeatureNode
> trees
) {
198 return featureNodeDao
.saveAll(trees
);
202 * FIXME Candidate for harmonization
203 * vocabularyService.find(UUID uuid)
205 public TermVocabulary
<Feature
> getFeatureVocabulary(UUID uuid
){
206 TermVocabulary
<Feature
> featureVocabulary
;
208 featureVocabulary
= (TermVocabulary
)vocabularyDao
.findByUuid(uuid
);
209 } catch (ClassCastException e
) {
212 return featureVocabulary
;
215 // public TermVocabulary<Feature> getFeatureVocabulary(){
216 // TermVocabulary<Feature> featureVocabulary;
218 // featureVocabulary = (TermVocabulary)vocabularyDao.findByUuid(uuid);
219 // } catch (ClassCastException e) {
222 // return featureVocabulary;
225 public TermVocabulary
<Feature
> getDefaultFeatureVocabulary(){
226 String uuidFeature
= "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
227 UUID featureUuid
= UUID
.fromString(uuidFeature
);
228 return getFeatureVocabulary(featureUuid
);
232 * FIXME Candidate for harmonization
233 * featureTreeService.list()
236 public List
<FeatureTree
> getFeatureTreesAll() {
237 return featureTreeDao
.list();
241 * FIXME Candidate for harmonization
244 public List
<FeatureNode
> getFeatureNodesAll() {
245 return featureNodeDao
.list();
249 * FIXME Candidate for harmonization
250 * termService.list(Feature.class, null,null,...)
252 public List
<Feature
> getFeaturesAll() {
253 return featureDao
.list();
257 * FIXME Candidate for harmonization
258 * featureTreeService.list
260 public List
<FeatureTree
> getFeatureTreesAll(List
<String
> propertyPaths
){
261 return featureTreeDao
.list(null, null, null, propertyPaths
);
265 * FIXME Candidate for harmonization
268 public List
<FeatureNode
> getFeatureNodesAll(List
<String
> propertyPaths
){
269 return featureNodeDao
.list(null, null, null, propertyPaths
);
273 * FIXME Candidate for harmonization
276 public List
<Feature
> getFeaturesAll(List
<String
> propertyPaths
){
277 return featureDao
.list(null, null, null, propertyPaths
);
281 protected void setDao(IDescriptionDao dao
) {
286 * FIXME Candidate for harmonization
289 public <TYPE
extends DescriptionBase
> int countDescriptions(Class
<TYPE
> type
, Boolean hasImages
, Boolean hasText
,Set
<Feature
> feature
) {
290 return dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
294 * FIXME Candidate for harmonization
295 * rename -> getElements
297 public <TYPE
extends DescriptionElementBase
> Pager
<TYPE
> getDescriptionElements(DescriptionBase description
,
298 Set
<Feature
> features
, Class
<TYPE
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
299 Integer numberOfResults
= dao
.countDescriptionElements(description
, features
, type
);
301 List
<TYPE
> results
= new ArrayList
<TYPE
>();
302 if (numberOfResults
> 0) { // no point checking again
303 results
= dao
.getDescriptionElements(description
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
306 return new DefaultPagerImpl
<TYPE
>(pageNumber
, numberOfResults
, pageSize
, results
);
310 public Pager
<Media
> getMedia(DescriptionElementBase descriptionElement
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
311 Integer numberOfResults
= descriptionElementDao
.countMedia(descriptionElement
);
313 List
<Media
> results
= new ArrayList
<Media
>();
314 if(numberOfResults
> 0) { // no point checking again
315 results
= descriptionElementDao
.getMedia(descriptionElement
, pageSize
, pageNumber
, propertyPaths
);
318 return new DefaultPagerImpl
<Media
>(pageNumber
, numberOfResults
, pageSize
, results
);
321 public Pager
<TaxonDescription
> getTaxonDescriptions(Taxon taxon
, Set
<Scope
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
322 Integer numberOfResults
= dao
.countTaxonDescriptions(taxon
, scopes
, geographicalScope
);
324 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
325 if(numberOfResults
> 0) { // no point checking again
326 results
= dao
.getTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
329 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
332 public Pager
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase name
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
333 Integer numberOfResults
= dao
.countTaxonNameDescriptions(name
);
335 List
<TaxonNameDescription
> results
= new ArrayList
<TaxonNameDescription
>();
336 if(numberOfResults
> 0) { // no point checking again
337 results
= dao
.getTaxonNameDescriptions(name
, pageSize
, pageNumber
,propertyPaths
);
340 return new DefaultPagerImpl
<TaxonNameDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
344 * FIXME Candidate for harmonization
347 public <TYPE
extends DescriptionBase
> Pager
<TYPE
> listDescriptions(Class
<TYPE
> type
, Boolean hasImages
, Boolean hasText
, Set
<Feature
> feature
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
348 Integer numberOfResults
= dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
350 List
<TYPE
> results
= new ArrayList
<TYPE
>();
351 if(numberOfResults
> 0) { // no point checking again
352 results
= dao
.listDescriptions(type
, hasImages
, hasText
, feature
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
355 return new DefaultPagerImpl
<TYPE
>(pageNumber
, numberOfResults
, pageSize
, results
);
359 * FIXME Candidate for harmonization
360 * Rename: searchByDistribution
362 public Pager
<TaxonDescription
> searchDescriptionByDistribution(Set
<NamedArea
> namedAreas
, PresenceAbsenceTermBase presence
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
363 Integer numberOfResults
= dao
.countDescriptionByDistribution(namedAreas
, presence
);
365 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
366 if(numberOfResults
> 0) { // no point checking again
367 results
= dao
.searchDescriptionByDistribution(namedAreas
, presence
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
370 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
374 * FIXME Candidate for harmonization
375 * move: descriptionElementService.search
377 public Pager
<DescriptionElementBase
> search(Class
<?
extends DescriptionElementBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
378 Integer numberOfResults
= descriptionElementDao
.count(clazz
,queryString
);
380 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
381 if(numberOfResults
> 0) { // no point checking again
382 results
= descriptionElementDao
.search(clazz
, queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
385 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
389 * FIXME Candidate for harmonization
390 * featureTreeService.find
392 public FeatureTree
getFeatureTreeByUuid(UUID uuid
) {
393 return featureTreeDao
.findByUuid(uuid
);
397 * FIXME Candidate for harmonization
398 * descriptionElementService.find
400 public DescriptionElementBase
getDescriptionElementByUuid(UUID uuid
) {
401 return descriptionElementDao
.findByUuid(uuid
);
405 * FIXME Candidate for harmonization
406 * is this needed? yes, I think it is, because there is no way to recursively
407 * initialize feature trees and all of their children otherwise
409 public FeatureNode
loadFeatureNode(UUID uuid
, List
<String
> propertyPaths
) {
410 return featureNodeDao
.load(uuid
, propertyPaths
);
414 * FIXME Candidate for harmonization
415 * featureTreeService.load
417 public FeatureTree
loadFeatureTree(UUID uuid
, List
<String
> propertyPaths
) {
418 return featureTreeDao
.load(uuid
, propertyPaths
);
422 * FIXME Candidate for harmonization
423 * descriptionElementService.load
425 public DescriptionElementBase
loadDescriptionElement(UUID uuid
, List
<String
> propertyPaths
) {
426 return descriptionElementDao
.load(uuid
, propertyPaths
);
430 * FIXME Candidate for harmonization
431 * descriptionElementService.save
433 public UUID
saveDescriptionElement(DescriptionElementBase descriptionElement
) {
434 return descriptionElementDao
.save(descriptionElement
);
438 * FIXME Candidate for harmonization
439 * descriptionElementService.delete
441 public UUID
deleteDescriptionElement(DescriptionElementBase descriptionElement
) {
442 return descriptionElementDao
.delete(descriptionElement
);