1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.api.application;
|
11
|
|
12
|
import javax.sql.DataSource;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.hibernate.SessionFactory;
|
16
|
import org.springframework.beans.BeansException;
|
17
|
import org.springframework.beans.factory.annotation.Autowired;
|
18
|
import org.springframework.context.ApplicationContext;
|
19
|
import org.springframework.context.ApplicationContextAware;
|
20
|
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
21
|
import org.springframework.security.authentication.ProviderManager;
|
22
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
23
|
import org.springframework.security.core.Authentication;
|
24
|
import org.springframework.security.core.context.SecurityContext;
|
25
|
import org.springframework.security.core.context.SecurityContextHolder;
|
26
|
import org.springframework.stereotype.Component;
|
27
|
import org.springframework.transaction.PlatformTransactionManager;
|
28
|
import org.springframework.transaction.TransactionDefinition;
|
29
|
import org.springframework.transaction.TransactionStatus;
|
30
|
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
31
|
|
32
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
33
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
34
|
import eu.etaxonomy.cdm.api.service.IAnnotationService;
|
35
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
36
|
import eu.etaxonomy.cdm.api.service.ICollectionService;
|
37
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
38
|
import eu.etaxonomy.cdm.api.service.IDatabaseService;
|
39
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
40
|
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService;
|
41
|
import eu.etaxonomy.cdm.api.service.IEntityValidationService;
|
42
|
import eu.etaxonomy.cdm.api.service.IEventBaseService;
|
43
|
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
44
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
45
|
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService;
|
46
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
47
|
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;
|
48
|
import eu.etaxonomy.cdm.api.service.ILocationService;
|
49
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
50
|
import eu.etaxonomy.cdm.api.service.IMetadataService;
|
51
|
import eu.etaxonomy.cdm.api.service.INameService;
|
52
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
53
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
54
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
55
|
import eu.etaxonomy.cdm.api.service.IPreferenceService;
|
56
|
import eu.etaxonomy.cdm.api.service.IProgressMonitorService;
|
57
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
58
|
import eu.etaxonomy.cdm.api.service.IRegistrationService;
|
59
|
import eu.etaxonomy.cdm.api.service.IRightsService;
|
60
|
import eu.etaxonomy.cdm.api.service.IService;
|
61
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
62
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
63
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
64
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
65
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
66
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
67
|
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
|
68
|
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
|
69
|
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
70
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
71
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
|
72
|
|
73
|
/**
|
74
|
* This class actually is the central access point to all cdm api services and thus to all the
|
75
|
* entities stored in the cdm. From this point of view this class provides a "repository" view
|
76
|
* on the cdm by which you can access everything important for client development.
|
77
|
*
|
78
|
* @author a.mueller
|
79
|
* @created 21.05.2008
|
80
|
*/
|
81
|
@Component
|
82
|
public class CdmRepository implements ICdmRepository, ApplicationContextAware {
|
83
|
private static final Logger logger = Logger.getLogger(CdmRepository.class);
|
84
|
|
85
|
protected ApplicationContext applicationContext;
|
86
|
|
87
|
@Autowired
|
88
|
//@Qualifier("nameService")
|
89
|
private IAnnotationService annotationService;
|
90
|
|
91
|
@Autowired
|
92
|
//@Qualifier("nameService")
|
93
|
private INameService nameService;
|
94
|
@Autowired
|
95
|
//@Qualifier("taxonService")
|
96
|
private ITaxonService taxonService;
|
97
|
@Autowired
|
98
|
//@Qualifier("classificationService")
|
99
|
private IClassificationService classificationService;
|
100
|
@Autowired
|
101
|
//@Qualifier("referenceService")
|
102
|
private IReferenceService referenceService;
|
103
|
@Autowired
|
104
|
//@Qualifier("agentService")
|
105
|
private IAgentService agentService;
|
106
|
@Autowired
|
107
|
//@Qualifier("databaseService")
|
108
|
private IDatabaseService databaseService;
|
109
|
@Autowired
|
110
|
//@Qualifier("termService")
|
111
|
private ITermService termService;
|
112
|
//@Autowired
|
113
|
private HibernateTransactionManager transactionManager;
|
114
|
@Autowired
|
115
|
//@Qualifier("descriptionService")
|
116
|
private IDescriptionService descriptionService;
|
117
|
@Autowired
|
118
|
//@Qualifier("occurrenceService")
|
119
|
private IOccurrenceService occurrenceService;
|
120
|
@Autowired
|
121
|
//@Qualifier("primerService")
|
122
|
private IPrimerService primerService;
|
123
|
@Autowired
|
124
|
//@Qualifier("amplificationService")
|
125
|
private IAmplificationService amplificationService;
|
126
|
@Autowired
|
127
|
//@Qualifier("sequenceService")
|
128
|
private ISequenceService sequenceService;
|
129
|
@Autowired
|
130
|
//@Qualifier("eventBaseService")
|
131
|
private IEventBaseService eventBaseService;
|
132
|
@Autowired
|
133
|
//@Qualifier("mediaService")
|
134
|
private IMediaService mediaService;
|
135
|
@Autowired
|
136
|
//@Qualifier("mediaService")
|
137
|
private IMetadataService metadataService;
|
138
|
@Autowired
|
139
|
//@Qualifier("commonService")
|
140
|
private ICommonService commonService;
|
141
|
@Autowired
|
142
|
private ILocationService locationService;
|
143
|
//@Autowired
|
144
|
private SessionFactory sessionFactory;
|
145
|
//@Autowired
|
146
|
private DataSource dataSource;
|
147
|
@Autowired
|
148
|
private ProviderManager authenticationManager;
|
149
|
@Autowired
|
150
|
private IUserService userService;
|
151
|
@Autowired
|
152
|
private IGrantedAuthorityService grantedAuthorityService;
|
153
|
@Autowired
|
154
|
private IGroupService groupService;
|
155
|
@Autowired
|
156
|
private ICollectionService collectionService;
|
157
|
@Autowired
|
158
|
private IFeatureTreeService featureTreeService;
|
159
|
@Autowired
|
160
|
private IFeatureNodeService featureNodeService;
|
161
|
@Autowired
|
162
|
private IVocabularyService vocabularyService;
|
163
|
@Autowired
|
164
|
private ITaxonNodeService taxonNodeService;
|
165
|
@Autowired
|
166
|
private IIdentificationKeyService identificationKeyService;
|
167
|
@Autowired
|
168
|
private IPolytomousKeyService polytomousKeyService;
|
169
|
@Autowired
|
170
|
private IPolytomousKeyNodeService polytomousKeyNodeService;
|
171
|
@Autowired
|
172
|
private IProgressMonitorService progressMonitorService;
|
173
|
@Autowired
|
174
|
private IEntityValidationService entityValidationService;
|
175
|
@Autowired
|
176
|
private IPreferenceService preferenceService;
|
177
|
@Autowired
|
178
|
private IRightsService rightsService;
|
179
|
@Autowired
|
180
|
private IRegistrationService registrationService;
|
181
|
@Autowired
|
182
|
private IEntityConstraintViolationService entityConstraintViolationService;
|
183
|
@Autowired
|
184
|
private ICdmPermissionEvaluator permissionEvaluator;
|
185
|
|
186
|
// @Autowired
|
187
|
//@Qualifier("mainService")
|
188
|
private IService<CdmBase> mainService;
|
189
|
|
190
|
@Autowired
|
191
|
private IWorkingSetService workingSetService;
|
192
|
|
193
|
|
194
|
//********************** CONSTRUCTOR *********************************************************/
|
195
|
|
196
|
/**
|
197
|
* Constructor
|
198
|
*/
|
199
|
protected CdmRepository(){}
|
200
|
|
201
|
|
202
|
// ****************************** APPLICATION CONTEXT *************************************************/
|
203
|
|
204
|
@Override
|
205
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
|
206
|
this.applicationContext = applicationContext;
|
207
|
}
|
208
|
|
209
|
// ****************************** GETTER *************************************************/
|
210
|
|
211
|
@Override
|
212
|
public final Object getBean(String name){
|
213
|
return this.applicationContext.getBean(name);
|
214
|
}
|
215
|
|
216
|
@Override
|
217
|
public IAnnotationService getAnnotationService(){
|
218
|
return this.annotationService;
|
219
|
}
|
220
|
|
221
|
@Override
|
222
|
public IAgentService getAgentService(){
|
223
|
return this.agentService;
|
224
|
}
|
225
|
|
226
|
@Override
|
227
|
public IDatabaseService getDatabaseService(){
|
228
|
return this.databaseService;
|
229
|
}
|
230
|
|
231
|
|
232
|
@Autowired
|
233
|
public void setDataSource(DataSource dataSource){
|
234
|
this.dataSource = dataSource;
|
235
|
}
|
236
|
|
237
|
@Override
|
238
|
public INameService getNameService(){
|
239
|
return this.nameService;
|
240
|
}
|
241
|
|
242
|
@Override
|
243
|
public IReferenceService getReferenceService(){
|
244
|
return this.referenceService;
|
245
|
}
|
246
|
|
247
|
@Autowired
|
248
|
public void setSessionFactory(SessionFactory sessionFactory){
|
249
|
this.sessionFactory = sessionFactory;
|
250
|
}
|
251
|
|
252
|
@Override
|
253
|
public ITaxonService getTaxonService(){
|
254
|
return this.taxonService;
|
255
|
}
|
256
|
|
257
|
@Override
|
258
|
public IClassificationService getClassificationService(){
|
259
|
return this.classificationService;
|
260
|
}
|
261
|
|
262
|
@Override
|
263
|
public ITaxonNodeService getTaxonNodeService(){
|
264
|
return this.taxonNodeService;
|
265
|
}
|
266
|
|
267
|
@Override
|
268
|
public IDescriptionService getDescriptionService(){
|
269
|
return this.descriptionService;
|
270
|
}
|
271
|
|
272
|
@Override
|
273
|
public IOccurrenceService getOccurrenceService(){
|
274
|
return this.occurrenceService;
|
275
|
}
|
276
|
|
277
|
@Override
|
278
|
public IPrimerService getPrimerService(){
|
279
|
return this.primerService;
|
280
|
}
|
281
|
|
282
|
@Override
|
283
|
public IAmplificationService getAmplificationService(){
|
284
|
return this.amplificationService;
|
285
|
}
|
286
|
|
287
|
@Override
|
288
|
public ISequenceService getSequenceService(){
|
289
|
return this.sequenceService;
|
290
|
}
|
291
|
|
292
|
@Override
|
293
|
public IEventBaseService getEventBaseService() {
|
294
|
return this.eventBaseService;
|
295
|
}
|
296
|
|
297
|
@Override
|
298
|
public IMediaService getMediaService(){
|
299
|
return this.mediaService;
|
300
|
}
|
301
|
|
302
|
/**
|
303
|
* {@inheritDoc}
|
304
|
*/
|
305
|
@Override
|
306
|
public IMetadataService getMetadataService() {
|
307
|
return this.metadataService;
|
308
|
}
|
309
|
|
310
|
@Override
|
311
|
public ITermService getTermService(){
|
312
|
return this.termService;
|
313
|
}
|
314
|
|
315
|
@Override
|
316
|
public ICommonService getCommonService(){
|
317
|
return this.commonService;
|
318
|
}
|
319
|
|
320
|
@Override
|
321
|
public ILocationService getLocationService(){
|
322
|
return this.locationService;
|
323
|
}
|
324
|
|
325
|
@Override
|
326
|
public IUserService getUserService(){
|
327
|
return this.userService;
|
328
|
}
|
329
|
|
330
|
@Override
|
331
|
public IGrantedAuthorityService getGrantedAuthorityService(){
|
332
|
return this.grantedAuthorityService;
|
333
|
}
|
334
|
|
335
|
@Override
|
336
|
public IService<CdmBase> getMainService(){
|
337
|
return this.mainService;
|
338
|
}
|
339
|
|
340
|
@Override
|
341
|
public PlatformTransactionManager getTransactionManager(){
|
342
|
return this.transactionManager;
|
343
|
}
|
344
|
|
345
|
|
346
|
@Autowired
|
347
|
public void setTransactionManager(PlatformTransactionManager transactionManager){
|
348
|
this.transactionManager = (HibernateTransactionManager) transactionManager;
|
349
|
}
|
350
|
|
351
|
@Override
|
352
|
public ProviderManager getAuthenticationManager(){
|
353
|
return this.authenticationManager;
|
354
|
}
|
355
|
|
356
|
@Override
|
357
|
public ConversationHolder NewConversation(){
|
358
|
// TODO make this a prototype
|
359
|
return new ConversationHolder(dataSource, sessionFactory, transactionManager);
|
360
|
}
|
361
|
|
362
|
@Override
|
363
|
public ICollectionService getCollectionService(){
|
364
|
return collectionService;
|
365
|
}
|
366
|
|
367
|
@Override
|
368
|
public IFeatureTreeService getFeatureTreeService(){
|
369
|
return featureTreeService;
|
370
|
}
|
371
|
|
372
|
@Override
|
373
|
public IFeatureNodeService getFeatureNodeService(){
|
374
|
return featureNodeService;
|
375
|
}
|
376
|
|
377
|
@Override
|
378
|
public IPreferenceService getPreferenceService(){
|
379
|
return preferenceService;
|
380
|
}
|
381
|
|
382
|
@Override
|
383
|
public IVocabularyService getVocabularyService(){
|
384
|
return vocabularyService;
|
385
|
}
|
386
|
|
387
|
@Override
|
388
|
public IIdentificationKeyService getIdentificationKeyService(){
|
389
|
return identificationKeyService;
|
390
|
}
|
391
|
|
392
|
@Override
|
393
|
public IPolytomousKeyService getPolytomousKeyService(){
|
394
|
return polytomousKeyService;
|
395
|
}
|
396
|
|
397
|
|
398
|
@Override
|
399
|
public IPolytomousKeyNodeService getPolytomousKeyNodeService(){
|
400
|
return polytomousKeyNodeService;
|
401
|
}
|
402
|
|
403
|
/**
|
404
|
* {@inheritDoc}
|
405
|
*/
|
406
|
@Override
|
407
|
public IProgressMonitorService getProgressMonitorService() {
|
408
|
return progressMonitorService;
|
409
|
}
|
410
|
|
411
|
@Override
|
412
|
public IWorkingSetService getWorkingSetService(){
|
413
|
return workingSetService;
|
414
|
}
|
415
|
|
416
|
@Override
|
417
|
public IGroupService getGroupService(){
|
418
|
return groupService;
|
419
|
}
|
420
|
|
421
|
|
422
|
@Override
|
423
|
public IEntityValidationService getEntityValidationService(){
|
424
|
return entityValidationService;
|
425
|
}
|
426
|
|
427
|
|
428
|
@Override
|
429
|
public IEntityConstraintViolationService getEntityConstraintViolationService(){
|
430
|
return entityConstraintViolationService;
|
431
|
}
|
432
|
|
433
|
@Override
|
434
|
public ICdmPermissionEvaluator getPermissionEvaluator(){
|
435
|
return permissionEvaluator;
|
436
|
}
|
437
|
|
438
|
|
439
|
@Override
|
440
|
public TransactionStatus startTransaction(){
|
441
|
return startTransaction(false);
|
442
|
}
|
443
|
|
444
|
@Override
|
445
|
public TransactionStatus startTransaction(Boolean readOnly){
|
446
|
|
447
|
PlatformTransactionManager txManager = getTransactionManager();
|
448
|
|
449
|
DefaultTransactionDefinition defaultTxDef = new DefaultTransactionDefinition();
|
450
|
defaultTxDef.setReadOnly(readOnly);
|
451
|
TransactionDefinition txDef = defaultTxDef;
|
452
|
|
453
|
// Log some transaction-related debug information.
|
454
|
if (logger.isDebugEnabled()) {
|
455
|
logger.debug("Transaction name = " + txDef.getName());
|
456
|
logger.debug("Transaction facets:");
|
457
|
logger.debug("Propagation behavior = " + txDef.getPropagationBehavior());
|
458
|
logger.debug("Isolation level = " + txDef.getIsolationLevel());
|
459
|
logger.debug("Timeout = " + txDef.getTimeout());
|
460
|
logger.debug("Read Only = " + txDef.isReadOnly());
|
461
|
// org.springframework.orm.hibernate5.HibernateTransactionManager
|
462
|
// provides more transaction/session-related debug information.
|
463
|
}
|
464
|
|
465
|
TransactionStatus txStatus = txManager.getTransaction(txDef);
|
466
|
return txStatus;
|
467
|
}
|
468
|
|
469
|
|
470
|
@Override
|
471
|
public void commitTransaction(TransactionStatus txStatus){
|
472
|
PlatformTransactionManager txManager = getTransactionManager();
|
473
|
txManager.commit(txStatus);
|
474
|
return;
|
475
|
}
|
476
|
|
477
|
@Override
|
478
|
public void authenticate(String username, String password){
|
479
|
UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password);
|
480
|
Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser);
|
481
|
SecurityContext context = SecurityContextHolder.getContext();
|
482
|
context.setAuthentication(authentication);
|
483
|
}
|
484
|
|
485
|
|
486
|
@Override
|
487
|
public IRightsService getRightsService() {
|
488
|
return rightsService;
|
489
|
}
|
490
|
|
491
|
@Override
|
492
|
public IRegistrationService getRegistrationService() {
|
493
|
return registrationService;
|
494
|
}
|
495
|
}
|