2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may
5 * not use this file except in compliance with the License. You may obtain
6 * a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 package org.akraino.validation.ui.conf;
18 import java.util.ArrayList;
19 import java.util.List;
21 import javax.sql.DataSource;
23 import org.akraino.validation.ui.login.LoginStrategyImpl;
24 import org.akraino.validation.ui.scheduler.RegistryAdapter;
25 import org.onap.portalapp.music.conf.MusicSessionConfig;
26 import org.onap.portalsdk.core.auth.LoginStrategy;
27 import org.onap.portalsdk.core.conf.AppConfig;
28 import org.onap.portalsdk.core.conf.Configurable;
29 import org.onap.portalsdk.core.logging.format.AlarmSeverityEnum;
30 import org.onap.portalsdk.core.logging.format.AppMessagesEnum;
31 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
32 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
33 import org.onap.portalsdk.core.onboarding.util.CipherUtil;
34 import org.onap.portalsdk.core.service.DataAccessService;
35 import org.onap.portalsdk.core.util.CacheManager;
36 import org.onap.portalsdk.core.util.SystemProperties;
37 import org.onap.portalsdk.core.web.support.UserUtils;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.context.annotation.Bean;
40 import org.springframework.context.annotation.ComponentScan;
41 import org.springframework.context.annotation.Configuration;
42 import org.springframework.context.annotation.Import;
43 import org.springframework.context.annotation.Profile;
44 import org.springframework.context.annotation.PropertySource;
45 import org.springframework.scheduling.annotation.EnableAsync;
46 import org.springframework.scheduling.annotation.EnableScheduling;
47 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
48 import org.springframework.web.servlet.ViewResolver;
49 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
50 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
51 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
53 import com.mchange.v2.c3p0.ComboPooledDataSource;
57 @ComponentScan(basePackages = {"org.akraino", "org.onap"})
58 @PropertySource(value = {"${container.classpath:}/WEB-INF/conf/app/test.properties"}, ignoreResourceNotFound = true)
62 @Import({MusicSessionConfig.class})
63 public class ExternalAppConfig extends AppConfig implements Configurable {
65 private RegistryAdapter schedulerRegistryAdapter;
66 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
69 @Import(SystemProperties.class)
70 static class InnerConfiguration {
74 * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
77 public ViewResolver viewResolver() {
78 return super.viewResolver();
82 * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
87 public void addResourceHandlers(ResourceHandlerRegistry registry) {
88 super.addResourceHandlers(registry);
92 * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
95 public DataAccessService dataAccessService() {
96 return super.dataAccessService();
101 * Creates the Application Data Source.
103 * @return DataSource Object
104 * @throws Exception on failure to create data source object
108 public DataSource dataSource() throws Exception {
112 ComboPooledDataSource dataSource = new ComboPooledDataSource();
114 dataSource.setDriverClass(SystemProperties.getProperty(SystemProperties.DB_DRIVER));
115 dataSource.setJdbcUrl("jdbc:mariadb://" + System.getenv("DB_CONNECTION_URL"));
116 dataSource.setUser(SystemProperties.getProperty(SystemProperties.DB_USERNAME));
117 String password = System.getenv("MARIADB_ROOT_PASSWORD");
118 if (SystemProperties.containsProperty(SystemProperties.DB_ENCRYPT_FLAG)) {
119 String encryptFlag = SystemProperties.getProperty(SystemProperties.DB_ENCRYPT_FLAG);
120 if (encryptFlag != null && encryptFlag.equalsIgnoreCase("true")) {
121 password = CipherUtil.decrypt(password);
124 dataSource.setPassword(password);
126 .setMinPoolSize(Integer.parseInt(SystemProperties.getProperty(SystemProperties.DB_MIN_POOL_SIZE)));
128 .setMaxPoolSize(Integer.parseInt(SystemProperties.getProperty(SystemProperties.DB_MAX_POOL_SIZE)));
129 dataSource.setIdleConnectionTestPeriod(
130 Integer.parseInt(SystemProperties.getProperty(SystemProperties.IDLE_CONNECTION_TEST_PERIOD)));
131 dataSource.setTestConnectionOnCheckout(getConnectionOnCheckout());
132 dataSource.setPreferredTestQuery(getPreferredTestQuery());
133 } catch (Exception e) {
134 LOGGER.error(EELFLoggerDelegate.errorLogger,
135 "Error initializing database, verify database settings in properties file: "
136 + UserUtils.getStackTrace(e),
137 AlarmSeverityEnum.CRITICAL);
138 LOGGER.error(EELFLoggerDelegate.debugLogger,
139 "Error initializing database, verify database settings in properties file: "
140 + UserUtils.getStackTrace(e),
141 AlarmSeverityEnum.CRITICAL);
142 // Raise an alarm that opening a connection to the database failed.
143 LOGGER.logEcompError(AppMessagesEnum.BeDaoSystemError);
150 * Creates a new list with a single entry that is the external app
151 * definitions.xml path.
153 * @return List of String, size 1
156 public List<String> addTileDefinitions() {
157 List<String> definitions = new ArrayList<>();
158 definitions.add("/WEB-INF/defs/definitions.xml");
163 * Adds request interceptors to the specified registry by calling
164 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
165 * certain paths from the session timeout interceptor.
168 public void addInterceptors(InterceptorRegistry registry) {
169 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
170 "/api*", "/single_signon.htm", "/single_signon");
171 super.addInterceptors(registry);
175 * Creates and returns a new instance of a {@link CacheManager} class.
177 * @return New instance of {@link CacheManager}
180 public AbstractCacheManager cacheManager() {
181 return new CacheManager();
185 * Creates and returns a new instance of a {@link SchedulerFactoryBean}
186 * and populates it with triggers.
188 * @return New instance of {@link SchedulerFactoryBean}
191 // @Bean // ANNOTATION COMMENTED OUT
192 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
193 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
194 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
195 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
196 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
197 scheduler.setDataSource(dataSource());
202 * Sets the scheduler registry adapter.
204 * @param schedulerRegistryAdapter
207 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
208 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
212 public LoginStrategy loginStrategy() {
213 return new LoginStrategyImpl();
217 * Gets the value of the property
218 * {@link SystemProperties#PREFERRED_TEST_QUERY}; defaults to "Select 1"
219 * if the property is not defined.
221 * @return String value that is a SQL query
223 private String getPreferredTestQuery() {
224 // Use simple default
225 String preferredTestQueryStr = "SELECT 1";
226 if (SystemProperties.containsProperty(SystemProperties.PREFERRED_TEST_QUERY)) {
227 preferredTestQueryStr = SystemProperties.getProperty(SystemProperties.PREFERRED_TEST_QUERY);
228 LOGGER.debug(EELFLoggerDelegate.debugLogger, "getPreferredTestQuery: property key {} value is {}",
229 SystemProperties.PREFERRED_TEST_QUERY, preferredTestQueryStr);
231 LOGGER.info(EELFLoggerDelegate.errorLogger,
232 "getPreferredTestQuery: property key {} not found, using default value {}",
233 SystemProperties.PREFERRED_TEST_QUERY, preferredTestQueryStr);
235 return preferredTestQueryStr;
239 * Gets the value of the property
240 * {@link SystemProperties#TEST_CONNECTION_ON_CHECKOUT}; defaults to true
241 * if the property is not defined.
243 * @return Boolean value
245 private Boolean getConnectionOnCheckout() {
246 // Default to true, always test connection
247 boolean testConnectionOnCheckout = true;
248 if (SystemProperties.containsProperty(SystemProperties.TEST_CONNECTION_ON_CHECKOUT)) {
249 testConnectionOnCheckout =
250 Boolean.valueOf(SystemProperties.getProperty(SystemProperties.TEST_CONNECTION_ON_CHECKOUT));
251 LOGGER.debug(EELFLoggerDelegate.debugLogger, "getConnectionOnCheckout: property key {} value is {}",
252 SystemProperties.TEST_CONNECTION_ON_CHECKOUT, testConnectionOnCheckout);
254 LOGGER.info(EELFLoggerDelegate.errorLogger,
255 "getConnectionOnCheckout: property key {} not found, using default value {}",
256 SystemProperties.TEST_CONNECTION_ON_CHECKOUT, testConnectionOnCheckout);
258 return testConnectionOnCheckout;