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.hibernate.HibernateProxyHelper;
|
32
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
33
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
34
|
import eu.etaxonomy.cdm.model.common.Language;
|
35
|
import eu.etaxonomy.cdm.model.common.Marker;
|
36
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
37
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
38
|
import eu.etaxonomy.cdm.model.description.DescriptionBase;
|
39
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
40
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
41
|
import eu.etaxonomy.cdm.model.description.Feature;
|
42
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
43
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
|
44
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
45
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
46
|
import eu.etaxonomy.cdm.model.description.TextData;
|
47
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
48
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
49
|
import eu.etaxonomy.cdm.model.media.Media;
|
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.dto.TermDto;
|
61
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
62
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
63
|
|
64
|
/**
|
65
|
* @author a.mueller
|
66
|
* @created 24.06.2008
|
67
|
* @version 1.0
|
68
|
*/
|
69
|
/**
|
70
|
* @author a.kohlbecker
|
71
|
* @date Dec 5, 2013
|
72
|
*
|
73
|
*/
|
74
|
@Service
|
75
|
@Transactional(readOnly = true)
|
76
|
public class DescriptionServiceImpl extends IdentifiableServiceBase<DescriptionBase,IDescriptionDao> implements IDescriptionService {
|
77
|
|
78
|
private static final Logger logger = Logger.getLogger(DescriptionServiceImpl.class);
|
79
|
|
80
|
protected IDescriptionElementDao descriptionElementDao;
|
81
|
protected IFeatureTreeDao featureTreeDao;
|
82
|
protected IFeatureNodeDao featureNodeDao;
|
83
|
protected IFeatureDao featureDao;
|
84
|
protected ITermVocabularyDao vocabularyDao;
|
85
|
protected IDefinedTermDao definedTermDao;
|
86
|
protected IStatisticalMeasurementValueDao statisticalMeasurementValueDao;
|
87
|
//TODO change to Interface
|
88
|
private NaturalLanguageGenerator naturalLanguageGenerator;
|
89
|
|
90
|
@Autowired
|
91
|
protected void setFeatureTreeDao(IFeatureTreeDao featureTreeDao) {
|
92
|
this.featureTreeDao = featureTreeDao;
|
93
|
}
|
94
|
|
95
|
@Autowired
|
96
|
protected void setFeatureNodeDao(IFeatureNodeDao featureNodeDao) {
|
97
|
this.featureNodeDao = featureNodeDao;
|
98
|
}
|
99
|
|
100
|
@Autowired
|
101
|
protected void setFeatureDao(IFeatureDao featureDao) {
|
102
|
this.featureDao = featureDao;
|
103
|
}
|
104
|
|
105
|
@Autowired
|
106
|
protected void setVocabularyDao(ITermVocabularyDao vocabularyDao) {
|
107
|
this.vocabularyDao = vocabularyDao;
|
108
|
}
|
109
|
|
110
|
@Autowired
|
111
|
protected void setDefinedTermDao(IDefinedTermDao definedTermDao) {
|
112
|
this.definedTermDao = definedTermDao;
|
113
|
}
|
114
|
|
115
|
@Autowired
|
116
|
protected void statisticalMeasurementValueDao(IStatisticalMeasurementValueDao statisticalMeasurementValueDao) {
|
117
|
this.statisticalMeasurementValueDao = statisticalMeasurementValueDao;
|
118
|
}
|
119
|
|
120
|
@Autowired
|
121
|
protected void setDescriptionElementDao(IDescriptionElementDao descriptionElementDao) {
|
122
|
this.descriptionElementDao = descriptionElementDao;
|
123
|
}
|
124
|
|
125
|
@Autowired
|
126
|
protected void setNaturalLanguageGenerator(NaturalLanguageGenerator naturalLanguageGenerator) {
|
127
|
this.naturalLanguageGenerator = naturalLanguageGenerator;
|
128
|
}
|
129
|
|
130
|
/**
|
131
|
*
|
132
|
*/
|
133
|
public DescriptionServiceImpl() {
|
134
|
logger.debug("Load DescriptionService Bean");
|
135
|
}
|
136
|
|
137
|
|
138
|
|
139
|
/* (non-Javadoc)
|
140
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
141
|
*/
|
142
|
@Override
|
143
|
@Transactional(readOnly = false)
|
144
|
public void updateTitleCache(Class<? extends DescriptionBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<DescriptionBase> cacheStrategy, IProgressMonitor monitor) {
|
145
|
if (clazz == null){
|
146
|
clazz = DescriptionBase.class;
|
147
|
}
|
148
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
149
|
}
|
150
|
|
151
|
|
152
|
@Override
|
153
|
public TermVocabulary<Feature> getDefaultFeatureVocabulary(){
|
154
|
String uuidFeature = "b187d555-f06f-4d65-9e53-da7c93f8eaa8";
|
155
|
UUID featureUuid = UUID.fromString(uuidFeature);
|
156
|
return vocabularyDao.findByUuid(featureUuid);
|
157
|
}
|
158
|
|
159
|
@Override
|
160
|
@Autowired
|
161
|
protected void setDao(IDescriptionDao dao) {
|
162
|
this.dao = dao;
|
163
|
}
|
164
|
|
165
|
@Override
|
166
|
public int count(Class<? extends DescriptionBase> type, Boolean hasImages, Boolean hasText,Set<Feature> feature) {
|
167
|
return dao.countDescriptions(type, hasImages, hasText, feature);
|
168
|
}
|
169
|
|
170
|
@Override
|
171
|
public Pager<DescriptionElementBase> pageDescriptionElements(DescriptionBase description, Class<? extends DescriptionBase> descriptionType,
|
172
|
Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
173
|
|
174
|
List<DescriptionElementBase> results = listDescriptionElements(description, descriptionType, features, type, pageSize, pageNumber, propertyPaths);
|
175
|
return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, results.size(), pageSize, results);
|
176
|
}
|
177
|
|
178
|
/* (non-Javadoc)
|
179
|
* @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)
|
180
|
*/
|
181
|
@Override
|
182
|
@Deprecated
|
183
|
public Pager<DescriptionElementBase> getDescriptionElements(DescriptionBase description,
|
184
|
Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
185
|
return pageDescriptionElements(description, null, features, type, pageSize, pageNumber, propertyPaths);
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public List<DescriptionElementBase> listDescriptionElements(DescriptionBase description, Class<? extends DescriptionBase> descriptionType,
|
190
|
Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
191
|
|
192
|
Integer numberOfResults = dao.countDescriptionElements(description, descriptionType, features, type);
|
193
|
List<DescriptionElementBase> results = new ArrayList<DescriptionElementBase>();
|
194
|
if(AbstractPagerImpl.hasResultsInRange(numberOfResults.longValue(), pageNumber, pageSize)) {
|
195
|
results = dao.getDescriptionElements(description, descriptionType, features, type, pageSize, pageNumber, propertyPaths);
|
196
|
}
|
197
|
return results;
|
198
|
}
|
199
|
|
200
|
/* (non-Javadoc)
|
201
|
* @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)
|
202
|
*/
|
203
|
@Override
|
204
|
@Deprecated
|
205
|
public List<DescriptionElementBase> listDescriptionElements(DescriptionBase description,
|
206
|
Set<Feature> features, Class<? extends DescriptionElementBase> type, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
207
|
|
208
|
return listDescriptionElements(description, null, features, type, pageSize, pageNumber, propertyPaths);
|
209
|
}
|
210
|
|
211
|
@Override
|
212
|
public Pager<Annotation> getDescriptionElementAnnotations(DescriptionElementBase annotatedObj, MarkerType status, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths){
|
213
|
Integer numberOfResults = descriptionElementDao.countAnnotations(annotatedObj, status);
|
214
|
|
215
|
List<Annotation> results = new ArrayList<Annotation>();
|
216
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
217
|
results = descriptionElementDao.getAnnotations(annotatedObj, status, pageSize, pageNumber, orderHints, propertyPaths);
|
218
|
}
|
219
|
|
220
|
return new DefaultPagerImpl<Annotation>(pageNumber, numberOfResults, pageSize, results);
|
221
|
}
|
222
|
|
223
|
|
224
|
|
225
|
@Override
|
226
|
public Pager<Media> getMedia(DescriptionElementBase descriptionElement, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
227
|
Integer numberOfResults = descriptionElementDao.countMedia(descriptionElement);
|
228
|
|
229
|
List<Media> results = new ArrayList<Media>();
|
230
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
231
|
results = descriptionElementDao.getMedia(descriptionElement, pageSize, pageNumber, propertyPaths);
|
232
|
}
|
233
|
|
234
|
return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);
|
235
|
}
|
236
|
|
237
|
@Override
|
238
|
public Pager<TaxonDescription> pageTaxonDescriptions(Taxon taxon, Set<DefinedTerm> scopes, Set<NamedArea> geographicalScope, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
239
|
Set<MarkerType> markerTypes = null;
|
240
|
return pageTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
|
241
|
}
|
242
|
|
243
|
@Override
|
244
|
public List<TaxonDescription> listTaxonDescriptions(Taxon taxon, Set<DefinedTerm> scopes, Set<NamedArea> geographicalScope, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
245
|
Set<MarkerType> markerTypes = null;
|
246
|
return listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
|
247
|
}
|
248
|
|
249
|
|
250
|
/* (non-Javadoc)
|
251
|
* @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
|
*/
|
253
|
@Override
|
254
|
public Pager<TaxonDescription> pageTaxonDescriptions(Taxon taxon, Set<DefinedTerm> scopes, Set<NamedArea> geographicalScope, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
255
|
Integer numberOfResults = dao.countTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes);
|
256
|
|
257
|
List<TaxonDescription> results = new ArrayList<TaxonDescription>();
|
258
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
259
|
results = dao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
|
260
|
}
|
261
|
|
262
|
return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
|
263
|
}
|
264
|
|
265
|
@Override
|
266
|
public List<TaxonDescription> listTaxonDescriptions(Taxon taxon, Set<DefinedTerm> scopes, Set<NamedArea> geographicalScope, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
267
|
List<TaxonDescription> results = dao.listTaxonDescriptions(taxon, scopes, geographicalScope, markerTypes, pageSize, pageNumber, propertyPaths);
|
268
|
return results;
|
269
|
}
|
270
|
|
271
|
|
272
|
/* (non-Javadoc)
|
273
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#listTaxonDescriptionMedia(UUID, boolean, Set, Integer, Integer, List)
|
274
|
*/
|
275
|
@Override
|
276
|
public List<Media> listTaxonDescriptionMedia(UUID taxonUuid, boolean limitToGalleries, Set<MarkerType> markerTypes, Integer pageSize, Integer pageNumber, List<String> propertyPaths){
|
277
|
return this.dao.listTaxonDescriptionMedia(taxonUuid, limitToGalleries, markerTypes, pageSize, pageNumber, propertyPaths);
|
278
|
}
|
279
|
|
280
|
/*
|
281
|
* @see IDescriptionService#countTaxonDescriptionMedia(UUID, boolean, Set)
|
282
|
*/
|
283
|
@Override
|
284
|
public int countTaxonDescriptionMedia(UUID taxonUuid, boolean limitToGalleries, Set<MarkerType> markerTypes){
|
285
|
return this.dao.countTaxonDescriptionMedia(taxonUuid, limitToGalleries, markerTypes);
|
286
|
}
|
287
|
|
288
|
|
289
|
/* (non-Javadoc)
|
290
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#getOrderedDistributions(java.util.Set, boolean, boolean, java.util.Set, java.util.List)
|
291
|
*/
|
292
|
@Override
|
293
|
@Deprecated
|
294
|
public DistributionTree getOrderedDistributions(
|
295
|
Set<TaxonDescription> taxonDescriptions,
|
296
|
boolean subAreaPreference,
|
297
|
boolean statusOrderPreference,
|
298
|
Set<MarkerType> hideMarkedAreas,
|
299
|
Set<NamedAreaLevel> omitLevels, List<String> propertyPaths){
|
300
|
|
301
|
List<Distribution> distList = new ArrayList<Distribution>();
|
302
|
|
303
|
List<UUID> uuids = new ArrayList<UUID>();
|
304
|
for (TaxonDescription taxonDescription : taxonDescriptions) {
|
305
|
if (! taxonDescription.isImageGallery()){ //image galleries should not have descriptions, but better filter fully on DTYPE of description element
|
306
|
uuids.add(taxonDescription.getUuid());
|
307
|
}
|
308
|
}
|
309
|
|
310
|
List<DescriptionBase> desclist = dao.list(uuids, null, null, null, propertyPaths);
|
311
|
for (DescriptionBase desc : desclist) {
|
312
|
if (desc.isInstanceOf(TaxonDescription.class)){
|
313
|
Set<DescriptionElementBase> elements = desc.getElements();
|
314
|
for (DescriptionElementBase element : elements) {
|
315
|
if (element.isInstanceOf(Distribution.class)) {
|
316
|
Distribution distribution = (Distribution) element;
|
317
|
if(distribution.getArea() != null){
|
318
|
distList.add(distribution);
|
319
|
}
|
320
|
}
|
321
|
}
|
322
|
}
|
323
|
}
|
324
|
|
325
|
//old
|
326
|
// for (TaxonDescription taxonDescription : taxonDescriptions) {
|
327
|
// if (logger.isDebugEnabled()){ logger.debug("load taxon description " + taxonDescription.getUuid());}
|
328
|
// //TODO why not loading all description via .list ? This may improve performance
|
329
|
// taxonDescription = (TaxonDescription) dao.load(taxonDescription.getUuid(), propertyPaths);
|
330
|
// Set<DescriptionElementBase> elements = taxonDescription.getElements();
|
331
|
// for (DescriptionElementBase element : elements) {
|
332
|
// if (element.isInstanceOf(Distribution.class)) {
|
333
|
// Distribution distribution = (Distribution) element;
|
334
|
// if(distribution.getArea() != null){
|
335
|
// distList.add(distribution);
|
336
|
// }
|
337
|
// }
|
338
|
// }
|
339
|
// }
|
340
|
|
341
|
if (logger.isDebugEnabled()){logger.debug("filter tree for " + distList.size() + " distributions ...");}
|
342
|
|
343
|
// filter distributions
|
344
|
Collection<Distribution> filteredDistributions = DescriptionUtility.filterDistributions(distList, subAreaPreference, statusOrderPreference, hideMarkedAreas);
|
345
|
distList.clear();
|
346
|
distList.addAll(filteredDistributions);
|
347
|
|
348
|
return DescriptionUtility.orderDistributions(omitLevels, distList);
|
349
|
}
|
350
|
|
351
|
|
352
|
@Override
|
353
|
public Pager<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase name, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
354
|
Integer numberOfResults = dao.countTaxonNameDescriptions(name);
|
355
|
|
356
|
List<TaxonNameDescription> results = new ArrayList<TaxonNameDescription>();
|
357
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
358
|
results = dao.getTaxonNameDescriptions(name, pageSize, pageNumber,propertyPaths);
|
359
|
}
|
360
|
|
361
|
return new DefaultPagerImpl<TaxonNameDescription>(pageNumber, numberOfResults, pageSize, results);
|
362
|
}
|
363
|
|
364
|
|
365
|
@Override
|
366
|
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) {
|
367
|
Integer numberOfResults = dao.countDescriptions(type, hasImages, hasText, feature);
|
368
|
|
369
|
List<DescriptionBase> results = new ArrayList<DescriptionBase>();
|
370
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
371
|
results = dao.listDescriptions(type, hasImages, hasText, feature, pageSize, pageNumber,orderHints,propertyPaths);
|
372
|
}
|
373
|
|
374
|
return new DefaultPagerImpl<DescriptionBase>(pageNumber, numberOfResults, pageSize, results);
|
375
|
}
|
376
|
|
377
|
/**
|
378
|
* FIXME Candidate for harmonization
|
379
|
* Rename: searchByDistribution
|
380
|
*/
|
381
|
@Override
|
382
|
public Pager<TaxonDescription> searchDescriptionByDistribution(Set<NamedArea> namedAreas, PresenceAbsenceTerm presence, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
383
|
Integer numberOfResults = dao.countDescriptionByDistribution(namedAreas, presence);
|
384
|
|
385
|
List<TaxonDescription> results = new ArrayList<TaxonDescription>();
|
386
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
387
|
results = dao.searchDescriptionByDistribution(namedAreas, presence, pageSize, pageNumber,orderHints,propertyPaths);
|
388
|
}
|
389
|
|
390
|
return new DefaultPagerImpl<TaxonDescription>(pageNumber, numberOfResults, pageSize, results);
|
391
|
}
|
392
|
|
393
|
/**
|
394
|
* FIXME Candidate for harmonization
|
395
|
* move: descriptionElementService.search
|
396
|
*/
|
397
|
@Override
|
398
|
public Pager<DescriptionElementBase> searchElements(Class<? extends DescriptionElementBase> clazz, String queryString, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
399
|
Integer numberOfResults = descriptionElementDao.count(clazz, queryString);
|
400
|
|
401
|
List<DescriptionElementBase> results = new ArrayList<DescriptionElementBase>();
|
402
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
403
|
results = descriptionElementDao.search(clazz, queryString, pageSize, pageNumber, orderHints, propertyPaths);
|
404
|
}
|
405
|
|
406
|
return new DefaultPagerImpl<DescriptionElementBase>(pageNumber, numberOfResults, pageSize, results);
|
407
|
}
|
408
|
|
409
|
/**
|
410
|
* FIXME Candidate for harmonization
|
411
|
* descriptionElementService.find
|
412
|
*/
|
413
|
@Override
|
414
|
public DescriptionElementBase getDescriptionElementByUuid(UUID uuid) {
|
415
|
return descriptionElementDao.findByUuid(uuid);
|
416
|
}
|
417
|
|
418
|
/**
|
419
|
* FIXME Candidate for harmonization
|
420
|
* descriptionElementService.load
|
421
|
*/
|
422
|
@Override
|
423
|
public DescriptionElementBase loadDescriptionElement(UUID uuid, List<String> propertyPaths) {
|
424
|
return descriptionElementDao.load(uuid, propertyPaths);
|
425
|
}
|
426
|
|
427
|
/**
|
428
|
* FIXME Candidate for harmonization
|
429
|
* descriptionElementService.save
|
430
|
*/
|
431
|
@Override
|
432
|
@Transactional(readOnly = false)
|
433
|
public UUID saveDescriptionElement(DescriptionElementBase descriptionElement) {
|
434
|
return descriptionElementDao.save(descriptionElement);
|
435
|
}
|
436
|
|
437
|
/**
|
438
|
* FIXME Candidate for harmonization
|
439
|
* descriptionElementService.save
|
440
|
*/
|
441
|
@Override
|
442
|
@Transactional(readOnly = false)
|
443
|
public Map<UUID, DescriptionElementBase> saveDescriptionElement(Collection<DescriptionElementBase> descriptionElements) {
|
444
|
return descriptionElementDao.saveAll(descriptionElements);
|
445
|
}
|
446
|
|
447
|
/**
|
448
|
* FIXME Candidate for harmonization
|
449
|
* descriptionElementService.delete
|
450
|
*/
|
451
|
@Override
|
452
|
public UUID deleteDescriptionElement(DescriptionElementBase descriptionElement) {
|
453
|
return descriptionElementDao.delete(descriptionElement);
|
454
|
}
|
455
|
|
456
|
@Override
|
457
|
public UUID deleteDescription(DescriptionBase description) {
|
458
|
if (description instanceof TaxonDescription){
|
459
|
TaxonDescription taxDescription = HibernateProxyHelper.deproxy(description, TaxonDescription.class);
|
460
|
Taxon tax = taxDescription.getTaxon();
|
461
|
tax.removeDescription(taxDescription, true);
|
462
|
}
|
463
|
|
464
|
return dao.delete(description);
|
465
|
}
|
466
|
@Override
|
467
|
public TermVocabulary<Feature> getFeatureVocabulary(UUID uuid) {
|
468
|
return vocabularyDao.findByUuid(uuid);
|
469
|
}
|
470
|
|
471
|
@Override
|
472
|
@Deprecated
|
473
|
public <T extends DescriptionElementBase> List<T> getDescriptionElementsForTaxon(
|
474
|
Taxon taxon, Set<Feature> features,
|
475
|
Class<T> type, Integer pageSize,
|
476
|
Integer pageNumber, List<String> propertyPaths) {
|
477
|
return listDescriptionElementsForTaxon(taxon, features, type, pageSize, pageNumber, propertyPaths);
|
478
|
}
|
479
|
|
480
|
@Override
|
481
|
public <T extends DescriptionElementBase> List<T> listDescriptionElementsForTaxon(
|
482
|
Taxon taxon, Set<Feature> features,
|
483
|
Class<T> type, Integer pageSize,
|
484
|
Integer pageNumber, List<String> propertyPaths) {
|
485
|
return dao.getDescriptionElementForTaxon(taxon.getUuid(), features, type, pageSize, pageNumber, propertyPaths);
|
486
|
}
|
487
|
|
488
|
@Override
|
489
|
public <T extends DescriptionElementBase> Pager<T> pageDescriptionElementsForTaxon(
|
490
|
Taxon taxon, Set<Feature> features,
|
491
|
Class<T> type, Integer pageSize,
|
492
|
Integer pageNumber, List<String> propertyPaths) {
|
493
|
if (logger.isDebugEnabled()){logger.debug(" get count ...");}
|
494
|
Long count = dao.countDescriptionElementForTaxon(taxon.getUuid(), features, type);
|
495
|
List<T> descriptionElements;
|
496
|
if(AbstractPagerImpl.hasResultsInRange(count, pageNumber, pageSize)){ // no point checking again
|
497
|
if (logger.isDebugEnabled()){logger.debug(" get list ...");}
|
498
|
descriptionElements = listDescriptionElementsForTaxon(taxon, features, type, pageSize, pageNumber, propertyPaths);
|
499
|
} else {
|
500
|
descriptionElements = new ArrayList<T>(0);
|
501
|
}
|
502
|
if (logger.isDebugEnabled()){logger.debug(" service - DONE ...");}
|
503
|
return new DefaultPagerImpl<T>(pageNumber, count.intValue(), pageSize, descriptionElements);
|
504
|
}
|
505
|
|
506
|
|
507
|
/* (non-Javadoc)
|
508
|
* @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)
|
509
|
*/
|
510
|
@Override
|
511
|
public String generateNaturalLanguageDescription(FeatureTree featureTree,
|
512
|
TaxonDescription description, List<Language> preferredLanguages, String separator) {
|
513
|
|
514
|
Language lang = preferredLanguages.size() > 0 ? preferredLanguages.get(0) : Language.DEFAULT();
|
515
|
|
516
|
description = (TaxonDescription)load(description.getUuid());
|
517
|
featureTree = featureTreeDao.load(featureTree.getUuid());
|
518
|
|
519
|
StringBuilder naturalLanguageDescription = new StringBuilder();
|
520
|
|
521
|
MarkerType useMarkerType = (MarkerType) definedTermDao.load(UUID.fromString("2e6e42d9-e92a-41f4-899b-03c0ac64f039"));
|
522
|
boolean isUseDescription = false;
|
523
|
if(!description.getMarkers().isEmpty()) {
|
524
|
for (Marker marker: description.getMarkers()) {
|
525
|
MarkerType markerType = marker.getMarkerType();
|
526
|
if (markerType.equals(useMarkerType)) {
|
527
|
isUseDescription = true;
|
528
|
}
|
529
|
|
530
|
}
|
531
|
}
|
532
|
|
533
|
if(description.hasStructuredData() && !isUseDescription){
|
534
|
|
535
|
|
536
|
String lastCategory = null;
|
537
|
String categorySeparator = ". ";
|
538
|
|
539
|
List<TextData> textDataList;
|
540
|
TextData naturalLanguageDescriptionText = null;
|
541
|
|
542
|
boolean useMicroFormatQuantitativeDescriptionBuilder = false;
|
543
|
|
544
|
if(useMicroFormatQuantitativeDescriptionBuilder){
|
545
|
|
546
|
MicroFormatQuantitativeDescriptionBuilder micro = new MicroFormatQuantitativeDescriptionBuilder();
|
547
|
naturalLanguageGenerator.setQuantitativeDescriptionBuilder(micro);
|
548
|
naturalLanguageDescriptionText = naturalLanguageGenerator.generateSingleTextData(featureTree, (description), lang);
|
549
|
|
550
|
} else {
|
551
|
|
552
|
naturalLanguageDescriptionText = naturalLanguageGenerator.generateSingleTextData(
|
553
|
featureTree,
|
554
|
(description),
|
555
|
lang);
|
556
|
}
|
557
|
|
558
|
return naturalLanguageDescriptionText.getText(lang);
|
559
|
|
560
|
//
|
561
|
// boolean doItBetter = false;
|
562
|
//
|
563
|
// for (TextData textData : textDataList.toArray(new TextData[textDataList.size()])){
|
564
|
// if(textData.getMultilanguageText().size() > 0){
|
565
|
//
|
566
|
// if (!textData.getFeature().equals(Feature.UNKNOWN())) {
|
567
|
// String featureLabel = textData.getFeature().getLabel(lang);
|
568
|
//
|
569
|
// if(doItBetter){
|
570
|
// /*
|
571
|
// * WARNING
|
572
|
// * The code lines below are desinged to handle
|
573
|
// * a special case where as the feature label contains
|
574
|
// * hierarchical information on the features. This code
|
575
|
// * exist only as a base for discussion, and is not
|
576
|
// * intendet to be used in production.
|
577
|
// */
|
578
|
// featureLabel = StringUtils.remove(featureLabel, '>');
|
579
|
//
|
580
|
// String[] labelTokens = StringUtils.split(featureLabel, '<');
|
581
|
// if(labelTokens[0].equals(lastCategory) && labelTokens.length > 1){
|
582
|
// if(naturalLanguageDescription.length() > 0){
|
583
|
// naturalLanguageDescription.append(separator);
|
584
|
// }
|
585
|
// naturalLanguageDescription.append(labelTokens[1]);
|
586
|
// } else {
|
587
|
// if(naturalLanguageDescription.length() > 0){
|
588
|
// naturalLanguageDescription.append(categorySeparator);
|
589
|
// }
|
590
|
// naturalLanguageDescription.append(StringUtils.join(labelTokens));
|
591
|
// }
|
592
|
// lastCategory = labelTokens[0];
|
593
|
// // end of demo code
|
594
|
// } else {
|
595
|
// if(naturalLanguageDescription.length() > 0){
|
596
|
// naturalLanguageDescription.append(separator);
|
597
|
// }
|
598
|
// naturalLanguageDescription.append(textData.getFeature().getLabel(lang));
|
599
|
// }
|
600
|
// } else {
|
601
|
// if(naturalLanguageDescription.length() > 0){
|
602
|
// naturalLanguageDescription.append(separator);
|
603
|
// }
|
604
|
// }
|
605
|
// String text = textData.getMultilanguageText().values().iterator().next().getText();
|
606
|
// naturalLanguageDescription.append(text);
|
607
|
//
|
608
|
// }
|
609
|
// }
|
610
|
|
611
|
}
|
612
|
else if (isUseDescription) {
|
613
|
//AT: Left Blank in case we need to generate a Natural language text string.
|
614
|
}
|
615
|
return naturalLanguageDescription.toString();
|
616
|
}
|
617
|
|
618
|
/* (non-Javadoc)
|
619
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#hasStructuredData(eu.etaxonomy.cdm.model.description.DescriptionBase)
|
620
|
*/
|
621
|
@Override
|
622
|
public boolean hasStructuredData(DescriptionBase<?> description) {
|
623
|
return load(description.getUuid()).hasStructuredData();
|
624
|
}
|
625
|
|
626
|
|
627
|
/* (non-Javadoc)
|
628
|
* @see eu.etaxonomy.cdm.api.service.IDescriptionService#moveDescriptionElementsToDescription(java.util.Collection, eu.etaxonomy.cdm.model.description.DescriptionBase, boolean)
|
629
|
*/
|
630
|
@Override
|
631
|
public void moveDescriptionElementsToDescription(Collection<DescriptionElementBase> descriptionElements,
|
632
|
DescriptionBase targetDescription, boolean isCopy) {
|
633
|
|
634
|
if (descriptionElements.isEmpty() ){
|
635
|
return ;
|
636
|
}
|
637
|
|
638
|
if (! isCopy && descriptionElements == descriptionElements.iterator().next().getInDescription().getElements()){
|
639
|
//if the descriptionElements collection is the elements set of a description, put it in a separate set before to avoid concurrent modification exceptions
|
640
|
descriptionElements = new HashSet<DescriptionElementBase>(descriptionElements);
|
641
|
// descriptionElementsTmp.addAll(descriptionElements);
|
642
|
// descriptionElements = descriptionElementsTmp;
|
643
|
}
|
644
|
for (DescriptionElementBase element : descriptionElements){
|
645
|
DescriptionBase description = element.getInDescription();
|
646
|
try {
|
647
|
DescriptionElementBase newElement = (DescriptionElementBase)element.clone();
|
648
|
targetDescription.addElement(newElement);
|
649
|
} catch (CloneNotSupportedException e) {
|
650
|
new RuntimeException ("Clone not yet implemented for class " + element.getClass().getName(), e);
|
651
|
}
|
652
|
if (! isCopy){
|
653
|
description.removeElement(element);
|
654
|
}
|
655
|
|
656
|
}
|
657
|
}
|
658
|
|
659
|
@Override
|
660
|
public Pager<TermDto> pageNamedAreasInUse(boolean includeAllParents, Integer pageSize,
|
661
|
Integer pageNumber){
|
662
|
|
663
|
List<TermDto> results = dao.listNamedAreasInUse(includeAllParents, pageSize, pageNumber);
|
664
|
return new DefaultPagerImpl<TermDto>(pageNumber, results.size(), pageSize, results);
|
665
|
}
|
666
|
|
667
|
}
|