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
.log4j
.Logger
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Service
;
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
.AbstractPagerImpl
;
28 import eu
.etaxonomy
.cdm
.api
.service
.pager
.impl
.DefaultPagerImpl
;
29 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
30 import eu
.etaxonomy
.cdm
.common
.monitor
.IProgressMonitor
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
32 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
35 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
37 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
39 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
40 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
41 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
42 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
43 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
44 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
45 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
46 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
47 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
48 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
49 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
50 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
58 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureTreeDao
;
59 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IStatisticalMeasurementValueDao
;
60 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
61 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
69 @Transactional(readOnly
= true)
70 public class DescriptionServiceImpl
extends IdentifiableServiceBase
<DescriptionBase
,IDescriptionDao
> implements IDescriptionService
{
72 private static final Logger logger
= Logger
.getLogger(DescriptionServiceImpl
.class);
74 protected IDescriptionElementDao descriptionElementDao
;
75 protected IFeatureTreeDao featureTreeDao
;
76 protected IFeatureNodeDao featureNodeDao
;
77 protected IFeatureDao featureDao
;
78 protected ITermVocabularyDao vocabularyDao
;
79 protected IDefinedTermDao definedTermDao
;
80 protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao
;
81 //TODO change to Interface
82 private NaturalLanguageGenerator naturalLanguageGenerator
;
85 protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao
) {
86 this.featureTreeDao
= featureTreeDao
;
90 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
91 this.featureNodeDao
= featureNodeDao
;
95 protected void setFeatureDao(IFeatureDao featureDao
) {
96 this.featureDao
= featureDao
;
100 protected void setVocabularyDao(ITermVocabularyDao vocabularyDao
) {
101 this.vocabularyDao
= vocabularyDao
;
105 protected void setDefinedTermDao(IDefinedTermDao definedTermDao
) {
106 this.definedTermDao
= definedTermDao
;
110 protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao
) {
111 this.statisticalMeasurementValueDao
= statisticalMeasurementValueDao
;
115 protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao
) {
116 this.descriptionElementDao
= descriptionElementDao
;
120 protected void setNaturalLanguageGenerator(NaturalLanguageGenerator naturalLanguageGenerator
) {
121 this.naturalLanguageGenerator
= naturalLanguageGenerator
;
127 public DescriptionServiceImpl() {
128 logger
.debug("Load DescriptionService Bean");
134 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
137 @Transactional(readOnly
= false)
138 public void updateTitleCache(Class
<?
extends DescriptionBase
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<DescriptionBase
> cacheStrategy
, IProgressMonitor monitor
) {
140 clazz
= DescriptionBase
.class;
142 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
147 public TermVocabulary
<Feature
> getDefaultFeatureVocabulary(){
148 String uuidFeature
= "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
149 UUID featureUuid
= UUID
.fromString(uuidFeature
);
150 return vocabularyDao
.findByUuid(featureUuid
);
155 protected void setDao(IDescriptionDao dao
) {
160 public int count(Class
<?
extends DescriptionBase
> type
, Boolean hasImages
, Boolean hasText
,Set
<Feature
> feature
) {
161 return dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
165 public Pager
<DescriptionElementBase
> pageDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
166 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
168 List
<DescriptionElementBase
> results
= listDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
169 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, results
.size(), pageSize
, results
);
173 * @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)
177 public Pager
<DescriptionElementBase
> getDescriptionElements(DescriptionBase description
,
178 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
179 return pageDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
183 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
184 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
186 Integer numberOfResults
= dao
.countDescriptionElements(description
, descriptionType
, features
, type
);
187 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
188 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
189 results
= dao
.getDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
195 * @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)
199 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
,
200 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
202 return listDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
206 public Pager
<Annotation
> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj
, MarkerType status
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
207 Integer numberOfResults
= descriptionElementDao
.countAnnotations(annotatedObj
, status
);
209 List
<Annotation
> results
= new ArrayList
<Annotation
>();
210 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
211 results
= descriptionElementDao
.getAnnotations(annotatedObj
, status
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
214 return new DefaultPagerImpl
<Annotation
>(pageNumber
, numberOfResults
, pageSize
, results
);
220 public Pager
<Media
> getMedia(DescriptionElementBase descriptionElement
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
221 Integer numberOfResults
= descriptionElementDao
.countMedia(descriptionElement
);
223 List
<Media
> results
= new ArrayList
<Media
>();
224 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
225 results
= descriptionElementDao
.getMedia(descriptionElement
, pageSize
, pageNumber
, propertyPaths
);
228 return new DefaultPagerImpl
<Media
>(pageNumber
, numberOfResults
, pageSize
, results
);
232 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
233 Set
<MarkerType
> markerTypes
= null;
234 return pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
238 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
239 Set
<MarkerType
> markerTypes
= null;
240 return listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
245 * @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)
248 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
249 Integer numberOfResults
= dao
.countTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
);
251 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
252 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
253 results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
256 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
260 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
261 List
<TaxonDescription
> results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
267 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
270 public List
<Media
> listTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
271 return this.dao
.listTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
275 * @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
278 public int countTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
){
279 return this.dao
.countTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
);
286 public DistributionTree
getOrderedDistributions(
287 Set
<TaxonDescription
> taxonDescriptions
,
288 Set
<NamedAreaLevel
> omitLevels
,
289 List
<String
> propertyPaths
){
291 DistributionTree tree
= new DistributionTree();
292 List
<Distribution
> distList
= new ArrayList
<Distribution
>();
294 for (TaxonDescription taxonDescription
: taxonDescriptions
) {
295 taxonDescription
= (TaxonDescription
) dao
.load(taxonDescription
.getUuid(), propertyPaths
);
296 Set
<DescriptionElementBase
> elements
= taxonDescription
.getElements();
297 for (DescriptionElementBase element
: elements
) {
298 if (element
.isInstanceOf(Distribution
.class)) {
299 Distribution distribution
= (Distribution
) element
;
300 if(distribution
.getArea() != null){
301 distList
.add(distribution
);
307 // filter distributions
308 Collection
<Distribution
> filteredDistributions
= DescriptionUtility
.filterDistributions(distList
);
310 distList
.addAll(filteredDistributions
);
313 tree
.orderAsTree(distList
, omitLevels
);
319 public Pager
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase name
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
320 Integer numberOfResults
= dao
.countTaxonNameDescriptions(name
);
322 List
<TaxonNameDescription
> results
= new ArrayList
<TaxonNameDescription
>();
323 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
324 results
= dao
.getTaxonNameDescriptions(name
, pageSize
, pageNumber
,propertyPaths
);
327 return new DefaultPagerImpl
<TaxonNameDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
332 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
) {
333 Integer numberOfResults
= dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
335 List
<DescriptionBase
> results
= new ArrayList
<DescriptionBase
>();
336 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
337 results
= dao
.listDescriptions(type
, hasImages
, hasText
, feature
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
340 return new DefaultPagerImpl
<DescriptionBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
344 * FIXME Candidate for harmonization
345 * Rename: searchByDistribution
348 public Pager
<TaxonDescription
> searchDescriptionByDistribution(Set
<NamedArea
> namedAreas
, PresenceAbsenceTermBase presence
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
349 Integer numberOfResults
= dao
.countDescriptionByDistribution(namedAreas
, presence
);
351 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
352 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
353 results
= dao
.searchDescriptionByDistribution(namedAreas
, presence
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
356 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
360 * FIXME Candidate for harmonization
361 * move: descriptionElementService.search
364 public Pager
<DescriptionElementBase
> searchElements(Class
<?
extends DescriptionElementBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
365 Integer numberOfResults
= descriptionElementDao
.count(clazz
, queryString
);
367 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
368 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
369 results
= descriptionElementDao
.search(clazz
, queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
372 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
376 * FIXME Candidate for harmonization
377 * descriptionElementService.find
380 public DescriptionElementBase
getDescriptionElementByUuid(UUID uuid
) {
381 return descriptionElementDao
.findByUuid(uuid
);
385 * FIXME Candidate for harmonization
386 * descriptionElementService.load
389 public DescriptionElementBase
loadDescriptionElement(UUID uuid
, List
<String
> propertyPaths
) {
390 return descriptionElementDao
.load(uuid
, propertyPaths
);
394 * FIXME Candidate for harmonization
395 * descriptionElementService.save
398 @Transactional(readOnly
= false)
399 public UUID
saveDescriptionElement(DescriptionElementBase descriptionElement
) {
400 return descriptionElementDao
.save(descriptionElement
);
404 * FIXME Candidate for harmonization
405 * descriptionElementService.save
408 @Transactional(readOnly
= false)
409 public Map
<UUID
, DescriptionElementBase
> saveDescriptionElement(Collection
<DescriptionElementBase
> descriptionElements
) {
410 return descriptionElementDao
.saveAll(descriptionElements
);
414 * FIXME Candidate for harmonization
415 * descriptionElementService.delete
418 public UUID
deleteDescriptionElement(DescriptionElementBase descriptionElement
) {
419 return descriptionElementDao
.delete(descriptionElement
);
423 public TermVocabulary
<Feature
> getFeatureVocabulary(UUID uuid
) {
424 return vocabularyDao
.findByUuid(uuid
);
429 public <T
extends DescriptionElementBase
> List
<T
> getDescriptionElementsForTaxon(
430 Taxon taxon
, Set
<Feature
> features
,
431 Class
<T
> type
, Integer pageSize
,
432 Integer pageNumber
, List
<String
> propertyPaths
) {
433 return listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
437 public <T
extends DescriptionElementBase
> List
<T
> listDescriptionElementsForTaxon(
438 Taxon taxon
, Set
<Feature
> features
,
439 Class
<T
> type
, Integer pageSize
,
440 Integer pageNumber
, List
<String
> propertyPaths
) {
441 return dao
.getDescriptionElementForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
445 public <T
extends DescriptionElementBase
> Pager
<T
> pageDescriptionElementsForTaxon(
446 Taxon taxon
, Set
<Feature
> features
,
447 Class
<T
> type
, Integer pageSize
,
448 Integer pageNumber
, List
<String
> propertyPaths
) {
449 Long count
= dao
.countDescriptionElementForTaxon(taxon
, features
, type
);
450 List
<T
> descriptionElements
;
451 if(AbstractPagerImpl
.hasResultsInRange(count
, pageNumber
, pageSize
)){ // no point checking again
452 descriptionElements
= listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
454 descriptionElements
= new ArrayList
<T
>(0);
456 return new DefaultPagerImpl
<T
>(pageNumber
, count
.intValue(), pageSize
, descriptionElements
);
461 * @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)
464 public String
generateNaturalLanguageDescription(FeatureTree featureTree
,
465 TaxonDescription description
, List
<Language
> preferredLanguages
, String separator
) {
467 Language lang
= preferredLanguages
.size() > 0 ? preferredLanguages
.get(0) : Language
.DEFAULT();
469 description
= (TaxonDescription
)load(description
.getUuid());
470 featureTree
= featureTreeDao
.load(featureTree
.getUuid());
472 StringBuilder naturalLanguageDescription
= new StringBuilder();
474 MarkerType useMarkerType
= (MarkerType
) definedTermDao
.load(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
475 boolean isUseDescription
= false;
476 if(!description
.getMarkers().isEmpty()) {
477 for (Marker marker
: description
.getMarkers()) {
478 MarkerType markerType
= marker
.getMarkerType();
479 if (markerType
.equals(useMarkerType
)) {
480 isUseDescription
= true;
486 if(description
.hasStructuredData() && !isUseDescription
){
489 String lastCategory
= null;
490 String categorySeparator
= ". ";
492 List
<TextData
> textDataList
;
493 TextData naturalLanguageDescriptionText
= null;
495 boolean useMicroFormatQuantitativeDescriptionBuilder
= false;
497 if(useMicroFormatQuantitativeDescriptionBuilder
){
499 MicroFormatQuantitativeDescriptionBuilder micro
= new MicroFormatQuantitativeDescriptionBuilder();
500 naturalLanguageGenerator
.setQuantitativeDescriptionBuilder(micro
);
501 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(featureTree
, (description
), lang
);
505 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(
511 return naturalLanguageDescriptionText
.getText(lang
);
514 // boolean doItBetter = false;
516 // for (TextData textData : textDataList.toArray(new TextData[textDataList.size()])){
517 // if(textData.getMultilanguageText().size() > 0){
519 // if (!textData.getFeature().equals(Feature.UNKNOWN())) {
520 // String featureLabel = textData.getFeature().getLabel(lang);
525 // * The code lines below are desinged to handle
526 // * a special case where as the feature label contains
527 // * hierarchical information on the features. This code
528 // * exist only as a base for discussion, and is not
529 // * intendet to be used in production.
531 // featureLabel = StringUtils.remove(featureLabel, '>');
533 // String[] labelTokens = StringUtils.split(featureLabel, '<');
534 // if(labelTokens[0].equals(lastCategory) && labelTokens.length > 1){
535 // if(naturalLanguageDescription.length() > 0){
536 // naturalLanguageDescription.append(separator);
538 // naturalLanguageDescription.append(labelTokens[1]);
540 // if(naturalLanguageDescription.length() > 0){
541 // naturalLanguageDescription.append(categorySeparator);
543 // naturalLanguageDescription.append(StringUtils.join(labelTokens));
545 // lastCategory = labelTokens[0];
546 // // end of demo code
548 // if(naturalLanguageDescription.length() > 0){
549 // naturalLanguageDescription.append(separator);
551 // naturalLanguageDescription.append(textData.getFeature().getLabel(lang));
554 // if(naturalLanguageDescription.length() > 0){
555 // naturalLanguageDescription.append(separator);
558 // String text = textData.getMultilanguageText().values().iterator().next().getText();
559 // naturalLanguageDescription.append(text);
565 else if (isUseDescription
) {
566 //AT: Left Blank in case we need to generate a Natural language text string.
568 return naturalLanguageDescription
.toString();
572 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#hasStructuredData(eu.etaxonomy.cdm.model.description.DescriptionBase)
575 public boolean hasStructuredData(DescriptionBase
<?
> description
) {
576 return load(description
.getUuid()).hasStructuredData();
581 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveDescriptionElementsToDescription(java.util.Collection, eu.etaxonomy.cdm.model.description.DescriptionBase, boolean)
584 public void moveDescriptionElementsToDescription(Collection
<DescriptionElementBase
> descriptionElements
,
585 DescriptionBase targetDescription
, boolean isCopy
) {
587 if (descriptionElements
.isEmpty() ){
591 if (! isCopy
&& descriptionElements
== descriptionElements
.iterator().next().getInDescription().getElements()){
592 //if the descriptionElements collection is the elements set of a description, put it in a separate set before to avoid concurrent modification exceptions
593 descriptionElements
= new HashSet
<DescriptionElementBase
>(descriptionElements
);
594 // descriptionElementsTmp.addAll(descriptionElements);
595 // descriptionElements = descriptionElementsTmp;
597 for (DescriptionElementBase element
: descriptionElements
){
598 DescriptionBase description
= element
.getInDescription();
600 DescriptionElementBase newElement
= (DescriptionElementBase
)element
.clone();
601 targetDescription
.addElement(newElement
);
602 } catch (CloneNotSupportedException e
) {
603 new RuntimeException ("Clone not yet implemented for class " + element
.getClass().getName(), e
);
606 description
.removeElement(element
);
612 public void aggregateDistributions(List
<NamedArea
> superAreas
, Rank lowerRank
, Rank upperRank
) {
614 // transmissionEngineDistribution engine = new transmissionEngineDistribution(superAreas, lowerRank, upperRank);