2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalapp.conf;
40 import java.util.ArrayList;
41 import java.util.List;
43 import javax.sql.DataSource;
45 import org.onap.portalapp.login.LoginStrategyImpl;
46 import org.onap.portalapp.scheduler.RegistryAdapter;
47 import org.onap.portalsdk.core.auth.LoginStrategy;
48 import org.onap.portalsdk.core.conf.AppConfig;
49 import org.onap.portalsdk.core.conf.Configurable;
50 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
51 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
52 import org.onap.portalsdk.core.service.DataAccessService;
53 import org.onap.portalsdk.core.util.CacheManager;
54 import org.onap.portalsdk.core.util.SystemProperties;
55 import org.springframework.beans.factory.annotation.Autowired;
56 import org.springframework.beans.factory.annotation.Value;
57 import org.springframework.context.annotation.Bean;
58 import org.springframework.context.annotation.ComponentScan;
59 import org.springframework.context.annotation.Configuration;
60 import org.springframework.context.annotation.DependsOn;
61 import org.springframework.context.annotation.Import;
62 import org.springframework.context.annotation.Profile;
63 import org.springframework.context.annotation.PropertySource;
64 import org.springframework.scheduling.annotation.EnableAsync;
65 import org.springframework.scheduling.annotation.EnableScheduling;
66 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
67 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
68 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
69 import org.springframework.web.servlet.ViewResolver;
70 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
71 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
72 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
73 import org.springframework.core.io.Resource;
74 import org.springframework.jdbc.datasource.init.DataSourceInitializer;
75 import org.springframework.jdbc.datasource.init.DatabasePopulator;
76 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
79 * ONAP Portal SDK sample application. Extends core AppConfig class to
80 * reuse interceptors, view resolvers and other features defined there.
84 @ComponentScan(basePackages = {"org.onap"})
85 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
89 public class ExternalAppConfig extends AppConfig implements Configurable {
91 private RegistryAdapter schedulerRegistryAdapter;
92 /** The Constant LOG. */
93 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
95 /** The vid schema script. */
96 @Value("classpath:vid-schema.sql")
97 private Resource vidSchemaScript;
99 /** The vid data script. */
100 @Value("classpath:vid-data.sql")
101 private Resource vidDataScript;
104 * The Class InnerConfiguration.
107 @Import(SystemProperties.class)
108 static class InnerConfiguration {
112 * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
115 public ViewResolver viewResolver() {
116 return super.viewResolver();
120 * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
125 public void addResourceHandlers(ResourceHandlerRegistry registry) {
126 super.addResourceHandlers(registry);
130 * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
133 public DataAccessService dataAccessService() {
134 // Echo the JDBC URL to assist developers when starting the app.
135 System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
136 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
137 return super.dataAccessService();
141 * Creates a new list with a single entry that is the external app
142 * definitions.xml path.
144 * @return List of String, size 1
147 public List<String> addTileDefinitions() {
148 List<String> definitions = new ArrayList<>();
149 definitions.add("/WEB-INF/defs/definitions.xml");
154 * Adds request interceptors to the specified registry by calling
155 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
156 * certain paths from the session timeout interceptor.
159 public void addInterceptors(InterceptorRegistry registry) {
160 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
161 "/api*", "/single_signon.htm", "/single_signon");
162 super.addInterceptors(registry);
166 * Creates and returns a new instance of a {@link CacheManager} class.
168 * @return New instance of {@link CacheManager}
171 public AbstractCacheManager cacheManager() {
172 return new CacheManager();
176 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
177 * populates it with triggers.
179 * @return New instance of {@link SchedulerFactoryBean}
182 @Bean // ANNOTATION COMMENTED OUT
183 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
184 @DependsOn("dataSourceInitializer")
185 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
186 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
187 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
188 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
189 scheduler.setDataSource(dataSource());
190 scheduler.setJobFactory(new SpringBeanJobFactory());
196 * Data source initializer.
198 * @param dataSource the data source
199 * @return the data source initializer
202 public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
204 LOG.info("Initializing VID data source");
206 final DataSourceInitializer initializer = new DataSourceInitializer();
207 initializer.setDataSource(dataSource);
208 initializer.setDatabasePopulator(databasePopulator());
213 * Database populator.
215 * @return the database populator
217 public DatabasePopulator databasePopulator() {
218 LOG.info("Populating VID data source");
220 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
221 populator.addScript(vidSchemaScript);
222 populator.addScript(vidDataScript);
228 public SpringLiquibase liquibaseBean(DataSource dataSource) {
229 SpringLiquibase springLiquibase = new SpringLiquibase();
230 springLiquibase.setDataSource(dataSource);
231 springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
232 return springLiquibase;
236 * Sets the scheduler registry adapter.
238 * @param schedulerRegistryAdapter
241 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
242 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
246 public LoginStrategy loginStrategy() {
247 return new LoginStrategyImpl();
251 public CommonsMultipartResolver multipartResolver() {
252 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
253 resolver.setDefaultEncoding("utf-8");