Add IEventBaseService to application controller #5403
[cdmlib.git] / cdmlib-services / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationDefaultConfiguration.java
index 820c8918f84a1ba084727696e2795dd40f8093cf..08804043cfc85526ae06bd04a929f9f829010e1d 100644 (file)
@@ -1,12 +1,12 @@
 // $Id$\r
 /**\r
-* Copyright (C) 2007 EDIT\r
-* European Distributed Institute of Taxonomy \r
-* http://www.e-taxonomy.eu\r
-* \r
-* The contents of this file are subject to the Mozilla Public License Version 1.1\r
-* See LICENSE.TXT at the top of this package for the full license terms.\r
-*/\r
+ * Copyright (C) 2007 EDIT\r
+ * European Distributed Institute of Taxonomy\r
+ * http://www.e-taxonomy.eu\r
+ *\r
+ * The contents of this file are subject to the Mozilla Public License Version 1.1\r
+ * See LICENSE.TXT at the top of this package for the full license terms.\r
+ */\r
 \r
 package eu.etaxonomy.cdm.api.application;\r
 \r
@@ -14,26 +14,59 @@ import javax.sql.DataSource;
 \r
 import org.apache.log4j.Logger;\r
 import org.hibernate.SessionFactory;\r
+import org.springframework.beans.BeansException;\r
 import org.springframework.beans.factory.annotation.Autowired;\r
-import org.springframework.orm.hibernate3.HibernateTransactionManager;\r
+import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.ApplicationContextAware;\r
+import org.springframework.orm.hibernate5.HibernateTransactionManager;\r
+import org.springframework.security.authentication.ProviderManager;\r
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;\r
+import org.springframework.security.core.Authentication;\r
+import org.springframework.security.core.context.SecurityContext;\r
+import org.springframework.security.core.context.SecurityContextHolder;\r
 import org.springframework.stereotype.Component;\r
 import org.springframework.transaction.PlatformTransactionManager;\r
+import org.springframework.transaction.TransactionDefinition;\r
+import org.springframework.transaction.TransactionStatus;\r
+import org.springframework.transaction.support.DefaultTransactionDefinition;\r
 \r
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;\r
 import eu.etaxonomy.cdm.api.service.IAgentService;\r
+import eu.etaxonomy.cdm.api.service.IAnnotationService;\r
+import eu.etaxonomy.cdm.api.service.IClassificationService;\r
+import eu.etaxonomy.cdm.api.service.ICollectionService;\r
 import eu.etaxonomy.cdm.api.service.ICommonService;\r
 import eu.etaxonomy.cdm.api.service.IDatabaseService;\r
 import eu.etaxonomy.cdm.api.service.IDescriptionService;\r
+import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService;\r
+import eu.etaxonomy.cdm.api.service.IEntityValidationService;\r
+import eu.etaxonomy.cdm.api.service.IEventBaseService;\r
+import eu.etaxonomy.cdm.api.service.IFeatureNodeService;\r
+import eu.etaxonomy.cdm.api.service.IFeatureTreeService;\r
+import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService;\r
+import eu.etaxonomy.cdm.api.service.IGroupService;\r
+import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;\r
 import eu.etaxonomy.cdm.api.service.ILocationService;\r
 import eu.etaxonomy.cdm.api.service.IMediaService;\r
+import eu.etaxonomy.cdm.api.service.IMetadataService;\r
 import eu.etaxonomy.cdm.api.service.INameService;\r
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;\r
+import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;\r
+import eu.etaxonomy.cdm.api.service.IProgressMonitorService;\r
 import eu.etaxonomy.cdm.api.service.IReferenceService;\r
 import eu.etaxonomy.cdm.api.service.IService;\r
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;\r
 import eu.etaxonomy.cdm.api.service.ITaxonService;\r
 import eu.etaxonomy.cdm.api.service.ITermService;\r
 import eu.etaxonomy.cdm.api.service.IUserService;\r
+import eu.etaxonomy.cdm.api.service.IVocabularyService;\r
+import eu.etaxonomy.cdm.api.service.IWorkingSetService;\r
+import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;\r
+import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;\r
+import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;\r
 \r
 /**\r
  * @author a.mueller\r
@@ -41,10 +74,15 @@ import eu.etaxonomy.cdm.model.common.CdmBase;
  * @version 1.0\r
  */\r
 @Component\r
