3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.api
.application
;
13 import javax
.sql
.DataSource
;
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
;
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
;
77 public class CdmApplicationDefaultConfiguration
implements ICdmApplicationConfiguration
, ApplicationContextAware
{
78 private static final Logger logger
= Logger
.getLogger(CdmApplicationDefaultConfiguration
.class);
80 protected ApplicationContext applicationContext
;
83 //@Qualifier("nameService")
84 private IAnnotationService annotationService
;
87 //@Qualifier("nameService")
88 private INameService nameService
;
90 //@Qualifier("taxonService")
91 private ITaxonService taxonService
;
93 //@Qualifier("classificationService")
94 private IClassificationService classificationService
;
96 //@Qualifier("referenceService")
97 private IReferenceService referenceService
;
99 //@Qualifier("agentService")
100 private IAgentService agentService
;
102 //@Qualifier("databaseService")
103 private IDatabaseService databaseService
;
105 //@Qualifier("termService")
106 private ITermService termService
;
108 private HibernateTransactionManager transactionManager
;
110 //@Qualifier("descriptionService")
111 private IDescriptionService descriptionService
;
113 //@Qualifier("occurrenceService")
114 private IOccurrenceService occurrenceService
;
116 //@Qualifier("primerService")
117 private IPrimerService primerService
;
119 //@Qualifier("amplificationService")
120 private IAmplificationService amplificationService
;
122 //@Qualifier("sequenceService")
123 private ISequenceService sequenceService
;
125 //@Qualifier("eventBaseService")
126 private IEventBaseService eventBaseService
;
128 //@Qualifier("mediaService")
129 private IMediaService mediaService
;
131 //@Qualifier("mediaService")
132 private IMetadataService metadataService
;
134 //@Qualifier("commonService")
135 private ICommonService commonService
;
137 private ILocationService locationService
;
139 private SessionFactory sessionFactory
;
141 private DataSource dataSource
;
143 private ProviderManager authenticationManager
;
145 private IUserService userService
;
147 private IGrantedAuthorityService grantedAuthorityService
;
149 private IGroupService groupService
;
151 private ICollectionService collectionService
;
153 private IFeatureTreeService featureTreeService
;
155 private IFeatureNodeService featureNodeService
;
157 private IVocabularyService vocabularyService
;
159 private ITaxonNodeService taxonNodeService
;
161 private IIdentificationKeyService identificationKeyService
;
163 private IPolytomousKeyService polytomousKeyService
;
165 private IPolytomousKeyNodeService polytomousKeyNodeService
;
167 private IProgressMonitorService progressMonitorService
;
169 private IEntityValidationService entityValidationService
;
171 private IEntityConstraintViolationService entityConstraintViolationService
;
173 private ICdmPermissionEvaluator permissionEvaluator
;
176 //@Qualifier("mainService")
177 private IService
<CdmBase
> mainService
;
180 private IWorkingSetService workingSetService
;
183 //********************** CONSTRUCTOR *********************************************************/
188 protected CdmApplicationDefaultConfiguration(){}
191 // ****************************** APPLICATION CONTEXT *************************************************/
194 public void setApplicationContext(ApplicationContext applicationContext
) throws BeansException
{
195 this.applicationContext
= applicationContext
;
198 // ****************************** GETTER *************************************************/
201 public final Object
getBean(String name
){
202 return this.applicationContext
.getBean(name
);
206 public IAnnotationService
getAnnotationService(){
207 return this.annotationService
;
211 public IAgentService
getAgentService(){
212 return this.agentService
;
216 public IDatabaseService
getDatabaseService(){
217 return this.databaseService
;
222 public void setDataSource(DataSource dataSource
){
223 this.dataSource
= dataSource
;
227 public INameService
getNameService(){
228 return this.nameService
;
232 public IReferenceService
getReferenceService(){
233 return this.referenceService
;
237 public void setSessionFactory(SessionFactory sessionFactory
){
238 this.sessionFactory
= sessionFactory
;
242 public ITaxonService
getTaxonService(){
243 return this.taxonService
;
247 public IClassificationService
getClassificationService(){
248 return this.classificationService
;
252 public ITaxonNodeService
getTaxonNodeService(){
253 return this.taxonNodeService
;
257 public IDescriptionService
getDescriptionService(){
258 return this.descriptionService
;
262 public IOccurrenceService
getOccurrenceService(){
263 return this.occurrenceService
;
267 public IPrimerService
getPrimerService(){
268 return this.primerService
;
272 public IAmplificationService
getAmplificationService(){
273 return this.amplificationService
;
277 public ISequenceService
getSequenceService(){
278 return this.sequenceService
;
282 public IEventBaseService
getEventBaseService() {
283 return this.eventBaseService
;
287 public IMediaService
getMediaService(){
288 return this.mediaService
;
295 public IMetadataService
getMetadataService() {
296 return this.metadataService
;
300 public ITermService
getTermService(){
301 return this.termService
;
305 public ICommonService
getCommonService(){
306 return this.commonService
;
310 public ILocationService
getLocationService(){
311 return this.locationService
;
315 public IUserService
getUserService(){
316 return this.userService
;
320 public IGrantedAuthorityService
getGrantedAuthorityService(){
321 return this.grantedAuthorityService
;
325 public IService
<CdmBase
> getMainService(){
326 return this.mainService
;
330 public PlatformTransactionManager
getTransactionManager(){
331 return this.transactionManager
;
336 public void setTransactionManager(PlatformTransactionManager transactionManager
){
337 this.transactionManager
= (HibernateTransactionManager
) transactionManager
;
341 public ProviderManager
getAuthenticationManager(){
342 return this.authenticationManager
;
346 public ConversationHolder
NewConversation(){
347 // TODO make this a prototype
348 return new ConversationHolder(dataSource
, sessionFactory
, transactionManager
);
352 public ICollectionService
getCollectionService(){
353 return collectionService
;
357 public IFeatureTreeService
getFeatureTreeService(){
358 return featureTreeService
;
362 public IFeatureNodeService
getFeatureNodeService(){
363 return featureNodeService
;
367 public IVocabularyService
getVocabularyService(){
368 return vocabularyService
;
372 public IIdentificationKeyService
getIdentificationKeyService(){
373 return identificationKeyService
;
377 public IPolytomousKeyService
getPolytomousKeyService(){
378 return polytomousKeyService
;
383 public IPolytomousKeyNodeService
getPolytomousKeyNodeService(){
384 return polytomousKeyNodeService
;
391 public IProgressMonitorService
getProgressMonitorService() {
392 return progressMonitorService
;
396 public IWorkingSetService
getWorkingSetService(){
397 return workingSetService
;
401 public IGroupService
getGroupService(){
407 public IEntityValidationService
getEntityValidationService(){
408 return entityValidationService
;
413 public IEntityConstraintViolationService
getEntityConstraintViolationService(){
414 return entityConstraintViolationService
;
418 public ICdmPermissionEvaluator
getPermissionEvaluator(){
419 return permissionEvaluator
;
423 public TransactionStatus
startTransaction(){
424 return startTransaction(false);
428 public TransactionStatus
startTransaction(Boolean readOnly
){
430 PlatformTransactionManager txManager
= getTransactionManager();
432 DefaultTransactionDefinition defaultTxDef
= new DefaultTransactionDefinition();
433 defaultTxDef
.setReadOnly(readOnly
);
434 TransactionDefinition txDef
= defaultTxDef
;
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.
448 TransactionStatus txStatus
= txManager
.getTransaction(txDef
);
454 public void commitTransaction(TransactionStatus txStatus
){
455 PlatformTransactionManager txManager
= getTransactionManager();
456 txManager
.commit(txStatus
);
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
);