Merge from ECOMP's repository
[vid.git] / epsdk-app-onap / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.conf;
39
40 import org.onap.portalapp.login.LoginStrategyImpl;
41 import org.onap.portalapp.scheduler.RegistryAdapter;
42 import org.onap.portalsdk.core.auth.LoginStrategy;
43 import org.onap.portalsdk.core.conf.AppConfig;
44 import org.onap.portalsdk.core.conf.Configurable;
45 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
46 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
47 import org.onap.portalsdk.core.service.DataAccessService;
48 import org.onap.portalsdk.core.util.CacheManager;
49 import org.onap.portalsdk.core.util.SystemProperties;
50 import org.springframework.beans.factory.annotation.Autowired;
51 import org.springframework.beans.factory.annotation.Value;
52 import org.springframework.context.annotation.*;
53 import org.springframework.core.io.Resource;
54 import org.springframework.jdbc.datasource.init.DataSourceInitializer;
55 import org.springframework.jdbc.datasource.init.DatabasePopulator;
56 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
57 import org.springframework.scheduling.annotation.EnableAsync;
58 import org.springframework.scheduling.annotation.EnableScheduling;
59 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
60 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
61 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
62 import org.springframework.web.servlet.ViewResolver;
63 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
64 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
65 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
66
67 import javax.sql.DataSource;
68 import java.util.ArrayList;
69 import java.util.List;
70
71 /**
72  * ONAP Portal SDK sample application. Extends core AppConfig class to
73  * reuse interceptors, view resolvers and other features defined there.
74  */
75 @Configuration
76 @EnableWebMvc
77 @ComponentScan(basePackages = {"org.onap"})
78 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
79 @Profile("src")
80 @EnableAsync
81 @EnableScheduling
82 @EnableAspectJAutoProxy(proxyTargetClass=true)
83 public class ExternalAppConfig extends AppConfig implements Configurable {
84
85         private RegistryAdapter schedulerRegistryAdapter;
86     /** The Constant LOG. */
87     private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
88  
89     /** The vid schema script. */
90     @Value("classpath:vid-schema.sql")
91     private Resource vidSchemaScript;
92
93     /** The vid data script. */
94     @Value("classpath:vid-data.sql")
95     private Resource vidDataScript;
96     
97     /**
98      * The Class InnerConfiguration.
99      */
100         @Configuration
101         @Import(SystemProperties.class)
102         static class InnerConfiguration {
103         }
104
105         /**
106          * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
107          */
108         @Override
109         public ViewResolver viewResolver() {
110                 return super.viewResolver();
111         }
112
113         /**
114          * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
115          * 
116          * @param registry
117          */
118         @Override
119         public void addResourceHandlers(ResourceHandlerRegistry registry) {
120                 super.addResourceHandlers(registry);
121         }
122
123         /**
124          * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
125          */
126         @Override
127         public DataAccessService dataAccessService() {
128                 // Echo the JDBC URL to assist developers when starting the app.
129                 System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
130                                 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
131                 return super.dataAccessService();
132         }
133
134         /**
135          * Creates a new list with a single entry that is the external app
136          * definitions.xml path.
137          * 
138          * @return List of String, size 1
139          */
140         @Override
141         public List<String> addTileDefinitions() {
142                 List<String> definitions = new ArrayList<>();
143                 definitions.add("/WEB-INF/defs/definitions.xml");
144                 return definitions;
145         }
146
147         /**
148          * Adds request interceptors to the specified registry by calling
149          * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
150          * certain paths from the session timeout interceptor.
151          */
152         @Override
153         public void addInterceptors(InterceptorRegistry registry) {
154                 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
155                                 "/api*", "/single_signon.htm", "/single_signon");
156                 super.addInterceptors(registry);
157         }
158
159         /**
160          * Creates and returns a new instance of a {@link CacheManager} class.
161          * 
162          * @return New instance of {@link CacheManager}
163          */
164         @Bean
165         public AbstractCacheManager cacheManager() {
166                 return new CacheManager();
167         }
168
169         /**
170          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
171          * populates it with triggers.
172          * 
173          * @return New instance of {@link SchedulerFactoryBean}
174          */
175         @Bean
176         public SchedulerFactoryBean schedulerFactoryBean() {
177                 SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
178                 schedulerFactory.setJobFactory(new SpringBeanJobFactory());
179                 return schedulerFactory;
180         }
181
182         
183         /**
184      * Data source initializer.
185      *
186      * @param dataSource the data source
187      * @return the data source initializer
188      */
189     @Bean
190     public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
191         
192         LOG.info("Initializing VID data source");
193         
194         final DataSourceInitializer initializer = new DataSourceInitializer();
195         initializer.setDataSource(dataSource);
196         initializer.setDatabasePopulator(databasePopulator());
197         return initializer;
198     }
199     
200     /**
201      * Database populator.
202      *
203      * @return the database populator
204      */
205     public DatabasePopulator databasePopulator() {
206         LOG.info("Populating VID data source");
207         
208         final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
209         populator.addScript(vidSchemaScript);
210         populator.addScript(vidDataScript);
211         return populator;
212     }
213         
214
215         /*@Bean
216         public SpringLiquibase liquibaseBean(DataSource dataSource) {
217                 SpringLiquibase springLiquibase = new SpringLiquibase();
218                 springLiquibase.setDataSource(dataSource);
219                 springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
220                 return springLiquibase;
221         }*/
222         
223         /**
224          * Sets the scheduler registry adapter.
225          * 
226          * @param schedulerRegistryAdapter
227          */
228         @Autowired
229         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
230                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
231         }
232
233         @Bean
234         public LoginStrategy loginStrategy() {
235                 return new LoginStrategyImpl();
236         }
237
238         @Bean
239         public CommonsMultipartResolver multipartResolver() {
240                 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
241                 resolver.setDefaultEncoding("utf-8");
242                 return resolver;
243         }
244
245 }