1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.api.service;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.Collection;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
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;
|
25
|
|
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.PresenceAbsenceTerm;
|
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;
|
61
|
|
62
|
/**
|
63
|
* @author a.mueller
|
64
|
* @created 24.06.2008
|
65
|
* @version 1.0
|
66
|
*/
|
67
|
/**
|
68
|
* @author a.kohlbecker
|
69
|
* @date Dec 5, 2013
|
70
|
*
|
71
|
*/
|
72
|
@Service
|
73
|
@Transactional(readOnly = true)
|
74
|
public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao> implements IDescriptionService {
|
75
|
|
76
|
private static final Logger logger = Logger.getLogger(DescriptionServiceImpl.class);
|
77
|
|
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;
|
87
|
|
88
|
@Autowired
|
89
|
protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao) {
|
90
|
this.featureTreeDao = featureTreeDao;
|
91
|
}
|
92
|
|
93
|
@Autowired
|
94
|
protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
|
95
|
this.featureNodeDao = featureNodeDao;
|
96
|
}
|
97
|
|
98
|
@Autowired
|
99
|
protected void setFeatureDao(IFeatureDao featureDao) {
|
100
|
this.featureDao = featureDao;
|
101
|
}
|
102
|
|
103
|
@Autowired
|
104
|
protected void setVocabularyDao(ITermVocabularyDao vocabularyDao) {
|
105
|
this.vocabularyDao = vocabularyDao;
|
106
|
}
|
107
|
|
108
|
@Autowired
|
109
|
protected void setDefinedTermDao(IDefinedTermDao definedTermDao) {
|
110
|
this.definedTermDao = definedTermDao;
|
111
|
}
|
112
|
|
113
|
@Autowired
|
114
|
protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao) {
|
115
|
this.statisticalMeasurementValueDao = statisticalMeasurementValueDao;
|
116
|
}
|
117
|
|
118
|
@Autowired
|
119
|
protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao) {
|
120
|
this.descriptionElementDao = descriptionElementDao;
|
121
|
}
|
122
|
|
123
|
@Autowired
|
124
|
protected void setNaturalLanguageGenerator(NaturalLanguageGenerator naturalLanguageGenerator) {
|
125
|
this.naturalLanguageGenerator = naturalLanguageGenerator;
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
*
|
130
|
*/
|
131
|
public DescriptionServiceImpl() {
|
132
|
logger.debug("Load DescriptionService Bean");
|
133
|
}
|
134
|
|
135
|
|
136
|
|
137
|
/* (non-Javadoc)
|
138
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
139
|
*/
|
140
|
@Override
|
141
|
@Transactional(readOnly = false)
|
142
|
public void updateTitleCache(Class<? extends DescriptionBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<DescriptionBase> cacheStrategy, IProgressMonitor monitor) {
|
143
|
if (clazz == null){
|
144
|
clazz = DescriptionBase.class;
|
145
|
}
|
146
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
147
|
}
|
148
|
|
149
|
|
150
|
@Override
|
151
|
public TermVocabulary<Feature> getDefaultFeatureVocabulary(){
|
152
|
String uuidFeature = "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
|
153
|
UUID featureUuid = UUID.fromString(uuidFeature);
|
154
|
return vocabularyDao.findByUuid(featureUuid);
|
155
|
}
|
156
|
|
157
|
@Override
|
158
|
@Autowired
|
159
|
protected void setDao(IDescriptionDao dao) {
|
160
|
this.dao = dao;
|
161
|
}
|
162
|
|
163
|
@Override
|
164
|
public int count(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText,Set<Feature> feature) {
|
165
|
return dao.countDescriptions(type, hasImages, hasText, feature);
|
166
|
}
|
167
|
|
168
|
@Override
|
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) {
|
171
|
|
172
|
List<DescriptionElementBase> results = listDescriptionElements(description, descriptionType, features, type, pageSize, pageNumber, propertyPaths);
|
173
|
return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, results.size(), pageSize, results);
|
174
|
}
|
175
|
|
176
|
/* (non-Javadoc)
|
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)
|
178
|
*/
|
179
|
@Override
|
180
|
@Deprecated
|
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);
|
184
|
}
|
185
|
|
186
|
@Override
|
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) {
|
189
|
|
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);
|
194
|
}
|
195
|
return results;
|
196
|
}
|
197
|
|
198
|
/* (non-Javadoc)
|
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)
|
200
|
*/
|
201
|
@Override
|
202
|
@Deprecated
|
203
|
public List<DescriptionElementBase> listDescriptionElements(DescriptionBase description,
|
204
|
Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
205
|
|
206
|
return listDescriptionElements(description, null, features, type, pageSize, pageNumber, propertyPaths);
|
207
|
}
|
208
|
|
209
|
@Override
|
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);
|
212
|
|
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);
|
216
|
}
|
217
|
|
218
|
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
|
219
|
}
|
220
|
|
221
|
|
222
|
|
223
|
@Override
|
224
|
public Pager<Media> getMedia(DescriptionElementBase descriptionElement, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
225
|
Integer numberOfResults = descriptionElementDao.countMedia(descriptionElement);
|
226
|
|
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);
|
230
|
}
|
231
|
|
232
|
return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);
|
233
|
}
|
234
|
|
235
|
@Override
|
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);
|
239
|
}
|
240
|
|
241
|
@Override
|
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);
|
245
|
}
|
246
|
|
247
|
|
248
|
/* (non-Javadoc)
|
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)
|
250
|
*/
|
251
|
@Override
|
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);
|
254
|
|
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);
|
258
|
}
|
259
|
|
260
|
return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
|
261
|
}
|
262
|
|
263
|
@Override
|
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);
|
266
|
return results;
|
267
|
}
|
268
|
|
269
|
|
270
|
/* (non-Javadoc)
|
271
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
|
272
|
*/
|
273
|
@Override
|
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);
|
276
|
}
|
277
|
|
278
|
/*
|
279
|
* @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
|
280
|
*/
|
281
|
@Override
|
282
|
public int countTaxonDescriptionMedia(UUID taxonUuid, boolean limitToGalleries, Set<MarkerType> markerTypes){
|
283
|
return this.dao.countTaxonDescriptionMedia(taxonUuid, limitToGalleries, markerTypes);
|
284
|
}
|
285
|
|
286
|
|
287
|
/* (non-Javadoc)
|
288
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#getOrderedDistributions(java.util.Set, boolean, boolean, java.util.Set, java.util.List)
|
289
|
*/
|
290
|
@Override
|
291
|
@Deprecated
|
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){
|
298
|
|
299
|
List<Distribution> distList = new ArrayList<Distribution>();
|
300
|
|
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());
|
305
|
}
|
306
|
}
|
307
|
|
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);
|
317
|
}
|
318
|
}
|
319
|
}
|
320
|
}
|
321
|
}
|
322
|
|
323
|
//old
|
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);
|
334
|
// }
|
335
|
// }
|
336
|
// }
|
337
|
// }
|
338
|
|
339
|
if (logger.isDebugEnabled()){logger.debug("filter tree for " + distList.size() + " distributions ...");}
|
340
|
|
341
|
// filter distributions
|
342
|
Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(distList, subAreaPreference, statusOrderPreference, hideMarkedAreas);
|
343
|
distList.clear();
|
344
|
distList.addAll(filteredDistributions);
|
345
|
|
346
|
return DescriptionUtility.orderDistributions(omitLevels, distList);
|
347
|
}
|
348
|
|
349
|
|
350
|
@Override
|
351
|
public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
352
|
Integer numberOfResults = dao.countTaxonNameDescriptions(name);
|
353
|
|
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);
|
357
|
}
|
358
|
|
359
|
return new DefaultPagerImpl<TaxonNameDescription>(pageNumber, numberOfResults, pageSize, results);
|
360
|
}
|
361
|
|
362
|
|
363
|
@Override
|
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);
|
366
|
|
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);
|
370
|
}
|
371
|
|
372
|
return new DefaultPagerImpl<DescriptionBase>(pageNumber, numberOfResults, pageSize, results);
|
373
|
}
|
374
|
|
375
|
/**
|
376
|
* FIXME Candidate for harmonization
|
377
|
* Rename: searchByDistribution
|
378
|
*/
|
379
|
@Override
|
380
|
public Pager<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTerm presence, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
381
|
Integer numberOfResults = dao.countDescriptionByDistribution(namedAreas, presence);
|
382
|
|
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);
|
386
|
}
|
387
|
|
388
|
return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
|
389
|
}
|
390
|
|
391
|
/**
|
392
|
* FIXME Candidate for harmonization
|
393
|
* move: descriptionElementService.search
|
394
|
*/
|
395
|
@Override
|
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);
|
398
|
|
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);
|
402
|
}
|
403
|
|
404
|
return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, numberOfResults, pageSize, results);
|
405
|
}
|
406
|
|
407
|
/**
|
408
|
* FIXME Candidate for harmonization
|
409
|
* descriptionElementService.find
|
410
|
*/
|
411
|
@Override
|
412
|
public DescriptionElementBase getDescriptionElementByUuid(UUID uuid) {
|
413
|
return descriptionElementDao.findByUuid(uuid);
|
414
|
}
|
415
|
|
416
|
/**
|
417
|
* FIXME Candidate for harmonization
|
418
|
* descriptionElementService.load
|
419
|
*/
|
420
|
@Override
|
421
|
public DescriptionElementBase loadDescriptionElement(UUID uuid, List<String> propertyPaths) {
|
422
|
return descriptionElementDao.load(uuid, propertyPaths);
|
423
|
}
|
424
|
|
425
|
/**
|
426
|
* FIXME Candidate for harmonization
|
427
|
* descriptionElementService.save
|
428
|
*/
|
429
|
@Override
|
430
|
@Transactional(readOnly = false)
|
431
|
public UUID saveDescriptionElement(DescriptionElementBase descriptionElement) {
|
432
|
return descriptionElementDao.save(descriptionElement);
|
433
|
}
|
434
|
|
435
|
/**
|
436
|
* FIXME Candidate for harmonization
|
437
|
* descriptionElementService.save
|
438
|
*/
|
439
|
@Override
|
440
|
@Transactional(readOnly = false)
|
441
|
public Map<UUID, DescriptionElementBase> saveDescriptionElement(Collection<DescriptionElementBase> descriptionElements) {
|
442
|
return descriptionElementDao.saveAll(descriptionElements);
|
443
|
}
|
444
|
|
445
|
/**
|
446
|
* FIXME Candidate for harmonization
|
447
|
* descriptionElementService.delete
|
448
|
*/
|
449
|
@Override
|
450
|
public UUID deleteDescriptionElement(DescriptionElementBase descriptionElement) {
|
451
|
return descriptionElementDao.delete(descriptionElement);
|
452
|
}
|
453
|
|
454
|
@Override
|
455
|
public TermVocabulary<Feature> getFeatureVocabulary(UUID uuid) {
|
456
|
return vocabularyDao.findByUuid(uuid);
|
457
|
}
|
458
|
|
459
|
@Override
|
460
|
@Deprecated
|
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);
|
466
|
}
|
467
|
|
468
|
@Override
|
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);
|
474
|
}
|
475
|
|
476
|
@Override
|
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);
|
487
|
} else {
|
488
|
descriptionElements = new ArrayList<T>(0);
|
489
|
}
|
490
|
if (logger.isDebugEnabled()){logger.debug(" service - DONE ...");}
|
491
|
return new DefaultPagerImpl<T>(pageNumber, count.intValue(), pageSize, descriptionElements);
|
492
|
}
|
493
|
|
494
|
|
495
|
/* (non-Javadoc)
|
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)
|
497
|
*/
|
498
|
@Override
|
499
|
public String generateNaturalLanguageDescription(FeatureTree featureTree,
|
500
|
TaxonDescription description, List<Language> preferredLanguages, String separator) {
|
501
|
|
502
|
Language lang = preferredLanguages.size() > 0 ? preferredLanguages.get(0) : Language.DEFAULT();
|
503
|
|
504
|
description = (TaxonDescription)load(description.getUuid());
|
505
|
featureTree = featureTreeDao.load(featureTree.getUuid());
|
506
|
|
507
|
StringBuilder naturalLanguageDescription = new StringBuilder();
|
508
|
|
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;
|
516
|
}
|
517
|
|
518
|
}
|
519
|
}
|
520
|
|
521
|
if(description.hasStructuredData() && !isUseDescription){
|
522
|
|
523
|
|
524
|
String lastCategory = null;
|
525
|
String categorySeparator = ". ";
|
526
|
|
527
|
List<TextData> textDataList;
|
528
|
TextData naturalLanguageDescriptionText = null;
|
529
|
|
530
|
boolean useMicroFormatQuantitativeDescriptionBuilder = false;
|
531
|
|
532
|
if(useMicroFormatQuantitativeDescriptionBuilder){
|
533
|
|
534
|
MicroFormatQuantitativeDescriptionBuilder micro = new MicroFormatQuantitativeDescriptionBuilder();
|
535
|
naturalLanguageGenerator.setQuantitativeDescriptionBuilder(micro);
|
536
|
naturalLanguageDescriptionText = naturalLanguageGenerator.generateSingleTextData(featureTree, (description), lang);
|
537
|
|
538
|
} else {
|
539
|
|
540
|
naturalLanguageDescriptionText = naturalLanguageGenerator.generateSingleTextData(
|
541
|
featureTree,
|
542
|
(description),
|
543
|
lang);
|
544
|
}
|
545
|
|
546
|
return naturalLanguageDescriptionText.getText(lang);
|
547
|
|
548
|
//
|
549
|
// boolean doItBetter = false;
|
550
|
//
|
551
|
// for (TextData textData : textDataList.toArray(new TextData[textDataList.size()])){
|
552
|
// if(textData.getMultilanguageText().size() > 0){
|
553
|
//
|
554
|
// if (!textData.getFeature().equals(Feature.UNKNOWN())) {
|
555
|
// String featureLabel = textData.getFeature().getLabel(lang);
|
556
|
//
|
557
|
// if(doItBetter){
|
558
|
// /*
|
559
|
// * WARNING
|
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.
|
565
|
// */
|
566
|
// featureLabel = StringUtils.remove(featureLabel, '>');
|
567
|
//
|
568
|
// String[] labelTokens = StringUtils.split(featureLabel, '<');
|
569
|
// if(labelTokens[0].equals(lastCategory) && labelTokens.length > 1){
|
570
|
// if(naturalLanguageDescription.length() > 0){
|
571
|
// naturalLanguageDescription.append(separator);
|
572
|
// }
|
573
|
// naturalLanguageDescription.append(labelTokens[1]);
|
574
|
// } else {
|
575
|
// if(naturalLanguageDescription.length() > 0){
|
576
|
// naturalLanguageDescription.append(categorySeparator);
|
577
|
// }
|
578
|
// naturalLanguageDescription.append(StringUtils.join(labelTokens));
|
579
|
// }
|
580
|
// lastCategory = labelTokens[0];
|
581
|
// // end of demo code
|
582
|
// } else {
|
583
|
// if(naturalLanguageDescription.length() > 0){
|
584
|
// naturalLanguageDescription.append(separator);
|
585
|
// }
|
586
|
// naturalLanguageDescription.append(textData.getFeature().getLabel(lang));
|
587
|
// }
|
588
|
// } else {
|
589
|
// if(naturalLanguageDescription.length() > 0){
|
590
|
// naturalLanguageDescription.append(separator);
|
591
|
// }
|
592
|
// }
|
593
|
// String text = textData.getMultilanguageText().values().iterator().next().getText();
|
594
|
// naturalLanguageDescription.append(text);
|
595
|
//
|
596
|
// }
|
597
|
// }
|
598
|
|
599
|
}
|
600
|
else if (isUseDescription) {
|
601
|
//AT: Left Blank in case we need to generate a Natural language text string.
|
602
|
}
|
603
|
return naturalLanguageDescription.toString();
|
604
|
}
|
605
|
|
606
|
/* (non-Javadoc)
|
607
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#hasStructuredData(eu.etaxonomy.cdm.model.description.DescriptionBase)
|
608
|
*/
|
609
|
@Override
|
610
|
public boolean hasStructuredData(DescriptionBase<?> description) {
|
611
|
return load(description.getUuid()).hasStructuredData();
|
612
|
}
|
613
|
|
614
|
|
615
|
/* (non-Javadoc)
|
616
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveDescriptionElementsToDescription(java.util.Collection, eu.etaxonomy.cdm.model.description.DescriptionBase, boolean)
|
617
|
*/
|
618
|
@Override
|
619
|
public void moveDescriptionElementsToDescription(Collection<DescriptionElementBase> descriptionElements,
|
620
|
DescriptionBase targetDescription, boolean isCopy) {
|
621
|
|
622
|
if (descriptionElements.isEmpty() ){
|
623
|
return ;
|
624
|
}
|
625
|
|
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;
|
631
|
}
|
632
|
for (DescriptionElementBase element : descriptionElements){
|
633
|
DescriptionBase description = element.getInDescription();
|
634
|
try {
|
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);
|
639
|
}
|
640
|
if (! isCopy){
|
641
|
description.removeElement(element);
|
642
|
}
|
643
|
|
644
|
}
|
645
|
}
|
646
|
|
647
|
@Override
|
648
|
public Pager<NamedArea> pageNamedAreasInUse(Integer pageSize,
|
649
|
Integer pageNumber, List<String> propertyPaths){
|
650
|
|
651
|
List<NamedArea> results = dao.listNamedAreasInUse(pageSize, pageNumber, propertyPaths);
|
652
|
return new DefaultPagerImpl<NamedArea>(pageNumber, results.size(), pageSize, results);
|
653
|
}
|
654
|
|
655
|
}
|