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
.TaxonNameBase
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
51 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.IDefinedTermDao
;
52 import eu
.etaxonomy
.cdm
.persistence
.dao
.common
.ITermVocabularyDao
;
53 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionDao
;
54 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IDescriptionElementDao
;
55 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureDao
;
56 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureNodeDao
;
57 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IFeatureTreeDao
;
58 import eu
.etaxonomy
.cdm
.persistence
.dao
.description
.IStatisticalMeasurementValueDao
;
59 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
60 import eu
.etaxonomy
.cdm
.strategy
.cache
.common
.IIdentifiableEntityCacheStrategy
;
68 * @author a.kohlbecker
73 @Transactional(readOnly
= true)
74 public class DescriptionServiceImpl
extends IdentifiableServiceBase
<DescriptionBase
,IDescriptionDao
> implements IDescriptionService
{
76 private static final Logger logger
= Logger
.getLogger(DescriptionServiceImpl
.class);
78 protected IDescriptionElementDao descriptionElementDao
;
79 protected IFeatureTreeDao featureTreeDao
;
80 protected IFeatureNodeDao featureNodeDao
;
81 protected IFeatureDao featureDao
;
82 protected ITermVocabularyDao vocabularyDao
;
83 protected IDefinedTermDao definedTermDao
;
84 protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao
;
85 //TODO change to Interface
86 private NaturalLanguageGenerator naturalLanguageGenerator
;
89 protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao
) {
90 this.featureTreeDao
= featureTreeDao
;
94 protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao
) {
95 this.featureNodeDao
= featureNodeDao
;
99 protected void setFeatureDao(IFeatureDao featureDao
) {
100 this.featureDao
= featureDao
;
104 protected void setVocabularyDao(ITermVocabularyDao vocabularyDao
) {
105 this.vocabularyDao
= vocabularyDao
;
109 protected void setDefinedTermDao(IDefinedTermDao definedTermDao
) {
110 this.definedTermDao
= definedTermDao
;
114 protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao
) {
115 this.statisticalMeasurementValueDao
= statisticalMeasurementValueDao
;
119 protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao
) {
120 this.descriptionElementDao
= descriptionElementDao
;
124 protected void setNaturalLanguageGenerator(NaturalLanguageGenerator naturalLanguageGenerator
) {
125 this.naturalLanguageGenerator
= naturalLanguageGenerator
;
131 public DescriptionServiceImpl() {
132 logger
.debug("Load DescriptionService Bean");
138 * @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
141 @Transactional(readOnly
= false)
142 public void updateTitleCache(Class
<?
extends DescriptionBase
> clazz
, Integer stepSize
, IIdentifiableEntityCacheStrategy
<DescriptionBase
> cacheStrategy
, IProgressMonitor monitor
) {
144 clazz
= DescriptionBase
.class;
146 super.updateTitleCacheImpl(clazz
, stepSize
, cacheStrategy
, monitor
);
151 public TermVocabulary
<Feature
> getDefaultFeatureVocabulary(){
152 String uuidFeature
= "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
153 UUID featureUuid
= UUID
.fromString(uuidFeature
);
154 return vocabularyDao
.findByUuid(featureUuid
);
159 protected void setDao(IDescriptionDao dao
) {
164 public int count(Class
<?
extends DescriptionBase
> type
, Boolean hasImages
, Boolean hasText
,Set
<Feature
> feature
) {
165 return dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
169 public Pager
<DescriptionElementBase
> pageDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
170 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
172 List
<DescriptionElementBase
> results
= listDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
173 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, results
.size(), pageSize
, results
);
177 * @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)
181 public Pager
<DescriptionElementBase
> getDescriptionElements(DescriptionBase description
,
182 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
183 return pageDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
187 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
, Class
<?
extends DescriptionBase
> descriptionType
,
188 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
190 Integer numberOfResults
= dao
.countDescriptionElements(description
, descriptionType
, features
, type
);
191 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
192 if(AbstractPagerImpl
.hasResultsInRange(numberOfResults
.longValue(), pageNumber
, pageSize
)) {
193 results
= dao
.getDescriptionElements(description
, descriptionType
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
199 * @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)
203 public List
<DescriptionElementBase
> listDescriptionElements(DescriptionBase description
,
204 Set
<Feature
> features
, Class
<?
extends DescriptionElementBase
> type
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
206 return listDescriptionElements(description
, null, features
, type
, pageSize
, pageNumber
, propertyPaths
);
210 public Pager
<Annotation
> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj
, MarkerType status
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
){
211 Integer numberOfResults
= descriptionElementDao
.countAnnotations(annotatedObj
, status
);
213 List
<Annotation
> results
= new ArrayList
<Annotation
>();
214 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
215 results
= descriptionElementDao
.getAnnotations(annotatedObj
, status
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
218 return new DefaultPagerImpl
<Annotation
>(pageNumber
, numberOfResults
, pageSize
, results
);
224 public Pager
<Media
> getMedia(DescriptionElementBase descriptionElement
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
225 Integer numberOfResults
= descriptionElementDao
.countMedia(descriptionElement
);
227 List
<Media
> results
= new ArrayList
<Media
>();
228 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
229 results
= descriptionElementDao
.getMedia(descriptionElement
, pageSize
, pageNumber
, propertyPaths
);
232 return new DefaultPagerImpl
<Media
>(pageNumber
, numberOfResults
, pageSize
, results
);
236 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
237 Set
<MarkerType
> markerTypes
= null;
238 return pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
242 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
243 Set
<MarkerType
> markerTypes
= null;
244 return listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
249 * @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)
252 public Pager
<TaxonDescription
> pageTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
253 Integer numberOfResults
= dao
.countTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
);
255 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
256 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
257 results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
260 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
264 public List
<TaxonDescription
> listTaxonDescriptions(Taxon taxon
, Set
<DefinedTerm
> scopes
, Set
<NamedArea
> geographicalScope
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
265 List
<TaxonDescription
> results
= dao
.listTaxonDescriptions(taxon
, scopes
, geographicalScope
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
271 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
274 public List
<Media
> listTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
){
275 return this.dao
.listTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
, pageSize
, pageNumber
, propertyPaths
);
279 * @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
282 public int countTaxonDescriptionMedia(UUID taxonUuid
, boolean limitToGalleries
, Set
<MarkerType
> markerTypes
){
283 return this.dao
.countTaxonDescriptionMedia(taxonUuid
, limitToGalleries
, markerTypes
);
288 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#getOrderedDistributions(java.util.Set, boolean, boolean, java.util.Set, java.util.List)
292 public DistributionTree
getOrderedDistributions(
293 Set
<TaxonDescription
> taxonDescriptions
,
294 boolean subAreaPreference
,
295 boolean statusOrderPreference
,
296 Set
<MarkerType
> hideMarkedAreas
,
297 Set
<NamedAreaLevel
> omitLevels
, List
<String
> propertyPaths
){
299 List
<Distribution
> distList
= new ArrayList
<Distribution
>();
301 List
<UUID
> uuids
= new ArrayList
<UUID
>();
302 for (TaxonDescription taxonDescription
: taxonDescriptions
) {
303 if (! taxonDescription
.isImageGallery()){ //image galleries should not have descriptions, but better filter fully on DTYPE of description element
304 uuids
.add(taxonDescription
.getUuid());
308 List
<DescriptionBase
> desclist
= dao
.list(uuids
, null, null, null, propertyPaths
);
309 for (DescriptionBase desc
: desclist
) {
310 if (desc
.isInstanceOf(TaxonDescription
.class)){
311 Set
<DescriptionElementBase
> elements
= desc
.getElements();
312 for (DescriptionElementBase element
: elements
) {
313 if (element
.isInstanceOf(Distribution
.class)) {
314 Distribution distribution
= (Distribution
) element
;
315 if(distribution
.getArea() != null){
316 distList
.add(distribution
);
324 // for (TaxonDescription taxonDescription : taxonDescriptions) {
325 // if (logger.isDebugEnabled()){ logger.debug("load taxon description " + taxonDescription.getUuid());}
326 // //TODO why not loading all description via .list ? This may improve performance
327 // taxonDescription = (TaxonDescription) dao.load(taxonDescription.getUuid(), propertyPaths);
328 // Set<DescriptionElementBase> elements = taxonDescription.getElements();
329 // for (DescriptionElementBase element : elements) {
330 // if (element.isInstanceOf(Distribution.class)) {
331 // Distribution distribution = (Distribution) element;
332 // if(distribution.getArea() != null){
333 // distList.add(distribution);
339 if (logger
.isDebugEnabled()){logger
.debug("filter tree for " + distList
.size() + " distributions ...");}
341 // filter distributions
342 Collection
<Distribution
> filteredDistributions
= DescriptionUtility
.filterDistributions(distList
, subAreaPreference
, statusOrderPreference
, hideMarkedAreas
);
344 distList
.addAll(filteredDistributions
);
346 return DescriptionUtility
.orderDistributions(omitLevels
, distList
);
351 public Pager
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase name
, Integer pageSize
, Integer pageNumber
, List
<String
> propertyPaths
) {
352 Integer numberOfResults
= dao
.countTaxonNameDescriptions(name
);
354 List
<TaxonNameDescription
> results
= new ArrayList
<TaxonNameDescription
>();
355 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
356 results
= dao
.getTaxonNameDescriptions(name
, pageSize
, pageNumber
,propertyPaths
);
359 return new DefaultPagerImpl
<TaxonNameDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
364 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
) {
365 Integer numberOfResults
= dao
.countDescriptions(type
, hasImages
, hasText
, feature
);
367 List
<DescriptionBase
> results
= new ArrayList
<DescriptionBase
>();
368 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
369 results
= dao
.listDescriptions(type
, hasImages
, hasText
, feature
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
372 return new DefaultPagerImpl
<DescriptionBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
376 * FIXME Candidate for harmonization
377 * Rename: searchByDistribution
380 public Pager
<TaxonDescription
> searchDescriptionByDistribution(Set
<NamedArea
> namedAreas
, PresenceAbsenceTermBase presence
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
381 Integer numberOfResults
= dao
.countDescriptionByDistribution(namedAreas
, presence
);
383 List
<TaxonDescription
> results
= new ArrayList
<TaxonDescription
>();
384 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
385 results
= dao
.searchDescriptionByDistribution(namedAreas
, presence
, pageSize
, pageNumber
,orderHints
,propertyPaths
);
388 return new DefaultPagerImpl
<TaxonDescription
>(pageNumber
, numberOfResults
, pageSize
, results
);
392 * FIXME Candidate for harmonization
393 * move: descriptionElementService.search
396 public Pager
<DescriptionElementBase
> searchElements(Class
<?
extends DescriptionElementBase
> clazz
, String queryString
, Integer pageSize
, Integer pageNumber
, List
<OrderHint
> orderHints
, List
<String
> propertyPaths
) {
397 Integer numberOfResults
= descriptionElementDao
.count(clazz
, queryString
);
399 List
<DescriptionElementBase
> results
= new ArrayList
<DescriptionElementBase
>();
400 if(numberOfResults
> 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
401 results
= descriptionElementDao
.search(clazz
, queryString
, pageSize
, pageNumber
, orderHints
, propertyPaths
);
404 return new DefaultPagerImpl
<DescriptionElementBase
>(pageNumber
, numberOfResults
, pageSize
, results
);
408 * FIXME Candidate for harmonization
409 * descriptionElementService.find
412 public DescriptionElementBase
getDescriptionElementByUuid(UUID uuid
) {
413 return descriptionElementDao
.findByUuid(uuid
);
417 * FIXME Candidate for harmonization
418 * descriptionElementService.load
421 public DescriptionElementBase
loadDescriptionElement(UUID uuid
, List
<String
> propertyPaths
) {
422 return descriptionElementDao
.load(uuid
, propertyPaths
);
426 * FIXME Candidate for harmonization
427 * descriptionElementService.save
430 @Transactional(readOnly
= false)
431 public UUID
saveDescriptionElement(DescriptionElementBase descriptionElement
) {
432 return descriptionElementDao
.save(descriptionElement
);
436 * FIXME Candidate for harmonization
437 * descriptionElementService.save
440 @Transactional(readOnly
= false)
441 public Map
<UUID
, DescriptionElementBase
> saveDescriptionElement(Collection
<DescriptionElementBase
> descriptionElements
) {
442 return descriptionElementDao
.saveAll(descriptionElements
);
446 * FIXME Candidate for harmonization
447 * descriptionElementService.delete
450 public UUID
deleteDescriptionElement(DescriptionElementBase descriptionElement
) {
451 return descriptionElementDao
.delete(descriptionElement
);
455 public TermVocabulary
<Feature
> getFeatureVocabulary(UUID uuid
) {
456 return vocabularyDao
.findByUuid(uuid
);
461 public <T
extends DescriptionElementBase
> List
<T
> getDescriptionElementsForTaxon(
462 Taxon taxon
, Set
<Feature
> features
,
463 Class
<T
> type
, Integer pageSize
,
464 Integer pageNumber
, List
<String
> propertyPaths
) {
465 return listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
469 public <T
extends DescriptionElementBase
> List
<T
> listDescriptionElementsForTaxon(
470 Taxon taxon
, Set
<Feature
> features
,
471 Class
<T
> type
, Integer pageSize
,
472 Integer pageNumber
, List
<String
> propertyPaths
) {
473 return dao
.getDescriptionElementForTaxon(taxon
.getUuid(), features
, type
, pageSize
, pageNumber
, propertyPaths
);
477 public <T
extends DescriptionElementBase
> Pager
<T
> pageDescriptionElementsForTaxon(
478 Taxon taxon
, Set
<Feature
> features
,
479 Class
<T
> type
, Integer pageSize
,
480 Integer pageNumber
, List
<String
> propertyPaths
) {
481 if (logger
.isDebugEnabled()){logger
.debug(" get count ...");}
482 Long count
= dao
.countDescriptionElementForTaxon(taxon
.getUuid(), features
, type
);
483 List
<T
> descriptionElements
;
484 if(AbstractPagerImpl
.hasResultsInRange(count
, pageNumber
, pageSize
)){ // no point checking again
485 if (logger
.isDebugEnabled()){logger
.debug(" get list ...");}
486 descriptionElements
= listDescriptionElementsForTaxon(taxon
, features
, type
, pageSize
, pageNumber
, propertyPaths
);
488 descriptionElements
= new ArrayList
<T
>(0);
490 if (logger
.isDebugEnabled()){logger
.debug(" service - DONE ...");}
491 return new DefaultPagerImpl
<T
>(pageNumber
, count
.intValue(), pageSize
, descriptionElements
);
496 * @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)
499 public String
generateNaturalLanguageDescription(FeatureTree featureTree
,
500 TaxonDescription description
, List
<Language
> preferredLanguages
, String separator
) {
502 Language lang
= preferredLanguages
.size() > 0 ? preferredLanguages
.get(0) : Language
.DEFAULT();
504 description
= (TaxonDescription
)load(description
.getUuid());
505 featureTree
= featureTreeDao
.load(featureTree
.getUuid());
507 StringBuilder naturalLanguageDescription
= new StringBuilder();
509 MarkerType useMarkerType
= (MarkerType
) definedTermDao
.load(UUID
.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
510 boolean isUseDescription
= false;
511 if(!description
.getMarkers().isEmpty()) {
512 for (Marker marker
: description
.getMarkers()) {
513 MarkerType markerType
= marker
.getMarkerType();
514 if (markerType
.equals(useMarkerType
)) {
515 isUseDescription
= true;
521 if(description
.hasStructuredData() && !isUseDescription
){
524 String lastCategory
= null;
525 String categorySeparator
= ". ";
527 List
<TextData
> textDataList
;
528 TextData naturalLanguageDescriptionText
= null;
530 boolean useMicroFormatQuantitativeDescriptionBuilder
= false;
532 if(useMicroFormatQuantitativeDescriptionBuilder
){
534 MicroFormatQuantitativeDescriptionBuilder micro
= new MicroFormatQuantitativeDescriptionBuilder();
535 naturalLanguageGenerator
.setQuantitativeDescriptionBuilder(micro
);
536 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(featureTree
, (description
), lang
);
540 naturalLanguageDescriptionText
= naturalLanguageGenerator
.generateSingleTextData(
546 return naturalLanguageDescriptionText
.getText(lang
);
549 // boolean doItBetter = false;
551 // for (TextData textData : textDataList.toArray(new TextData[textDataList.size()])){
552 // if(textData.getMultilanguageText().size() > 0){
554 // if (!textData.getFeature().equals(Feature.UNKNOWN())) {
555 // String featureLabel = textData.getFeature().getLabel(lang);
560 // * The code lines below are desinged to handle
561 // * a special case where as the feature label contains
562 // * hierarchical information on the features. This code
563 // * exist only as a base for discussion, and is not
564 // * intendet to be used in production.
566 // featureLabel = StringUtils.remove(featureLabel, '>');
568 // String[] labelTokens = StringUtils.split(featureLabel, '<');
569 // if(labelTokens[0].equals(lastCategory) && labelTokens.length > 1){
570 // if(naturalLanguageDescription.length() > 0){
571 // naturalLanguageDescription.append(separator);
573 // naturalLanguageDescription.append(labelTokens[1]);
575 // if(naturalLanguageDescription.length() > 0){
576 // naturalLanguageDescription.append(categorySeparator);
578 // naturalLanguageDescription.append(StringUtils.join(labelTokens));
580 // lastCategory = labelTokens[0];
581 // // end of demo code
583 // if(naturalLanguageDescription.length() > 0){
584 // naturalLanguageDescription.append(separator);
586 // naturalLanguageDescription.append(textData.getFeature().getLabel(lang));
589 // if(naturalLanguageDescription.length() > 0){
590 // naturalLanguageDescription.append(separator);
593 // String text = textData.getMultilanguageText().values().iterator().next().getText();
594 // naturalLanguageDescription.append(text);
600 else if (isUseDescription
) {
601 //AT: Left Blank in case we need to generate a Natural language text string.
603 return naturalLanguageDescription
.toString();
607 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#hasStructuredData(eu.etaxonomy.cdm.model.description.DescriptionBase)
610 public boolean hasStructuredData(DescriptionBase
<?
> description
) {
611 return load(description
.getUuid()).hasStructuredData();
616 * @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveDescriptionElementsToDescription(java.util.Collection, eu.etaxonomy.cdm.model.description.DescriptionBase, boolean)
619 public void moveDescriptionElementsToDescription(Collection
<DescriptionElementBase
> descriptionElements
,
620 DescriptionBase targetDescription
, boolean isCopy
) {
622 if (descriptionElements
.isEmpty() ){
626 if (! isCopy
&& descriptionElements
== descriptionElements
.iterator().next().getInDescription().getElements()){
627 //if the descriptionElements collection is the elements set of a description, put it in a separate set before to avoid concurrent modification exceptions
628 descriptionElements
= new HashSet
<DescriptionElementBase
>(descriptionElements
);
629 // descriptionElementsTmp.addAll(descriptionElements);
630 // descriptionElements = descriptionElementsTmp;
632 for (DescriptionElementBase element
: descriptionElements
){
633 DescriptionBase description
= element
.getInDescription();
635 DescriptionElementBase newElement
= (DescriptionElementBase
)element
.clone();
636 targetDescription
.addElement(newElement
);
637 } catch (CloneNotSupportedException e
) {
638 new RuntimeException ("Clone not yet implemented for class " + element
.getClass().getName(), e
);
641 description
.removeElement(element
);
648 public Pager
<NamedArea
> pageNamedAreasInUse(Integer pageSize
,
649 Integer pageNumber
, List
<String
> propertyPaths
){
651 List
<NamedArea
> results
= dao
.listNamedAreasInUse(pageSize
, pageNumber
, propertyPaths
);
652 return new DefaultPagerImpl
<NamedArea
>(pageNumber
, results
.size(), pageSize
, results
);