remove 2016 logger aspects + verify audit score
[vid.git] / epsdk-app-onap / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
index 2d222f0..39fb99a 100644 (file)
  */
 package org.onap.portalapp.conf;
 
+import static org.apache.commons.lang3.StringUtils.isNotEmpty;
+
 import java.util.ArrayList;
 import java.util.List;
-
 import javax.sql.DataSource;
-
+import liquibase.integration.spring.SpringLiquibase;
 import org.onap.portalapp.login.LoginStrategyImpl;
-import org.onap.portalapp.scheduler.RegistryAdapter;
 import org.onap.portalsdk.core.auth.LoginStrategy;
 import org.onap.portalsdk.core.conf.AppConfig;
 import org.onap.portalsdk.core.conf.Configurable;
@@ -52,25 +52,22 @@ import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
 import org.onap.portalsdk.core.service.DataAccessService;
 import org.onap.portalsdk.core.util.CacheManager;
 import org.onap.portalsdk.core.util.SystemProperties;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.DependsOn;
 import org.springframework.context.annotation.Import;
 import org.springframework.context.annotation.Profile;
 import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.annotation.Order;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
-import org.springframework.web.servlet.ViewResolver;
+import org.springframework.scheduling.quartz.SpringBeanJobFactory;
+import org.springframework.web.multipart.commons.CommonsMultipartResolver;
 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.core.io.Resource;
-import org.springframework.jdbc.datasource.init.DataSourceInitializer;
-import org.springframework.jdbc.datasource.init.DatabasePopulator;
-import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
 
 /**
  * ONAP Portal SDK sample application. Extends core AppConfig class to
@@ -85,18 +82,9 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
 @EnableScheduling
 public class ExternalAppConfig extends AppConfig implements Configurable {
 
-       private RegistryAdapter schedulerRegistryAdapter;
-    /** The Constant LOG. */
+       /** The Constant LOG. */
     private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
-    /** The vid schema script. */
-    @Value("classpath:vid-schema.sql")
-    private Resource vidSchemaScript;
-
-    /** The vid data script. */
-    @Value("classpath:vid-data.sql")
-    private Resource vidDataScript;
-    
+
     /**
      * The Class InnerConfiguration.
      */
@@ -105,31 +93,14 @@ public class ExternalAppConfig extends AppConfig implements Configurable {
        static class InnerConfiguration {
        }
 
-       /**
-        * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
-        */
-       @Override
-       public ViewResolver viewResolver() {
-               return super.viewResolver();
-       }
-
-       /**
-        * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
-        * 
-        * @param registry
-        */
-       @Override
-       public void addResourceHandlers(ResourceHandlerRegistry registry) {
-               super.addResourceHandlers(registry);
-       }
-
        /**
         * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
         */
        @Override
+       @DependsOn("liquibaseBean")
        public DataAccessService dataAccessService() {
                // Echo the JDBC URL to assist developers when starting the app.
-               System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
+               LOG.info("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
                                + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
                return super.dataAccessService();
        }
@@ -137,7 +108,7 @@ public class ExternalAppConfig extends AppConfig implements Configurable {
        /**
         * Creates a new list with a single entry that is the external app
         * definitions.xml path.
-        * 
+        *
         * @return List of String, size 1
         */
        @Override
@@ -161,7 +132,7 @@ public class ExternalAppConfig extends AppConfig implements Configurable {
 
        /**
         * Creates and returns a new instance of a {@link CacheManager} class.
-        * 
+        *
         * @return New instance of {@link CacheManager}
         */
        @Bean
@@ -172,65 +143,44 @@ public class ExternalAppConfig extends AppConfig implements Configurable {
        /**
         * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
         * populates it with triggers.
-        * 
+        *
         * @return New instance of {@link SchedulerFactoryBean}
-        * @throws Exception
         */
-       // @Bean // ANNOTATION COMMENTED OUT
-       // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
-       public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
-               SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
-               scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
-               scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
-               scheduler.setDataSource(dataSource());
-               return scheduler;
+       @Bean
+       @DependsOn("liquibaseBean")
+       public SchedulerFactoryBean schedulerFactoryBean() {
+               SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
+               schedulerFactory.setJobFactory(new SpringBeanJobFactory());
+               return schedulerFactory;
        }
 
-       
-       /**
-     * Data source initializer.
-     *
-     * @param dataSource the data source
-     * @return the data source initializer
-     */
-    @Bean
-    public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
-        
-        LOG.info("Initializing VID data source");
-        
-        final DataSourceInitializer initializer = new DataSourceInitializer();
-        initializer.setDataSource(dataSource);
-        initializer.setDatabasePopulator(databasePopulator());
-        return initializer;
-    }
-    
-    /**
-     * Database populator.
-     *
-     * @return the database populator
-     */
-    public DatabasePopulator databasePopulator() {
-        LOG.info("Populating VID data source");
-        
-        final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
-        populator.addScript(vidSchemaScript);
-        populator.addScript(vidDataScript);
-        return populator;
-    }
-       
-       
-       /**
-        * Sets the scheduler registry adapter.
-        * 
-        * @param schedulerRegistryAdapter
-        */
-       @Autowired
-       public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
-               this.schedulerRegistryAdapter = schedulerRegistryAdapter;
+
+       @Bean
+       @Order(1)
+       public SpringLiquibase liquibaseBean(DataSource dataSource) {
+               SpringLiquibase springLiquibase = new SpringLiquibase();
+               springLiquibase.setDataSource(dataSource);
+               springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
+               return springLiquibase;
        }
 
        @Bean
-       public LoginStrategy loginStrategy() {
-               return new LoginStrategyImpl();
+       public LoginStrategy loginStrategy(@Value("${login.strategy.classname:}") String classname) throws ReflectiveOperationException {
+               return isNotEmpty(classname) ?
+                       newLoginStrategyInstance(classname) : new LoginStrategyImpl();
+       }
+
+       private LoginStrategy newLoginStrategyInstance(String loginStrategyClassname) throws ReflectiveOperationException {
+               return (LoginStrategy) Class.forName(loginStrategyClassname)
+                       .getConstructor()
+                       .newInstance();
        }
+
+       @Bean
+       public CommonsMultipartResolver multipartResolver() {
+               CommonsMultipartResolver resolver=new CommonsMultipartResolver();
+               resolver.setDefaultEncoding("utf-8");
+               return resolver;
+       }
+
 }