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;
42 import javax.sql.DataSource;
43 import org.onap.portalapp.login.LoginStrategyImpl;
44 import org.onap.portalsdk.core.auth.LoginStrategy;
45 import org.onap.portalsdk.core.conf.AppConfig;
46 import org.onap.portalsdk.core.conf.Configurable;
47 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
48 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
49 import org.onap.portalsdk.core.service.DataAccessService;
50 import org.onap.portalsdk.core.util.CacheManager;
51 import org.onap.portalsdk.core.util.SystemProperties;
52 import org.springframework.beans.factory.annotation.Value;
53 import org.springframework.context.annotation.Bean;
54 import org.springframework.context.annotation.ComponentScan;
55 import org.springframework.context.annotation.Configuration;
56 import org.springframework.context.annotation.DependsOn;
57 import org.springframework.context.annotation.EnableAspectJAutoProxy;
58 import org.springframework.context.annotation.Import;
59 import org.springframework.context.annotation.Profile;
60 import org.springframework.context.annotation.PropertySource;
61 import org.springframework.core.io.Resource;
62 import org.springframework.jdbc.datasource.init.DataSourceInitializer;
63 import org.springframework.jdbc.datasource.init.DatabasePopulator;
64 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
65 import org.springframework.scheduling.annotation.EnableAsync;
66 import org.springframework.scheduling.annotation.EnableScheduling;
67 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
68 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
69 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
70 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
71 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
74 * ONAP Portal SDK sample application. Extends core AppConfig class to
75 * reuse interceptors, view resolvers and other features defined there.
79 @ComponentScan(basePackages = {"org.onap"})
80 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
84 @EnableAspectJAutoProxy(proxyTargetClass=true)
85 public class ExternalAppConfig extends AppConfig implements Configurable {
87 /** The Constant LOG. */
88 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
90 /** The vid schema script. */
91 @Value("classpath:vid-schema.sql")
92 private Resource vidSchemaScript;
94 /** The vid data script. */
95 @Value("classpath:vid-data.sql")
96 private Resource vidDataScript;
99 * The Class InnerConfiguration.
102 @Import(SystemProperties.class)
103 static class InnerConfiguration {
107 * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
110 public DataAccessService dataAccessService() {
111 // Echo the JDBC URL to assist developers when starting the app.
112 LOG.info("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
113 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
114 return super.dataAccessService();
118 * Creates a new list with a single entry that is the external app
119 * definitions.xml path.
121 * @return List of String, size 1
124 public List<String> addTileDefinitions() {
125 List<String> definitions = new ArrayList<>();
126 definitions.add("/WEB-INF/defs/definitions.xml");
131 * Adds request interceptors to the specified registry by calling
132 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
133 * certain paths from the session timeout interceptor.
136 public void addInterceptors(InterceptorRegistry registry) {
137 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
138 "/api*", "/single_signon.htm", "/single_signon");
139 super.addInterceptors(registry);
143 * Creates and returns a new instance of a {@link CacheManager} class.
145 * @return New instance of {@link CacheManager}
148 public AbstractCacheManager cacheManager() {
149 return new CacheManager();
153 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
154 * populates it with triggers.
156 * @return New instance of {@link SchedulerFactoryBean}
159 @DependsOn("dataSourceInitializer")
160 public SchedulerFactoryBean schedulerFactoryBean() {
161 SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
162 schedulerFactory.setJobFactory(new SpringBeanJobFactory());
163 return schedulerFactory;
168 * Data source initializer.
170 * @param dataSource the data source
171 * @return the data source initializer
174 public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
176 LOG.info("Initializing VID data source");
178 final DataSourceInitializer initializer = new DataSourceInitializer();
179 initializer.setDataSource(dataSource);
180 initializer.setDatabasePopulator(databasePopulator());
185 * Database populator.
187 * @return the database populator
189 public DatabasePopulator databasePopulator() {
190 LOG.info("Populating VID data source");
192 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
193 populator.addScript(vidSchemaScript);
194 populator.addScript(vidDataScript);
199 public LoginStrategy loginStrategy() {
200 return new LoginStrategyImpl();
204 public CommonsMultipartResolver multipartResolver() {
205 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
206 resolver.setDefaultEncoding("utf-8");