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.Enumeration;
|
16
|
import java.util.List;
|
17
|
import java.util.Locale;
|
18
|
import java.util.Map;
|
19
|
import java.util.Set;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.beans.factory.annotation.Qualifier;
|
25
|
import org.springframework.stereotype.Service;
|
26
|
import org.springframework.transaction.annotation.Transactional;
|
27
|
|
28
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
29
|
import eu.etaxonomy.cdm.api.service.pager.impl.DefaultPagerImpl;
|
30
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
31
|
import eu.etaxonomy.cdm.model.common.Language;
|
32
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
33
|
import eu.etaxonomy.cdm.model.common.LanguageStringBase;
|
34
|
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
|
35
|
import eu.etaxonomy.cdm.model.common.Representation;
|
36
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
37
|
import eu.etaxonomy.cdm.model.common.VocabularyEnum;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
39
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
40
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
41
|
import eu.etaxonomy.cdm.model.location.TdwgArea;
|
42
|
import eu.etaxonomy.cdm.model.media.Media;
|
43
|
import eu.etaxonomy.cdm.model.name.NameRelationship;
|
44
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
45
|
import eu.etaxonomy.cdm.persistence.dao.common.ILanguageStringBaseDao;
|
46
|
import eu.etaxonomy.cdm.persistence.dao.common.ILanguageStringDao;
|
47
|
import eu.etaxonomy.cdm.persistence.dao.common.IRepresentationDao;
|
48
|
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
49
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
50
|
|
51
|
@Service
|
52
|
@Transactional(readOnly = true)
|
53
|
public class TermServiceImpl extends ServiceBase<DefinedTermBase,IDefinedTermDao> implements ITermService{
|
54
|
private static final Logger logger = Logger.getLogger(TermServiceImpl.class);
|
55
|
|
56
|
protected ITermVocabularyDao vocabularyDao;
|
57
|
@Autowired
|
58
|
@Qualifier("langStrBaseDao")
|
59
|
private ILanguageStringBaseDao languageStringBaseDao;
|
60
|
@Autowired
|
61
|
private IRepresentationDao representationDao;
|
62
|
@Autowired
|
63
|
private ILanguageStringDao languageStringDao;
|
64
|
|
65
|
@Autowired
|
66
|
protected void setVocabularyDao(ITermVocabularyDao vocabularyDao) {
|
67
|
this.vocabularyDao = vocabularyDao;
|
68
|
}
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see eu.etaxonomy.cdm.api.service.ITermService#getTermByUri(java.lang.String)
|
72
|
*/
|
73
|
public DefinedTermBase getTermByUri(String uri) {
|
74
|
//FIXME transformation from URI to UUID
|
75
|
return dao.findByUri(uri);
|
76
|
}
|
77
|
|
78
|
/* FIXME candidate for harmonization(non-Javadoc)
|
79
|
* @see eu.etaxonomy.cdm.api.service.ITermService#getTermByUuid(java.util.UUID)
|
80
|
*/
|
81
|
public DefinedTermBase getTermByUuid(UUID uuid) {
|
82
|
return dao.findByUuid(uuid);
|
83
|
}
|
84
|
|
85
|
public List<DefinedTermBase> getAllDefinedTerms(int limit, int start){
|
86
|
return dao.list(limit, start);
|
87
|
}
|
88
|
|
89
|
@Transactional(readOnly = false)
|
90
|
public UUID saveTerm(DefinedTermBase termBase) {
|
91
|
return super.saveCdmObject(termBase);
|
92
|
}
|
93
|
|
94
|
@Transactional(readOnly = false)
|
95
|
public Map<UUID, DefinedTermBase> saveTermsAll(Collection<? extends DefinedTermBase> termBaseCollection){
|
96
|
return saveCdmObjectAll(termBaseCollection);
|
97
|
}
|
98
|
|
99
|
/* (non-Javadoc)
|
100
|
* @see eu.etaxonomy.cdm.api.service.ITermService#getVocabulary(java.util.UUID)
|
101
|
*/
|
102
|
public TermVocabulary<? extends DefinedTermBase<?>> getVocabulary(UUID vocabularyUuid) {
|
103
|
TermVocabulary<? extends DefinedTermBase<?>> vocabulary = (TermVocabulary) vocabularyDao.findByUuid(vocabularyUuid);
|
104
|
return vocabulary;
|
105
|
}
|
106
|
|
107
|
public TermVocabulary loadVocabulary(UUID vocabularyUuid, List<String> propertyPaths) {
|
108
|
TermVocabulary<? extends DefinedTermBase<?>> vocabulary = (TermVocabulary) vocabularyDao.load(vocabularyUuid,
|
109
|
propertyPaths);
|
110
|
return vocabulary;
|
111
|
}
|
112
|
|
113
|
public TermVocabulary<? extends DefinedTermBase<?>> getVocabulary(VocabularyEnum vocabularyType){
|
114
|
TermVocabulary<? extends DefinedTermBase<?>> vocabulary = getVocabulary(vocabularyType.getUuid());
|
115
|
return vocabulary;
|
116
|
}
|
117
|
|
118
|
/* (non-Javadoc)
|
119
|
* @see eu.etaxonomy.cdm.api.service.ITermService#listVocabularies(java.lang.Class)
|
120
|
*/
|
121
|
public Set<TermVocabulary> listVocabularies(Class termClass) {
|
122
|
logger.error("Method not implemented yet");
|
123
|
return null;
|
124
|
}
|
125
|
|
126
|
public List<TermVocabulary<DefinedTermBase>> getAllTermVocabularies(int limit, int start) {
|
127
|
return vocabularyDao.list(limit, start);
|
128
|
}
|
129
|
|
130
|
public List<TermVocabulary<DefinedTermBase>> listTermVocabularies(Integer limit, Integer start, List<OrderHint> orderHints,
|
131
|
List<String> propertyPaths){
|
132
|
return vocabularyDao.list(limit, start, orderHints, propertyPaths);
|
133
|
}
|
134
|
|
135
|
public Pager<TermVocabulary<DefinedTermBase>> pageTermVocabularies(Integer pageSize, Integer pageNumber,
|
136
|
List<OrderHint> orderHints, List<String> propertyPaths) {
|
137
|
|
138
|
List<TermVocabulary<DefinedTermBase>> vocabs = vocabularyDao.list(pageSize, pageNumber * pageSize, orderHints,
|
139
|
propertyPaths);
|
140
|
Pager<TermVocabulary<DefinedTermBase>> pager = new DefaultPagerImpl<TermVocabulary<DefinedTermBase>>(
|
141
|
pageNumber, vocabs.size(), pageSize, vocabs);
|
142
|
return pager;
|
143
|
}
|
144
|
|
145
|
/* (non-Javadoc)
|
146
|
* @see eu.etaxonomy.cdm.api.service.ITermService#getLanguageVocabulary()
|
147
|
*/
|
148
|
public TermVocabulary<Language> getLanguageVocabulary() {
|
149
|
String uuidString = "45ac7043-7f5e-4f37-92f2-3874aaaef2de";
|
150
|
UUID uuid = UUID.fromString(uuidString);
|
151
|
TermVocabulary<Language> languageVocabulary =
|
152
|
(TermVocabulary)vocabularyDao.findByUuid(uuid);
|
153
|
return languageVocabulary;
|
154
|
}
|
155
|
|
156
|
public Map<UUID, TermVocabulary<DefinedTermBase>>
|
157
|
saveTermVocabulariesAll(Collection<TermVocabulary<DefinedTermBase>> termVocabularies) {
|
158
|
return vocabularyDao.saveAll(termVocabularies);
|
159
|
}
|
160
|
|
161
|
public UUID saveTermVocabulary(TermVocabulary termVocabulary) {
|
162
|
return vocabularyDao.save(termVocabulary);
|
163
|
}
|
164
|
|
165
|
// @Transactional(readOnly = false)
|
166
|
// public Map<UUID, Representation> saveRepresentationsAll(Collection<Representation> representations){
|
167
|
// return representationDao.saveAll(representations);
|
168
|
// }
|
169
|
|
170
|
@Transactional(readOnly = false)
|
171
|
public Map<UUID, LanguageStringBase> saveLanguageDataAll(Collection<LanguageStringBase> languageData) {
|
172
|
return languageStringBaseDao.saveAll(languageData);
|
173
|
}
|
174
|
|
175
|
@Transactional(readOnly = false)
|
176
|
public Map<UUID, Representation> saveRepresentationAll(Collection<Representation> representations) {
|
177
|
return representationDao.saveAll(representations);
|
178
|
}
|
179
|
|
180
|
public List<Representation> getAllRepresentations(int limit, int start){
|
181
|
return representationDao.list(limit, start);
|
182
|
}
|
183
|
|
184
|
public List<LanguageString> getAllLanguageStrings(int limit, int start) {
|
185
|
return languageStringDao.list(limit, start);
|
186
|
}
|
187
|
|
188
|
public Map<UUID, LanguageStringBase>
|
189
|
saveLanguageStringBasesAll(Collection<LanguageStringBase> languageStringBases) {
|
190
|
return languageStringBaseDao.saveAll(languageStringBases);
|
191
|
}
|
192
|
|
193
|
public Language getLanguageByIso(String iso639) {
|
194
|
return dao.getLanguageByIso(iso639);
|
195
|
}
|
196
|
|
197
|
public List<Language> getLanguagesByLocale(Enumeration<Locale> locales){
|
198
|
return dao.getLanguagesByLocale(locales);
|
199
|
}
|
200
|
|
201
|
@Transactional(readOnly = false)
|
202
|
public UUID saveLanguageData(
|
203
|
LanguageStringBase languageData) {
|
204
|
return languageStringBaseDao.save(languageData);
|
205
|
}
|
206
|
|
207
|
@Autowired
|
208
|
protected void setDao(IDefinedTermDao dao) {
|
209
|
this.dao = dao;
|
210
|
}
|
211
|
|
212
|
/* (non-Javadoc)
|
213
|
* @see eu.etaxonomy.cdm.api.service.ITermService#getAreaByTdwgAbbreviation(java.lang.String)
|
214
|
*/
|
215
|
public NamedArea getAreaByTdwgAbbreviation(String tdwgAbbreviation) {
|
216
|
//FIXME this is just a placeholder until it is decided where to implement this method
|
217
|
//(see also FIXMEs in TdwgArea)
|
218
|
return TdwgArea.getAreaByTdwgAbbreviation(tdwgAbbreviation);
|
219
|
}
|
220
|
|
221
|
public <T extends DefinedTermBase> Pager<T> getGeneralizationOf(T definedTerm, Integer pageSize, Integer pageNumber) {
|
222
|
Integer numberOfResults = dao.countGeneralizationOf(definedTerm);
|
223
|
|
224
|
List<T> results = new ArrayList<T>();
|
225
|
if(numberOfResults > 0) { // no point checking again
|
226
|
results = dao.getGeneralizationOf(definedTerm, pageSize, pageNumber);
|
227
|
}
|
228
|
|
229
|
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
|
230
|
}
|
231
|
|
232
|
public <T extends DefinedTermBase> Pager<T> getIncludes(Set<T> definedTerms, Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
233
|
Integer numberOfResults = dao.countIncludes(definedTerms);
|
234
|
|
235
|
List<T> results = new ArrayList<T>();
|
236
|
if(numberOfResults > 0) { // no point checking again
|
237
|
results = dao.getIncludes(definedTerms, pageSize, pageNumber,propertyPaths);
|
238
|
}
|
239
|
|
240
|
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
|
241
|
}
|
242
|
|
243
|
public Pager<Media> getMedia(DefinedTermBase definedTerm, Integer pageSize, Integer pageNumber) {
|
244
|
Integer numberOfResults = dao.countMedia(definedTerm);
|
245
|
|
246
|
List<Media> results = new ArrayList<Media>();
|
247
|
if(numberOfResults > 0) { // no point checking again
|
248
|
results = dao.getMedia(definedTerm, pageSize, pageNumber);
|
249
|
}
|
250
|
|
251
|
return new DefaultPagerImpl<Media>(pageNumber, numberOfResults, pageSize, results);
|
252
|
}
|
253
|
|
254
|
public <T extends DefinedTermBase> Pager<T> getPartOf(Set<T> definedTerms,Integer pageSize, Integer pageNumber, List<String> propertyPaths) {
|
255
|
Integer numberOfResults = dao.countPartOf(definedTerms);
|
256
|
|
257
|
List<T> results = new ArrayList<T>();
|
258
|
if(numberOfResults > 0) { // no point checking again
|
259
|
results = dao.getPartOf(definedTerms, pageSize, pageNumber, propertyPaths);
|
260
|
}
|
261
|
|
262
|
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
|
263
|
}
|
264
|
|
265
|
public Pager<NamedArea> list(NamedAreaLevel level, NamedAreaType type, Integer pageSize, Integer pageNumber) {
|
266
|
Integer numberOfResults = dao.count(level, type);
|
267
|
|
268
|
List<NamedArea> results = new ArrayList<NamedArea>();
|
269
|
if(numberOfResults > 0) { // no point checking again
|
270
|
results = dao.list(level, type, pageSize, pageNumber);
|
271
|
}
|
272
|
|
273
|
return new DefaultPagerImpl<NamedArea>(pageNumber, numberOfResults, pageSize, results);
|
274
|
}
|
275
|
|
276
|
public <T extends DefinedTermBase> Pager<T> findByRepresentationText(String label, Class<T> clazz, Integer pageSize, Integer pageNumber) {
|
277
|
Integer numberOfResults = dao.countDefinedTermByRepresentationText(label,clazz);
|
278
|
|
279
|
List<T> results = new ArrayList<T>();
|
280
|
if(numberOfResults > 0) { // no point checking again
|
281
|
results = dao.getDefinedTermByRepresentationText(label, clazz, pageSize, pageNumber);
|
282
|
}
|
283
|
|
284
|
return new DefaultPagerImpl<T>(pageNumber, numberOfResults, pageSize, results);
|
285
|
}
|
286
|
}
|