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