-public class CdmApplicationDefaultConfiguration implements ICdmApplicationConfiguration {\r
-       @SuppressWarnings("unused")\r
+public class CdmApplicationDefaultConfiguration implements ICdmApplicationConfiguration, ApplicationContextAware {\r
        private static final Logger logger = Logger.getLogger(CdmApplicationDefaultConfiguration.class);\r
 \r
+       protected ApplicationContext applicationContext;\r
+\r
+       @Autowired\r
+    //@Qualifier("nameService")\r
+    private IAnnotationService annotationService;\r
+\r
        @Autowired\r
        //@Qualifier("nameService")\r
        private INameService nameService;\r
@@ -52,6 +90,9 @@ public class CdmApplicationDefaultConfiguration implements ICdmApplicationConfig
        //@Qualifier("taxonService")\r
        private ITaxonService taxonService;\r
        @Autowired\r
+       //@Qualifier("classificationService")\r
+       private IClassificationService classificationService;\r
+       @Autowired\r
        //@Qualifier("referenceService")\r
        private IReferenceService referenceService;\r
        @Autowired\r
@@ -63,7 +104,7 @@ public class CdmApplicationDefaultConfiguration implements ICdmApplicationConfig
        @Autowired\r
        //@Qualifier("termService")\r
        private ITermService termService;\r
-       @Autowired\r
+       //@Autowired\r
        private HibernateTransactionManager transactionManager;\r
        @Autowired\r
        //@Qualifier("descriptionService")\r
@@ -72,128 +113,355 @@ public class CdmApplicationDefaultConfiguration implements ICdmApplicationConfig
        //@Qualifier("occurrenceService")\r
        private IOccurrenceService occurrenceService;\r
        @Autowired\r
+       //@Qualifier("primerService")\r
+       private IPrimerService primerService;\r
+       @Autowired\r
+       //@Qualifier("amplificationService")\r
+       private IAmplificationService amplificationService;\r
+       @Autowired\r
+       //@Qualifier("sequenceService")\r
+       private ISequenceService sequenceService;\r
+       @Autowired\r
+       //@Qualifier("eventBaseService")\r
+       private IEventBaseService eventBaseService;\r
+       @Autowired\r
        //@Qualifier("mediaService")\r
        private IMediaService mediaService;\r
+    @Autowired\r
+    //@Qualifier("mediaService")\r
+    private IMetadataService metadataService;\r
        @Autowired\r
        //@Qualifier("commonService")\r
        private ICommonService commonService;\r
        @Autowired\r
        private ILocationService locationService;\r
+       //@Autowired\r
+       private SessionFactory sessionFactory;\r
+       //@Autowired\r
+       private DataSource dataSource;\r
+       @Autowired\r
+       private ProviderManager authenticationManager;\r
        @Autowired\r
        private IUserService userService;\r
-//     @Autowired\r
+       @Autowired\r
+       private IGrantedAuthorityService grantedAuthorityService;\r
+       @Autowired\r
+       private IGroupService groupService;\r
+       @Autowired\r
+       private ICollectionService collectionService;\r
+       @Autowired\r
+       private IFeatureTreeService featureTreeService;\r
+       @Autowired\r
+       private IFeatureNodeService featureNodeService;\r
+       @Autowired\r
+       private IVocabularyService vocabularyService;\r
+       @Autowired\r
+       private ITaxonNodeService taxonNodeService;\r
+       @Autowired\r
+       private IIdentificationKeyService identificationKeyService;\r
+       @Autowired\r
+       private IPolytomousKeyService polytomousKeyService;\r
+       @Autowired\r
+       private IPolytomousKeyNodeService polytomousKeyNodeService;\r
+       @Autowired\r
+       private IProgressMonitorService progressMonitorService;\r
+       @Autowired\r
+       private IEntityValidationService entityValidationService;\r
+       @Autowired\r
+       private IEntityConstraintViolationService entityConstraintViolationService;\r
+       @Autowired\r
+       private ICdmPermissionEvaluator permissionEvaluator;\r
+\r
+       //      @Autowired\r
        //@Qualifier("mainService")\r
        private IService<CdmBase> mainService;\r
+\r
        @Autowired\r
-       private SessionFactory sessionFactory;\r
-       @Autowired\r
-       private DataSource dataSource;\r
+       private IWorkingSetService workingSetService;\r
+\r
+\r
+       //********************** CONSTRUCTOR *********************************************************/\r
 \r
-       \r
        /**\r
-        * \r
+        * Constructor\r
         */\r
-       public CdmApplicationDefaultConfiguration() {\r
+       protected CdmApplicationDefaultConfiguration(){}\r
+\r
+\r
+       // ****************************** APPLICATION CONTEXT *************************************************/\r
+\r
+       @Override\r
+       public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{\r
+               this.applicationContext = applicationContext;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getAgentService()\r
-        */\r
-       public IAgentService getAgentService() {\r
+       // ****************************** GETTER *************************************************/\r
+\r
+       @Override\r
+       public final Object getBean(String name){\r
+           return this.applicationContext.getBean(name);\r
+       }\r
+\r
+       @Override\r
+       public IAnnotationService getAnnotationService(){\r
+           return this.annotationService;\r
+       }\r
+\r
+       @Override\r
+       public IAgentService getAgentService(){\r
                return this.agentService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getDatabaseService()\r
-        */\r
-       public IDatabaseService getDatabaseService() {\r
+       @Override\r
+       public IDatabaseService getDatabaseService(){\r
                return this.databaseService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getNameService()\r
-        */\r
-       public INameService getNameService() {\r
+\r
+       @Autowired\r
+       public void setDataSource(DataSource dataSource){\r
+               this.dataSource = dataSource;\r
+       }\r
+\r
+       @Override\r
+       public INameService getNameService(){\r
                return this.nameService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getReferenceService()\r
-        */\r
-       public IReferenceService getReferenceService() {\r
+       @Override\r
+       public IReferenceService getReferenceService(){\r
                return this.referenceService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getTaxonService()\r
-        */\r
-       public ITaxonService getTaxonService() {\r
+       @Autowired\r
+       public void setSessionFactory(SessionFactory sessionFactory){\r
+               this.sessionFactory = sessionFactory;\r
+       }\r
+\r
+       @Override\r
+       public ITaxonService getTaxonService(){\r
                return this.taxonService;\r
        }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getDescriptionService()\r
-        */\r
+\r
+       @Override\r
+       public IClassificationService getClassificationService(){\r
+               return this.classificationService;\r
+       }\r
+\r
+       @Override\r
+       public ITaxonNodeService getTaxonNodeService(){\r
+               return this.taxonNodeService;\r
+       }\r
+\r
+       @Override\r
        public IDescriptionService getDescriptionService(){\r
                return this.descriptionService;\r
        }\r
 \r
+       @Override\r
        public IOccurrenceService getOccurrenceService(){\r
                return this.occurrenceService;\r
        }\r
 \r
+       @Override\r
+       public IPrimerService getPrimerService(){\r
+               return this.primerService;\r
+       }\r
+\r
+       @Override\r
+       public IAmplificationService getAmplificationService(){\r
+               return this.amplificationService;\r
+       }\r
+\r
+       @Override\r
+       public ISequenceService getSequenceService(){\r
+               return this.sequenceService;\r
+       }\r
+\r
+       @Override\r
+       public IEventBaseService getEventBaseService() {\r
+           return this.eventBaseService;\r
+       }\r
+\r
+       @Override\r
        public IMediaService getMediaService(){\r
                return this.mediaService;\r
        }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getTermService()\r
-        */\r
-       public ITermService getTermService() {\r
+\r
+    /**\r
+     * {@inheritDoc}\r
+     */\r
+    @Override\r
+    public IMetadataService getMetadataService() {\r
+        return this.metadataService;\r
+    }\r
+\r
+       @Override\r
+       public ITermService getTermService(){\r
                return this.termService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getCommonService()\r
-        */\r
+       @Override\r
        public ICommonService getCommonService(){\r
                return this.commonService;\r
        }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getLocationService()\r
-        */\r
-       public ILocationService getLocationService() {\r
+\r
+       @Override\r
+       public ILocationService getLocationService(){\r
                return this.locationService;\r
        }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getUserService()\r
-        */\r
-       public IUserService getUserService() {\r
+\r
+       @Override\r
+       public IUserService getUserService(){\r
                return this.userService;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getCommonService()\r
-        */\r
+       @Override\r
+       public IGrantedAuthorityService getGrantedAuthorityService(){\r
+               return this.grantedAuthorityService;\r
+       }\r
+\r
+       @Override\r
        public IService<CdmBase> getMainService(){\r
                return this.mainService;\r
        }\r
-       \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#getTransactionManager()\r
-        */\r
-       public PlatformTransactionManager getTransactionManager() {\r
+\r
+       @Override\r
+       public PlatformTransactionManager getTransactionManager(){\r
                return this.transactionManager;\r
        }\r
 \r
-       /* (non-Javadoc)\r
-        * @see eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration#NewConversation()\r
-        */\r
-       public ConversationHolder NewConversation() {\r
+\r
+       @Autowired\r
+       public void setTransactionManager(PlatformTransactionManager transactionManager){\r
+               this.transactionManager = (HibernateTransactionManager) transactionManager;\r
+       }\r
+\r
+       @Override\r
+       public ProviderManager getAuthenticationManager(){\r
+               return this.authenticationManager;\r
+       }\r
+\r
+       @Override\r
+       public ConversationHolder NewConversation(){\r
                // TODO make this a prototype\r
                return new ConversationHolder(dataSource, sessionFactory, transactionManager);\r
-       }       \r
-       \r
+       }\r
+\r
+       @Override\r
+       public ICollectionService getCollectionService(){\r
+               return collectionService;\r
+       }\r
+\r
+       @Override\r
+       public IFeatureTreeService getFeatureTreeService(){\r
+               return featureTreeService;\r
+       }\r
+\r
+       @Override\r
+       public IFeatureNodeService getFeatureNodeService(){\r
+               return featureNodeService;\r
+       }\r
+\r
+       @Override\r
+       public IVocabularyService getVocabularyService(){\r
+               return vocabularyService;\r
+       }\r
+\r
+       @Override\r
+       public IIdentificationKeyService getIdentificationKeyService(){\r
+               return identificationKeyService;\r
+       }\r
+\r
+       @Override\r
+       public IPolytomousKeyService getPolytomousKeyService(){\r
+               return polytomousKeyService;\r
+       }\r
+\r
+\r
+       @Override\r
+       public IPolytomousKeyNodeService getPolytomousKeyNodeService(){\r
+               return polytomousKeyNodeService;\r
+       }\r
+\r
+    /**\r
+     * {@inheritDoc}\r
+     */\r
+    @Override\r
+    public IProgressMonitorService getProgressMonitorService() {\r
+        return progressMonitorService;\r
+    }\r
+\r
+       @Override\r
+       public IWorkingSetService getWorkingSetService(){\r
+               return workingSetService;\r
+       }\r
+\r
+       @Override\r
+       public IGroupService getGroupService(){\r
+               return groupService;\r
+       }\r
+\r
+\r
+       @Override\r
+       public IEntityValidationService getEntityValidationService(){\r
+               return entityValidationService;\r
+       }\r
+\r
+\r
+       @Override\r
+       public IEntityConstraintViolationService getEntityConstraintViolationService(){\r
+               return entityConstraintViolationService;\r
+       }\r
+\r
+       @Override\r
+       public ICdmPermissionEvaluator getPermissionEvaluator(){\r
+               return permissionEvaluator;\r
+       }\r
+\r
+       @Override\r
+       public TransactionStatus startTransaction(){\r
+               return startTransaction(false);\r
+       }\r
+\r
+       @Override\r
+       public TransactionStatus startTransaction(Boolean readOnly){\r
+\r
+               PlatformTransactionManager txManager = getTransactionManager();\r
+\r
+               DefaultTransactionDefinition defaultTxDef = new DefaultTransactionDefinition();\r
+               defaultTxDef.setReadOnly(readOnly);\r
+               TransactionDefinition txDef = defaultTxDef;\r
+\r
+               // Log some transaction-related debug information.\r
+               if (logger.isDebugEnabled()) {\r
+                       logger.debug("Transaction name = " + txDef.getName());\r
+                       logger.debug("Transaction facets:");\r
+                       logger.debug("Propagation behavior = " + txDef.getPropagationBehavior());\r
+                       logger.debug("Isolation level = " + txDef.getIsolationLevel());\r
+                       logger.debug("Timeout = " + txDef.getTimeout());\r
+                       logger.debug("Read Only = " + txDef.isReadOnly());\r
+                       // org.springframework.orm.hibernate5.HibernateTransactionManager\r
+                       // provides more transaction/session-related debug information.\r
+               }\r
+\r
+               TransactionStatus txStatus = txManager.getTransaction(txDef);\r
+               return txStatus;\r
+       }\r
+\r
+\r
+       @Override\r
+       public void commitTransaction(TransactionStatus txStatus){\r
+               PlatformTransactionManager txManager = getTransactionManager();\r
+               txManager.commit(txStatus);\r
+               return;\r
+       }\r
+\r
+       @Override\r
+       public void authenticate(String username, String password){\r
+               UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password);\r
+               Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser);\r
+               SecurityContext context = SecurityContextHolder.getContext();\r
+               context.setAuthentication(authentication);\r
+       }\r
 }\r