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
.HashSet
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import org
.apache
.commons
.lang
.StringUtils
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
24 import org
.springframework
.stereotype
.Service
;
25 import org
.springframework
.transaction
.annotation
.Transactional
;
27 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
28 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.AbstractPagerImpl
;
29 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
30 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
31 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
32 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
34 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
35 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
38 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
39 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
40 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
43 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
44 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
45 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
46 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
47 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
48 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
49 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
50 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
51 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
52 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
58 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureDao
;
59 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
60 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureTreeDao
;
61 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IStatisticalMeasurementValueDao
;
62 import eu
.etaxonomy
.cdm
.persistence
.dao
.taxon
.ITaxonDao
;
63 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
64 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
72 * @author a.kohlbecker
77 @Transactional(readOnly
= true)
78 public class DescriptionServiceImpl
extends IdentifiableServiceBase
<DescriptionBase
,IDescriptionDao
> implements IDescriptionService
{
80 private static final Logger logger
= Logger
.getLogger(DescriptionServiceImpl
.class);
82 protected IDescriptionElementDao descriptionElementDao
;
83 protected IFeatureTreeDao featureTreeDao
;
84 protected IFeatureNodeDao featureNodeDao
;
85 protected IFeatureDao featureDao
;
86 protected ITermVocabularyDao vocabularyDao
;
87 protected IDefinedTermDao definedTermDao
;
88 protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao
;
89 protected ITaxonDao taxonDao
;
91 //TODO change to Interface
92 private NaturalLanguageGenerator naturalLanguageGenerator
;
95 protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao
) {
96 this.featureTreeDao
= featureTreeDao
;
100 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
101 this.featureNodeDao
= featureNodeDao
;
105 protected void setFeatureDao(IFeatureDao featureDao
) {
106 this.featureDao
= featureDao
;
110 protected void setVocabularyDao(ITermVocabularyDao vocabularyDao
) {
111 this.vocabularyDao
= vocabularyDao
;
115 protected void setDefinedTermDao(IDefinedTermDao definedTermDao
) {
116 this.definedTermDao
= definedTermDao
;
120 protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao
) {
121 this.statisticalMeasurementValueDao
= statisticalMeasurementValueDao
;
125 protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao
) {
126 this.descriptionElementDao
= descriptionElementDao
;
130 protected void setNaturalLanguageGenerator(NaturalLanguageGenerator naturalLanguageGenerator
) {
131 this.naturalLanguageGenerator
= naturalLanguageGenerator
;
135 protected void setTaxonDao(ITaxonDao taxonDao
) {
136 this.taxonDao
= taxonDao
;
142 public DescriptionServiceImpl() {
143 logger
.debug("Load DescriptionService Bean");
149 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
152 @Transactional(readOnly
= false)
153 public void updateTitleCache(Class
<?
extends DescriptionBase
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<DescriptionBase
> cacheStrategy
, IProgressMonitor monitor
) {
155 clazz
= DescriptionBase
.class;
157 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
162 public TermVocabulary
<Feature
> getDefaultFeatureVocabulary(){
163 String uuidFeature
= "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
164 UUID featureUuid
= UUID
.fromString(uuidFeature
);
165 return vocabularyDao
.findByUuid(featureUuid
);
170 protected void setDao(IDescriptionDao dao
) {
175 public int count(Class
<?
extends DescriptionBase
> type
, Boolean hasImages
, Boolean hasText
,Set
<Feature
> feature
) {
176 return dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
180 public Pager
<DescriptionElementBase
> pageDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
181 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
183 List
<DescriptionElementBase
> results
= listDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
184 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, results
.size(), pageSize
, results
);
188 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getDescriptionElements(eu.etaxonomy.cdm.model.description.DescriptionBase, java.util.Set, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
192 public Pager
<DescriptionElementBase
> getDescriptionElements(DescriptionBase description
,
193 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
194 return pageDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
198 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
199 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
201 Integer numberOfResults
= dao
.countDescriptionElements(description
, descriptionType
, features
, type
);
202 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
203 if(AbstractPagerImpl
.hasResultsInRange(numberOfResults
.longValue(), pageNumber
, pageSize
)) {
204 results
= dao
.getDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
210 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#listDescriptionElements(eu.etaxonomy.cdm.model.description.DescriptionBase, java.util.Set, java.lang.Class, java.lang.Integer, java.lang.Integer, java.util.List)
214 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
,
215 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
217 return listDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
221 public Pager
<Annotation
> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj
, MarkerType status
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
222 Integer numberOfResults
= descriptionElementDao
.countAnnotations(annotatedObj
, status
);
224 List
<Annotation
> results
= new ArrayList
<Annotation
>();
225 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
226 results
= descriptionElementDao
.getAnnotations(annotatedObj
, status
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
229 return new DefaultPagerImpl
<Annotation
>(pageNumber
, numberOfResults
, pageSize
, results
);
235 public Pager
<Media
> getMedia(DescriptionElementBase descriptionElement
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
236 Integer numberOfResults
= descriptionElementDao
.countMedia(descriptionElement
);
238 List
<Media
> results
= new ArrayList
<Media
>();
239 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
240 results
= descriptionElementDao
.getMedia(descriptionElement
, pageSize
, pageNumber
, propertyPaths
);
243 return new DefaultPagerImpl
<Media
>(pageNumber
, numberOfResults
, pageSize
, results
);
247 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
248 Set
<MarkerType
> markerTypes
= null;
249 return pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
253 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
254 Set
<MarkerType
> markerTypes
= null;
255 return listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
260 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#pageMarkedTaxonDescriptions(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.Set, java.util.Set, java.util.Set, java.lang.Integer, java.lang.Integer, java.util.List)
263 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
264 Integer numberOfResults
= dao
.countTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
);
266 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
267 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
268 results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
271 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
275 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
276 List
<TaxonDescription
> results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
282 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
285 public List
<Media
> listTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
286 return this.dao
.listTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
290 * @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
293 public int countTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
){
294 return this.dao
.countTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
);
299 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getOrderedDistributions(java.util.Set, boolean, boolean, java.util.Set, java.util.List)
303 public DistributionTree
getOrderedDistributions(
304 Set
<TaxonDescription
> taxonDescriptions
,
305 boolean subAreaPreference
,
306 boolean statusOrderPreference
,
307 Set
<MarkerType
> hideMarkedAreas
,
308 Set
<NamedAreaLevel
> omitLevels
, List
<String
> propertyPaths
){
310 List
<Distribution
> distList
= new ArrayList
<Distribution
>();
312 List
<UUID
> uuids
= new ArrayList
<UUID
>();
313 for (TaxonDescription taxonDescription
: taxonDescriptions
) {
314 if (! taxonDescription
.isImageGallery()){ //image galleries should not have descriptions, but better filter fully on DTYPE of description element
315 uuids
.add(taxonDescription
.getUuid());
319 List
<DescriptionBase
> desclist
= dao
.list(uuids
, null, null, null, propertyPaths
);
320 for (DescriptionBase desc
: desclist
) {
321 if (desc
.isInstanceOf(TaxonDescription
.class)){
322 Set
<DescriptionElementBase
> elements
= desc
.getElements();
323 for (DescriptionElementBase element
: elements
) {
324 if (element
.isInstanceOf(Distribution
.class)) {
325 Distribution distribution
= (Distribution
) element
;
326 if(distribution
.getArea() != null){
327 distList
.add(distribution
);
335 // for (TaxonDescription taxonDescription : taxonDescriptions) {
336 // if (logger.isDebugEnabled()){ logger.debug("load taxon description " + taxonDescription.getUuid());}
337 // //TODO why not loading all description via .list ? This may improve performance
338 // taxonDescription = (TaxonDescription) dao.load(taxonDescription.getUuid(), propertyPaths);
339 // Set<DescriptionElementBase> elements = taxonDescription.getElements();
340 // for (DescriptionElementBase element : elements) {
341 // if (element.isInstanceOf(Distribution.class)) {
342 // Distribution distribution = (Distribution) element;
343 // if(distribution.getArea() != null){
344 // distList.add(distribution);
350 if (logger
.isDebugEnabled()){logger
.debug("filter tree for " + distList
.size() + " distributions ...");}
352 // filter distributions
353 Collection
<Distribution
> filteredDistributions
= DescriptionUtility
.filterDistributions(distList
, subAreaPreference
, statusOrderPreference
, hideMarkedAreas
);
355 distList
.addAll(filteredDistributions
);
357 return DescriptionUtility
.orderDistributions(omitLevels
, distList
);
362 public Pager
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase name
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
363 Integer numberOfResults
= dao
.countTaxonNameDescriptions(name
);
365 List
<TaxonNameDescription
> results
= new ArrayList
<TaxonNameDescription
>();
366 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
367 results
= dao
.getTaxonNameDescriptions(name
, pageSize
, pageNumber
,propertyPaths
);
370 return new DefaultPagerImpl
<TaxonNameDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
375 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
) {
376 Integer numberOfResults
= dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
378 List
<DescriptionBase
> results
= new ArrayList
<DescriptionBase
>();
379 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
380 results
= dao
.listDescriptions(type
, hasImages
, hasText
, feature
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
383 return new DefaultPagerImpl
<DescriptionBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
387 * FIXME Candidate for harmonization
388 * Rename: searchByDistribution
391 public Pager
<TaxonDescription
> searchDescriptionByDistribution(Set
<NamedArea
> namedAreas
, PresenceAbsenceTerm presence
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
392 Integer numberOfResults
= dao
.countDescriptionByDistribution(namedAreas
, presence
);
394 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
395 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
396 results
= dao
.searchDescriptionByDistribution(namedAreas
, presence
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
399 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
403 * FIXME Candidate for harmonization
404 * move: descriptionElementService.search
407 public Pager
<DescriptionElementBase
> searchElements(Class
<?
extends DescriptionElementBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
408 Integer numberOfResults
= descriptionElementDao
.count(clazz
, queryString
);
410 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
411 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
412 results
= descriptionElementDao
.search(clazz
, queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
415 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
419 * FIXME Candidate for harmonization
420 * descriptionElementService.find
423 public DescriptionElementBase
getDescriptionElementByUuid(UUID uuid
) {
424 return descriptionElementDao
.findByUuid(uuid
);
428 * FIXME Candidate for harmonization
429 * descriptionElementService.load
432 public DescriptionElementBase
loadDescriptionElement(UUID uuid
, List
<String
> propertyPaths
) {
433 return descriptionElementDao
.load(uuid
, propertyPaths
);
437 * FIXME Candidate for harmonization
438 * descriptionElementService.save
441 @Transactional(readOnly
= false)
442 public UUID
saveDescriptionElement(DescriptionElementBase descriptionElement
) {
443 return descriptionElementDao
.save(descriptionElement
);
447 * FIXME Candidate for harmonization
448 * descriptionElementService.save
451 @Transactional(readOnly
= false)
452 public Map
<UUID
, DescriptionElementBase
> saveDescriptionElement(Collection
<DescriptionElementBase
> descriptionElements
) {
453 return descriptionElementDao
.saveAll(descriptionElements
);
457 * FIXME Candidate for harmonization
458 * descriptionElementService.delete
461 public UUID
deleteDescriptionElement(DescriptionElementBase descriptionElement
) {
462 return descriptionElementDao
.delete(descriptionElement
);
466 public UUID
deleteDescription(DescriptionBase description
) {
467 if (description
instanceof TaxonDescription
){
468 TaxonDescription taxDescription
= HibernateProxyHelper
.deproxy(description
, TaxonDescription
.class);
469 Taxon tax
= taxDescription
.getTaxon();
470 tax
.removeDescription(taxDescription
, true);
473 return dao
.delete(description
);
476 public TermVocabulary
<Feature
> getFeatureVocabulary(UUID uuid
) {
477 return vocabularyDao
.findByUuid(uuid
);
482 public <T
extends DescriptionElementBase
> List
<T
> getDescriptionElementsForTaxon(
483 Taxon taxon
, Set
<Feature
> features
,
484 Class
<T
> type
, Integer pageSize
,
485 Integer pageNumber
, List
<String
> propertyPaths
) {
486 return listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
490 public <T
extends DescriptionElementBase
> List
<T
> listDescriptionElementsForTaxon(
491 Taxon taxon
, Set
<Feature
> features
,
492 Class
<T
> type
, Integer pageSize
,
493 Integer pageNumber
, List
<String
> propertyPaths
) {
494 return dao
.getDescriptionElementForTaxon(taxon
.getUuid(), features
, type
, pageSize
, pageNumber
, propertyPaths
);
498 public <T
extends DescriptionElementBase
> Pager
<T
> pageDescriptionElementsForTaxon(
499 Taxon taxon
, Set
<Feature
> features
,
500 Class
<T
> type
, Integer pageSize
,
501 Integer pageNumber
, List
<String
> propertyPaths
) {
502 if (logger
.isDebugEnabled()){logger
.debug(" get count ...");}
503 Long count
= dao
.countDescriptionElementForTaxon(taxon
.getUuid(), features
, type
);
504 List
<T
> descriptionElements
;
505 if(AbstractPagerImpl
.hasResultsInRange(count
, pageNumber
, pageSize
)){ // no point checking again
506 if (logger
.isDebugEnabled()){logger
.debug(" get list ...");}
507 descriptionElements
= listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
509 descriptionElements
= new ArrayList
<T
>(0);
511 if (logger
.isDebugEnabled()){logger
.debug(" service - DONE ...");}
512 return new DefaultPagerImpl
<T
>(pageNumber
, count
.intValue(), pageSize
, descriptionElements
);
517 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#generateNaturalLanguageDescription(eu.etaxonomy.cdm.model.description.FeatureTree, eu.etaxonomy.cdm.model.description.TaxonDescription, eu.etaxonomy.cdm.model.common.Language, java.util.List)
520 public String
generateNaturalLanguageDescription(FeatureTree featureTree
,
521 TaxonDescription description
, List
<Language
> preferredLanguages
, String separator
) {
523 Language lang
= preferredLanguages
.size() > 0 ? preferredLanguages
.get(0) : Language
.DEFAULT();
525 description
= (TaxonDescription
)load(description
.getUuid());
526 featureTree
= featureTreeDao
.load(featureTree
.getUuid());
528 StringBuilder naturalLanguageDescription
= new StringBuilder();
530 MarkerType useMarkerType
= (MarkerType
) definedTermDao
.load(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
531 boolean isUseDescription
= false;
532 if(!description
.getMarkers().isEmpty()) {
533 for (Marker marker
: description
.getMarkers()) {
534 MarkerType markerType
= marker
.getMarkerType();
535 if (markerType
.equals(useMarkerType
)) {
536 isUseDescription
= true;
542 if(description
.hasStructuredData() && !isUseDescription
){
545 String lastCategory
= null;
546 String categorySeparator
= ". ";
548 List
<TextData
> textDataList
;
549 TextData naturalLanguageDescriptionText
= null;
551 boolean useMicroFormatQuantitativeDescriptionBuilder
= false;
553 if(useMicroFormatQuantitativeDescriptionBuilder
){
555 MicroFormatQuantitativeDescriptionBuilder micro
= new MicroFormatQuantitativeDescriptionBuilder();
556 naturalLanguageGenerator
.setQuantitativeDescriptionBuilder(micro
);
557 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(featureTree
, (description
), lang
);
561 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(
567 return naturalLanguageDescriptionText
.getText(lang
);
570 // boolean doItBetter = false;
572 // for (TextData textData : textDataList.toArray(new TextData[textDataList.size()])){
573 // if(textData.getMultilanguageText().size() > 0){
575 // if (!textData.getFeature().equals(Feature.UNKNOWN())) {
576 // String featureLabel = textData.getFeature().getLabel(lang);
581 // * The code lines below are desinged to handle
582 // * a special case where as the feature label contains
583 // * hierarchical information on the features. This code
584 // * exist only as a base for discussion, and is not
585 // * intendet to be used in production.
587 // featureLabel = StringUtils.remove(featureLabel, '>');
589 // String[] labelTokens = StringUtils.split(featureLabel, '<');
590 // if(labelTokens[0].equals(lastCategory) && labelTokens.length > 1){
591 // if(naturalLanguageDescription.length() > 0){
592 // naturalLanguageDescription.append(separator);
594 // naturalLanguageDescription.append(labelTokens[1]);
596 // if(naturalLanguageDescription.length() > 0){
597 // naturalLanguageDescription.append(categorySeparator);
599 // naturalLanguageDescription.append(StringUtils.join(labelTokens));
601 // lastCategory = labelTokens[0];
602 // // end of demo code
604 // if(naturalLanguageDescription.length() > 0){
605 // naturalLanguageDescription.append(separator);
607 // naturalLanguageDescription.append(textData.getFeature().getLabel(lang));
610 // if(naturalLanguageDescription.length() > 0){
611 // naturalLanguageDescription.append(separator);
614 // String text = textData.getMultilanguageText().values().iterator().next().getText();
615 // naturalLanguageDescription.append(text);
621 else if (isUseDescription
) {
622 //AT: Left Blank in case we need to generate a Natural language text string.
624 return naturalLanguageDescription
.toString();
628 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#hasStructuredData(eu.etaxonomy.cdm.model.description.DescriptionBase)
631 public boolean hasStructuredData(DescriptionBase
<?
> description
) {
632 return load(description
.getUuid()).hasStructuredData();
637 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveDescriptionElementsToDescription(java.util.Collection, eu.etaxonomy.cdm.model.description.DescriptionBase, boolean)
640 public void moveDescriptionElementsToDescription(Collection
<DescriptionElementBase
> descriptionElements
,
641 DescriptionBase targetDescription
, boolean isCopy
) {
643 if (descriptionElements
.isEmpty() ){
647 if (! isCopy
&& descriptionElements
== descriptionElements
.iterator().next().getInDescription().getElements()){
648 //if the descriptionElements collection is the elements set of a description, put it in a separate set before to avoid concurrent modification exceptions
649 descriptionElements
= new HashSet
<DescriptionElementBase
>(descriptionElements
);
650 // descriptionElementsTmp.addAll(descriptionElements);
651 // descriptionElements = descriptionElementsTmp;
653 for (DescriptionElementBase element
: descriptionElements
){
654 DescriptionBase description
= element
.getInDescription();
656 DescriptionElementBase newElement
= (DescriptionElementBase
)element
.clone();
657 targetDescription
.addElement(newElement
);
658 } catch (CloneNotSupportedException e
) {
659 new RuntimeException ("Clone not yet implemented for class " + element
.getClass().getName(), e
);
662 description
.removeElement(element
);
669 public Pager
<NamedArea
> pageNamedAreasInUse(Integer pageSize
,
670 Integer pageNumber
, List
<String
> propertyPaths
){
672 List
<NamedArea
> results
= dao
.listNamedAreasInUse(pageSize
, pageNumber
, propertyPaths
);
673 return new DefaultPagerImpl
<NamedArea
>(pageNumber
, results
.size(), pageSize
, results
);
678 @Transactional(readOnly
= false)
679 public void moveTaxonDescriptions(Taxon sourceTaxon
, Taxon targetTaxon
) {
680 List
<TaxonDescription
> descriptions
= new ArrayList(sourceTaxon
.getDescriptions());
681 for(TaxonDescription description
: descriptions
){
683 String moveMessage
= String
.format("Description moved from %s", sourceTaxon
);
684 if(description
.isProtectedTitleCache()){
685 String separator
= "";
686 if(!StringUtils
.isBlank(description
.getTitleCache())){
689 description
.setTitleCache(description
.getTitleCache() + separator
+ moveMessage
, true);
691 Annotation annotation
= Annotation
.NewInstance(moveMessage
, Language
.getDefaultLanguage());
692 annotation
.setAnnotationType(AnnotationType
.TECHNICAL());
693 description
.addAnnotation(annotation
);
694 targetTaxon
.addDescription(description
);
699 @Transactional(readOnly
= false)
700 public void moveTaxonDescriptions(UUID sourceTaxonUuid
, UUID targetTaxonUuid
) {
701 Taxon sourceTaxon
= HibernateProxyHelper
.deproxy(taxonDao
.load(sourceTaxonUuid
), Taxon
.class);
702 Taxon targetTaxon
= HibernateProxyHelper
.deproxy(taxonDao
.load(targetTaxonUuid
), Taxon
.class);
703 moveTaxonDescriptions(sourceTaxon
, targetTaxon
);