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.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.hibernate.criterion.Criterion;
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.beans.factory.annotation.Qualifier;
|
23
|
import org.springframework.stereotype.Service;
|
24
|
import org.springframework.transaction.annotation.Propagation;
|
25
|
import org.springframework.transaction.annotation.Transactional;
|
26
|
|
27
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
28
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.impl.AbstractPagerImpl;
|
30
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
31
|
import eu.etaxonomy.cdm.common.IProgressMonitor;
|
32
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
33
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
34
|
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
|
35
|
import eu.etaxonomy.cdm.model.common.RelationshipBase;
|
36
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
37
|
import eu.etaxonomy.cdm.model.common.UuidAndTitleCache;
|
38
|
import eu.etaxonomy.cdm.model.common.RelationshipBase.Direction;
|
39
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
40
|
import eu.etaxonomy.cdm.model.media.Media;
|
41
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
42
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
43
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
44
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
45
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
46
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
47
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
48
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
49
|
import eu.etaxonomy.cdm.model.name.Rank;
|
50
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
51
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
52
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
53
|
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;
|
54
|
import eu.etaxonomy.cdm.persistence.dao.common.IReferencedEntityDao;
|
55
|
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
56
|
import eu.etaxonomy.cdm.persistence.dao.name.IHomotypicalGroupDao;
|
57
|
import eu.etaxonomy.cdm.persistence.dao.name.INomenclaturalStatusDao;
|
58
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
59
|
import eu.etaxonomy.cdm.persistence.dao.name.ITypeDesignationDao;
|
60
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
61
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
62
|
import eu.etaxonomy.cdm.strategy.TaggedText;
|
63
|
import eu.etaxonomy.cdm.strategy.TaggedTextGenerator;
|
64
|
import eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy;
|
65
|
|
66
|
|
67
|
@Service
|
68
|
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
|
69
|
public class NameServiceImpl extends IdentifiableServiceBase<TaxonNameBase,ITaxonNameDao> implements INameService {
|
70
|
static private final Logger logger = Logger.getLogger(NameServiceImpl.class);
|
71
|
|
72
|
@Autowired
|
73
|
protected ITermVocabularyDao vocabularyDao;
|
74
|
@Autowired
|
75
|
protected IOrderedTermVocabularyDao orderedVocabularyDao;
|
76
|
@Autowired
|
77
|
@Qualifier("refEntDao")
|
78
|
protected IReferencedEntityDao<ReferencedEntityBase> referencedEntityDao;
|
79
|
@Autowired
|
80
|
private INomenclaturalStatusDao nomStatusDao;
|
81
|
@Autowired
|
82
|
private ITypeDesignationDao typeDesignationDao;
|
83
|
@Autowired
|
84
|
private IHomotypicalGroupDao homotypicalGroupDao;
|
85
|
|
86
|
/**
|
87
|
* Constructor
|
88
|
*/
|
89
|
public NameServiceImpl(){
|
90
|
if (logger.isDebugEnabled()) { logger.debug("Load NameService Bean"); }
|
91
|
}
|
92
|
|
93
|
//********************* METHODS ****************************************************************//
|
94
|
|
95
|
public List getNamesByName(String name){
|
96
|
return super.findCdmObjectsByTitle(name);
|
97
|
}
|
98
|
|
99
|
public List<NonViralName> getNamesByNameCache(String nameCache){
|
100
|
List result = dao.findByName(nameCache, MatchMode.EXACT, null, null, null, null);
|
101
|
return result;
|
102
|
}
|
103
|
|
104
|
public List getNamesByName(String name, CdmBase sessionObject){
|
105
|
return super.findCdmObjectsByTitle(name, sessionObject);
|
106
|
}
|
107
|
|
108
|
public List findNamesByTitle(String title){
|
109
|
return super.findCdmObjectsByTitle(title);
|
110
|
}
|
111
|
|
112
|
public List findNamesByTitle(String title, CdmBase sessionObject){
|
113
|
return super.findCdmObjectsByTitle(title, sessionObject);
|
114
|
}
|
115
|
|
116
|
@Transactional(readOnly = false)
|
117
|
public Map<UUID, HomotypicalGroup> saveAllHomotypicalGroups(Collection<HomotypicalGroup> homotypicalGroups){
|
118
|
return homotypicalGroupDao.saveAll(homotypicalGroups);
|
119
|
}
|
120
|
|
121
|
@Transactional(readOnly = false)
|
122
|
public Map<UUID, TypeDesignationBase> saveTypeDesignationAll(Collection<TypeDesignationBase> typeDesignationCollection){
|
123
|
return typeDesignationDao.saveAll(typeDesignationCollection);
|
124
|
}
|
125
|
|
126
|
@Transactional(readOnly = false)
|
127
|
public Map<UUID, ReferencedEntityBase> saveReferencedEntitiesAll(Collection<ReferencedEntityBase> referencedEntityCollection){
|
128
|
return referencedEntityDao.saveAll(referencedEntityCollection);
|
129
|
}
|
130
|
|
131
|
public List<TaxonNameBase> getAllNames(int limit, int start){
|
132
|
return dao.list(limit, start);
|
133
|
}
|
134
|
|
135
|
public List<NomenclaturalStatus> getAllNomenclaturalStatus(int limit, int start){
|
136
|
return nomStatusDao.list(limit, start);
|
137
|
}
|
138
|
|
139
|
public List<TypeDesignationBase> getAllTypeDesignations(int limit, int start){
|
140
|
return typeDesignationDao.getAllTypeDesignations(limit, start);
|
141
|
}
|
142
|
/**
|
143
|
* FIXME Candidate for harmonization
|
144
|
* homotypicalGroupService.list
|
145
|
*/
|
146
|
public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start){
|
147
|
return homotypicalGroupDao.list(limit, start);
|
148
|
}
|
149
|
|
150
|
/**
|
151
|
* FIXME Candidate for harmonization
|
152
|
* remove
|
153
|
*/
|
154
|
@Deprecated
|
155
|
public List<RelationshipBase> getAllRelationships(int limit, int start){
|
156
|
return dao.getRelationships(limit, start);
|
157
|
}
|
158
|
|
159
|
/**
|
160
|
* FIXME Candidate for harmonization
|
161
|
* is this the same as termService.getVocabulary(VocabularyEnum.Rank)
|
162
|
* (non-Javadoc)
|
163
|
* @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
|
164
|
*/
|
165
|
public OrderedTermVocabulary<Rank> getRankVocabulary() {
|
166
|
String uuidString = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
|
167
|
UUID uuid = UUID.fromString(uuidString);
|
168
|
OrderedTermVocabulary<Rank> rankVocabulary =
|
169
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
170
|
return rankVocabulary;
|
171
|
}
|
172
|
|
173
|
/**
|
174
|
* FIXME Candidate for harmonization
|
175
|
* is this the same as termService.getVocabulary(VocabularyEnum.NameRelationshipType)
|
176
|
* (non-Javadoc)
|
177
|
* @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
|
178
|
*/
|
179
|
public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary() {
|
180
|
String uuidString = "6878cb82-c1a4-4613-b012-7e73b413c8cd";
|
181
|
UUID uuid = UUID.fromString(uuidString);
|
182
|
TermVocabulary<NameRelationshipType> nameRelTypeVocabulary =
|
183
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
184
|
return nameRelTypeVocabulary;
|
185
|
}
|
186
|
|
187
|
/**
|
188
|
* FIXME Candidate for harmonization
|
189
|
* is this the same as termService.getVocabulary(VocabularyEnum.StatusType)
|
190
|
* (non-Javadoc)
|
191
|
* @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
|
192
|
*/
|
193
|
public TermVocabulary<NomenclaturalStatusType> getStatusTypeVocabulary() {
|
194
|
String uuidString = "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
|
195
|
UUID uuid = UUID.fromString(uuidString);
|
196
|
TermVocabulary<NomenclaturalStatusType> nomStatusTypeVocabulary =
|
197
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
198
|
return nomStatusTypeVocabulary;
|
199
|
}
|
200
|
|
201
|
/**
|
202
|
* FIXME Candidate for harmonization
|
203
|
* is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
|
204
|
* (non-Javadoc)
|
205
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
206
|
*/
|
207
|
public TermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationStatusVocabulary() {
|
208
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
209
|
UUID uuid = UUID.fromString(uuidString);
|
210
|
TermVocabulary<SpecimenTypeDesignationStatus> typeDesigStatusVocabulary =
|
211
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
212
|
return typeDesigStatusVocabulary;
|
213
|
}
|
214
|
|
215
|
/**
|
216
|
* FIXME Candidate for harmonization
|
217
|
* is this the same as termService.getVocabulary(VocabularyEnum.SpecimenTypeDesignationStatus)
|
218
|
* and also seems to duplicate the above method, differing only in the DAO used and the return type
|
219
|
* (non-Javadoc)
|
220
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
221
|
*/
|
222
|
public OrderedTermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationVocabulary() {
|
223
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
224
|
UUID uuid = UUID.fromString(uuidString);
|
225
|
OrderedTermVocabulary<SpecimenTypeDesignationStatus> typeDesignationVocabulary =
|
226
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
227
|
return typeDesignationVocabulary;
|
228
|
}
|
229
|
|
230
|
|
231
|
@Autowired
|
232
|
protected void setDao(ITaxonNameDao dao) {
|
233
|
this.dao = dao;
|
234
|
}
|
235
|
|
236
|
public Pager<HybridRelationship> getHybridNames(NonViralName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
237
|
Integer numberOfResults = dao.countHybridNames(name, type);
|
238
|
|
239
|
List<HybridRelationship> results = new ArrayList<HybridRelationship>();
|
240
|
if(AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)) { // no point checking again
|
241
|
results = dao.getHybridNames(name, type, pageSize, pageNumber,orderHints,propertyPaths);
|
242
|
}
|
243
|
|
244
|
return new DefaultPagerImpl<HybridRelationship>(pageNumber, numberOfResults, pageSize, results);
|
245
|
}
|
246
|
|
247
|
/* (non-Javadoc)
|
248
|
* @see eu.etaxonomy.cdm.api.service.INameService#listNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
249
|
*/
|
250
|
@Override
|
251
|
public List<NameRelationship> listNameRelationships(TaxonNameBase name, Direction direction, NameRelationshipType type, Integer pageSize,
|
252
|
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
253
|
|
254
|
Integer numberOfResults = dao.countNameRelationships(name, NameRelationship.Direction.relatedFrom, type);
|
255
|
|
256
|
List<NameRelationship> results = new ArrayList<NameRelationship>();
|
257
|
if (AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)) { // no point checking again
|
258
|
results = dao.getNameRelationships(name, direction, type, pageSize, pageNumber, orderHints, propertyPaths);
|
259
|
}
|
260
|
return results;
|
261
|
}
|
262
|
|
263
|
/* (non-Javadoc)
|
264
|
* @see eu.etaxonomy.cdm.api.service.INameService#pageNameRelationships(eu.etaxonomy.cdm.model.name.TaxonNameBase, eu.etaxonomy.cdm.model.common.RelationshipBase.Direction, eu.etaxonomy.cdm.model.name.NameRelationshipType, java.lang.Integer, java.lang.Integer, java.util.List, java.util.List)
|
265
|
*/
|
266
|
@Override
|
267
|
public Pager<NameRelationship> pageNameRelationships(TaxonNameBase name, Direction direction, NameRelationshipType type, Integer pageSize,
|
268
|
Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
269
|
List<NameRelationship> results = listNameRelationships(name, direction, type, pageSize, pageNumber, orderHints, propertyPaths);
|
270
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
271
|
}
|
272
|
|
273
|
public List<NameRelationship> listFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
274
|
return listNameRelationships(name, Direction.relatedFrom, type, pageSize, pageNumber, orderHints, propertyPaths);
|
275
|
}
|
276
|
|
277
|
public Pager<NameRelationship> pageFromNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
278
|
List<NameRelationship> results = listNameRelationships(name, Direction.relatedFrom, type, pageSize, pageNumber, orderHints, propertyPaths);
|
279
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
280
|
}
|
281
|
|
282
|
public List<NameRelationship> listToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
283
|
return listNameRelationships(name, Direction.relatedTo, type, pageSize, pageNumber, orderHints, propertyPaths);
|
284
|
}
|
285
|
|
286
|
public Pager<NameRelationship> pageToNameRelationships(TaxonNameBase name, NameRelationshipType type, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints, List<String> propertyPaths) {
|
287
|
List<NameRelationship> results = listNameRelationships(name, Direction.relatedTo, type, pageSize, pageNumber, orderHints, propertyPaths);
|
288
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, results.size(), pageSize, results);
|
289
|
}
|
290
|
|
291
|
public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name, SpecimenTypeDesignationStatus status,
|
292
|
Integer pageSize, Integer pageNumber) {
|
293
|
return getTypeDesignations(name, status, pageSize, pageNumber, null);
|
294
|
}
|
295
|
|
296
|
public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name, SpecimenTypeDesignationStatus status,
|
297
|
Integer pageSize, Integer pageNumber, List<String> propertyPaths){
|
298
|
Integer numberOfResults = dao.countTypeDesignations(name, status);
|
299
|
|
300
|
List<TypeDesignationBase> results = new ArrayList<TypeDesignationBase>();
|
301
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
302
|
results = dao.getTypeDesignations(name, status, pageSize, pageNumber, propertyPaths);
|
303
|
}
|
304
|
|
305
|
return new DefaultPagerImpl<TypeDesignationBase>(pageNumber, numberOfResults, pageSize, results);
|
306
|
}
|
307
|
|
308
|
/**
|
309
|
* FIXME Candidate for harmonization
|
310
|
* rename search
|
311
|
*/
|
312
|
public Pager<TaxonNameBase> searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber, List<OrderHint> orderHints,
|
313
|
List<String> propertyPaths) {
|
314
|
Integer numberOfResults = dao.countNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank);
|
315
|
|
316
|
List<TaxonNameBase> results = new ArrayList<TaxonNameBase>();
|
317
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
318
|
results = dao.searchNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber, orderHints, propertyPaths);
|
319
|
}
|
320
|
|
321
|
return new DefaultPagerImpl<TaxonNameBase>(pageNumber, numberOfResults, pageSize, results);
|
322
|
}
|
323
|
|
324
|
/* (non-Javadoc)
|
325
|
* @see eu.etaxonomy.cdm.api.service.INameService#getUuidAndTitleCacheOfNames()
|
326
|
*/
|
327
|
public List<UuidAndTitleCache> getUuidAndTitleCacheOfNames() {
|
328
|
return dao.getUuidAndTitleCacheOfNames();
|
329
|
}
|
330
|
|
331
|
public Pager<TaxonNameBase> findByName(Class<? extends TaxonNameBase> clazz, String queryString, MatchMode matchmode, List<Criterion> criteria, Integer pageSize,Integer pageNumber, List<OrderHint> orderHints,List<String> propertyPaths) {
|
332
|
Integer numberOfResults = dao.countByName(clazz, queryString, matchmode, criteria);
|
333
|
|
334
|
List<TaxonNameBase> results = new ArrayList<TaxonNameBase>();
|
335
|
if(numberOfResults > 0) { // no point checking again //TODO use AbstractPagerImpl.hasResultsInRange(numberOfResults, pageNumber, pageSize)
|
336
|
results = dao.findByName(clazz, queryString, matchmode, criteria, pageSize, pageNumber, orderHints, propertyPaths);
|
337
|
}
|
338
|
|
339
|
return new DefaultPagerImpl<TaxonNameBase>(pageNumber, numberOfResults, pageSize, results);
|
340
|
}
|
341
|
|
342
|
public HomotypicalGroup findHomotypicalGroup(UUID uuid) {
|
343
|
return homotypicalGroupDao.findByUuid(uuid);
|
344
|
}
|
345
|
|
346
|
|
347
|
/* (non-Javadoc)
|
348
|
* @see eu.etaxonomy.cdm.api.service.IIdentifiableEntityService#updateTitleCache(java.lang.Integer, eu.etaxonomy.cdm.strategy.cache.common.IIdentifiableEntityCacheStrategy)
|
349
|
*/
|
350
|
@Override
|
351
|
public void updateTitleCache(Class<? extends TaxonNameBase> clazz, Integer stepSize, IIdentifiableEntityCacheStrategy<TaxonNameBase> cacheStrategy, IProgressMonitor monitor) {
|
352
|
if (clazz == null){
|
353
|
clazz = TaxonNameBase.class;
|
354
|
}
|
355
|
super.updateTitleCacheImpl(clazz, stepSize, cacheStrategy, monitor);
|
356
|
}
|
357
|
|
358
|
|
359
|
@Override
|
360
|
protected void setOtherCachesNull(TaxonNameBase name) {
|
361
|
if (name.isInstanceOf(NonViralName.class)){
|
362
|
NonViralName nvn = CdmBase.deproxy(name, NonViralName.class);
|
363
|
if (! nvn.isProtectedNameCache()){
|
364
|
nvn.setNameCache(null, false);
|
365
|
}
|
366
|
if (! nvn.isProtectedAuthorshipCache()){
|
367
|
nvn.setAuthorshipCache(null, false);
|
368
|
}
|
369
|
if (! nvn.isProtectedFullTitleCache()){
|
370
|
nvn.setFullTitleCache(null, false);
|
371
|
}
|
372
|
}
|
373
|
}
|
374
|
|
375
|
/* (non-Javadoc)
|
376
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTaggedName(eu.etaxonomy.cdm.model.name.TaxonNameBase)
|
377
|
*/
|
378
|
@Override
|
379
|
public List<TaggedText> getTaggedName(UUID uuid) {
|
380
|
TaxonNameBase taxonNameBase = dao.load(uuid);
|
381
|
return TaggedTextGenerator.getTaggedName(taxonNameBase);
|
382
|
}
|
383
|
|
384
|
|
385
|
}
|