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.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.beans.factory.annotation.Qualifier;
|
22
|
import org.springframework.stereotype.Service;
|
23
|
import org.springframework.transaction.annotation.Transactional;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.service.config.IIdentifiableEntityServiceConfigurator;
|
26
|
import eu.etaxonomy.cdm.api.service.config.INameServiceConfigurator;
|
27
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
28
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
29
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
30
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
31
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
32
|
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
|
33
|
import eu.etaxonomy.cdm.model.common.RelationshipTermBase;
|
34
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
35
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
36
|
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
|
37
|
import eu.etaxonomy.cdm.model.name.HybridRelationship;
|
38
|
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
|
39
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
40
|
import eu.etaxonomy.cdm.model.name.NameRelationshipType;
|
41
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
|
42
|
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
|
43
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
44
|
import eu.etaxonomy.cdm.model.name.Rank;
|
45
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
46
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
47
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
|
48
|
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
|
49
|
import eu.etaxonomy.cdm.persistence.dao.common.IOrderedTermVocabularyDao;
|
50
|
import eu.etaxonomy.cdm.persistence.dao.common.IReferencedEntityDao;
|
51
|
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
52
|
import eu.etaxonomy.cdm.persistence.dao.name.IHomotypicalGroupDao;
|
53
|
import eu.etaxonomy.cdm.persistence.dao.name.INomenclaturalStatusDao;
|
54
|
import eu.etaxonomy.cdm.persistence.dao.name.ITaxonNameDao;
|
55
|
import eu.etaxonomy.cdm.persistence.dao.name.ITypeDesignationDao;
|
56
|
|
57
|
|
58
|
@Service
|
59
|
@Transactional(readOnly = true)
|
60
|
public class NameServiceImpl extends IdentifiableServiceBase<TaxonNameBase,ITaxonNameDao> implements INameService {
|
61
|
static private final Logger logger = Logger.getLogger(NameServiceImpl.class);
|
62
|
|
63
|
@Autowired
|
64
|
protected ITermVocabularyDao vocabularyDao;
|
65
|
@Autowired
|
66
|
protected IOrderedTermVocabularyDao orderedVocabularyDao;
|
67
|
@Autowired
|
68
|
@Qualifier("refEntDao")
|
69
|
protected IReferencedEntityDao<ReferencedEntityBase> referencedEntityDao;
|
70
|
@Autowired
|
71
|
private INomenclaturalStatusDao nomStatusDao;
|
72
|
@Autowired
|
73
|
private ITypeDesignationDao typeDesignationDao;
|
74
|
@Autowired
|
75
|
private IHomotypicalGroupDao homotypicalGroupDao;
|
76
|
|
77
|
/**
|
78
|
* Constructor
|
79
|
*/
|
80
|
public NameServiceImpl(){
|
81
|
if (logger.isDebugEnabled()) { logger.debug("Load NameService Bean"); }
|
82
|
}
|
83
|
|
84
|
//********************* METHODS ****************************************************************//
|
85
|
|
86
|
public List getNamesByName(String name){
|
87
|
return super.findCdmObjectsByTitle(name);
|
88
|
}
|
89
|
|
90
|
public List getNamesByName(String name, CdmBase sessionObject){
|
91
|
return super.findCdmObjectsByTitle(name, sessionObject);
|
92
|
}
|
93
|
|
94
|
public List findNamesByTitle(String title){
|
95
|
return super.findCdmObjectsByTitle(title);
|
96
|
}
|
97
|
|
98
|
public List findNamesByTitle(String title, CdmBase sessionObject){
|
99
|
return super.findCdmObjectsByTitle(title, sessionObject);
|
100
|
}
|
101
|
|
102
|
public List<TaxonNameBase> findByTitle(IIdentifiableEntityServiceConfigurator config) {
|
103
|
return super.findByTitle(config);
|
104
|
}
|
105
|
|
106
|
public TaxonNameBase<?,?> getTaxonNameByUuid(UUID uuid) {
|
107
|
return super.getCdmObjectByUuid(uuid);
|
108
|
}
|
109
|
|
110
|
@Transactional(readOnly = false)
|
111
|
public UUID saveTaxonName(TaxonNameBase taxonName) {
|
112
|
return super.saveCdmObject(taxonName);
|
113
|
}
|
114
|
|
115
|
@Transactional(readOnly = false)
|
116
|
public Map<UUID, TaxonNameBase> saveTaxonNameAll(Collection<? extends TaxonNameBase> taxonNameCollection){
|
117
|
return saveCdmObjectAll(taxonNameCollection);
|
118
|
}
|
119
|
|
120
|
@Transactional(readOnly = false)
|
121
|
public Map<UUID, HomotypicalGroup> saveAllHomotypicalGroups(Collection<HomotypicalGroup> homotypicalGroups){
|
122
|
return homotypicalGroupDao.saveAll(homotypicalGroups);
|
123
|
}
|
124
|
|
125
|
@Transactional(readOnly = false)
|
126
|
public Map<UUID, TypeDesignationBase> saveTypeDesignationAll(Collection<TypeDesignationBase> typeDesignationCollection){
|
127
|
return typeDesignationDao.saveAll(typeDesignationCollection);
|
128
|
}
|
129
|
|
130
|
@Transactional(readOnly = false)
|
131
|
public Map<UUID, ReferencedEntityBase> saveReferencedEntitiesAll(Collection<ReferencedEntityBase> referencedEntityCollection){
|
132
|
return referencedEntityDao.saveAll(referencedEntityCollection);
|
133
|
}
|
134
|
|
135
|
@Transactional(readOnly = false)
|
136
|
public UUID removeTaxonName(TaxonNameBase taxonName) {
|
137
|
return super.removeCdmObject(taxonName);
|
138
|
}
|
139
|
|
140
|
public List<TaxonNameBase> getAllNames(int limit, int start){
|
141
|
return dao.list(limit, start);
|
142
|
}
|
143
|
|
144
|
public List<NomenclaturalStatus> getAllNomenclaturalStatus(int limit, int start){
|
145
|
return nomStatusDao.list(limit, start);
|
146
|
}
|
147
|
|
148
|
public List<TypeDesignationBase> getAllTypeDesignations(int limit, int start){
|
149
|
return typeDesignationDao.getAllTypeDesignations(limit, start);
|
150
|
}
|
151
|
|
152
|
public List<HomotypicalGroup> getAllHomotypicalGroups(int limit, int start){
|
153
|
return homotypicalGroupDao.list(limit, start);
|
154
|
}
|
155
|
|
156
|
/* (non-Javadoc)
|
157
|
* @see eu.etaxonomy.cdm.api.service.INameService#getRankVocabulary()
|
158
|
*/
|
159
|
public OrderedTermVocabulary<Rank> getRankVocabulary() {
|
160
|
String uuidString = "ef0d1ce1-26e3-4e83-b47b-ca74eed40b1b";
|
161
|
UUID uuid = UUID.fromString(uuidString);
|
162
|
OrderedTermVocabulary<Rank> rankVocabulary =
|
163
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
164
|
return rankVocabulary;
|
165
|
}
|
166
|
|
167
|
/* (non-Javadoc)
|
168
|
* @see eu.etaxonomy.cdm.api.service.INameService#getNameRelationshipTypeVocabulary()
|
169
|
*/
|
170
|
public TermVocabulary<NameRelationshipType> getNameRelationshipTypeVocabulary() {
|
171
|
String uuidString = "6878cb82-c1a4-4613-b012-7e73b413c8cd";
|
172
|
UUID uuid = UUID.fromString(uuidString);
|
173
|
TermVocabulary<NameRelationshipType> nameRelTypeVocabulary =
|
174
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
175
|
return nameRelTypeVocabulary;
|
176
|
}
|
177
|
|
178
|
/* (non-Javadoc)
|
179
|
* @see eu.etaxonomy.cdm.api.service.INameService#getStatusTypeVocabulary()
|
180
|
*/
|
181
|
public TermVocabulary<NomenclaturalStatusType> getStatusTypeVocabulary() {
|
182
|
String uuidString = "bb28cdca-2f8a-4f11-9c21-517e9ae87f1f";
|
183
|
UUID uuid = UUID.fromString(uuidString);
|
184
|
TermVocabulary<NomenclaturalStatusType> nomStatusTypeVocabulary =
|
185
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
186
|
return nomStatusTypeVocabulary;
|
187
|
}
|
188
|
|
189
|
/* (non-Javadoc)
|
190
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
191
|
*/
|
192
|
public TermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationStatusVocabulary() {
|
193
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
194
|
UUID uuid = UUID.fromString(uuidString);
|
195
|
TermVocabulary<SpecimenTypeDesignationStatus> typeDesigStatusVocabulary =
|
196
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
197
|
return typeDesigStatusVocabulary;
|
198
|
}
|
199
|
|
200
|
/* (non-Javadoc)
|
201
|
* @see eu.etaxonomy.cdm.api.service.INameService#getTypeDesignationStatusVocabulary()
|
202
|
*/
|
203
|
public OrderedTermVocabulary<SpecimenTypeDesignationStatus> getSpecimenTypeDesignationVocabulary() {
|
204
|
String uuidString = "ab177bd7-d3c8-4e58-a388-226fff6ba3c2";
|
205
|
UUID uuid = UUID.fromString(uuidString);
|
206
|
OrderedTermVocabulary<SpecimenTypeDesignationStatus> typeDesignationVocabulary =
|
207
|
(OrderedTermVocabulary)orderedVocabularyDao.findByUuid(uuid);
|
208
|
return typeDesignationVocabulary;
|
209
|
}
|
210
|
|
211
|
public void generateTitleCache() {
|
212
|
logger.warn("Not yet implemented");
|
213
|
// TODO Auto-generated method stub
|
214
|
}
|
215
|
|
216
|
@Autowired
|
217
|
protected void setDao(ITaxonNameDao dao) {
|
218
|
this.dao = dao;
|
219
|
}
|
220
|
|
221
|
public Pager<HybridRelationship> getHybridNames(BotanicalName name, HybridRelationshipType type, Integer pageSize, Integer pageNumber) {
|
222
|
Integer numberOfResults = dao.countHybridNames(name, type);
|
223
|
|
224
|
List<HybridRelationship> results = new ArrayList<HybridRelationship>();
|
225
|
if(numberOfResults > 0) { // no point checking again
|
226
|
results = dao.getHybridNames(name, type, pageSize, pageNumber);
|
227
|
}
|
228
|
|
229
|
return new DefaultPagerImpl<HybridRelationship>(pageNumber, numberOfResults, pageSize, results);
|
230
|
}
|
231
|
|
232
|
public Pager<NameRelationship> getRelatedNames(TaxonNameBase name,NameRelationshipType type, Integer pageSize, Integer pageNumber) {
|
233
|
Integer numberOfResults = dao.countRelatedNames(name, type);
|
234
|
|
235
|
List<NameRelationship> results = new ArrayList<NameRelationship>();
|
236
|
if(numberOfResults > 0) { // no point checking again
|
237
|
results = dao.getRelatedNames(name, type, pageSize, pageNumber);
|
238
|
}
|
239
|
|
240
|
return new DefaultPagerImpl<NameRelationship>(pageNumber, numberOfResults, pageSize, results);
|
241
|
}
|
242
|
|
243
|
public Pager<TypeDesignationBase> getTypeDesignations(TaxonNameBase name, SpecimenTypeDesignationStatus status, Integer pageSize, Integer pageNumber) {
|
244
|
Integer numberOfResults = dao.countTypeDesignations(name, status);
|
245
|
|
246
|
List<TypeDesignationBase> results = new ArrayList<TypeDesignationBase>();
|
247
|
if(numberOfResults > 0) { // no point checking again
|
248
|
results = dao.getTypeDesignations(name, status, pageSize, pageNumber);
|
249
|
}
|
250
|
|
251
|
return new DefaultPagerImpl<TypeDesignationBase>(pageNumber, numberOfResults, pageSize, results);
|
252
|
}
|
253
|
|
254
|
public Pager<TaxonNameBase> searchNames(String uninomial,String infraGenericEpithet, String specificEpithet, String infraspecificEpithet, Rank rank, Integer pageSize, Integer pageNumber) {
|
255
|
Integer numberOfResults = dao.countNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank);
|
256
|
|
257
|
List<TaxonNameBase> results = new ArrayList<TaxonNameBase>();
|
258
|
if(numberOfResults > 0) { // no point checking again
|
259
|
results = dao.searchNames(uninomial, infraGenericEpithet, specificEpithet, infraspecificEpithet, rank, pageSize, pageNumber);
|
260
|
}
|
261
|
|
262
|
return new DefaultPagerImpl<TaxonNameBase>(pageNumber, numberOfResults, pageSize, results);
|
263
|
}
|
264
|
|
265
|
}
|