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.onboarding.util.PortalApiProperties;
35 import org.onap.portalsdk.core.service.DataAccessService;
36 import org.onap.portalsdk.core.util.CacheManager;
37 import org.onap.portalsdk.core.util.SystemProperties;
38 import org.onap.portalsdk.core.web.support.UserUtils;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.ComponentScan;
42 import org.springframework.context.annotation.Configuration;
43 import org.springframework.context.annotation.Import;
44 import org.springframework.context.annotation.Profile;
45 import org.springframework.context.annotation.PropertySource;
46 import org.springframework.scheduling.annotation.EnableAsync;
47 import org.springframework.scheduling.annotation.EnableScheduling;
48 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
49 import org.springframework.web.servlet.ViewResolver;
50 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
51 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
52 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
54 import com.mchange.v2.c3p0.ComboPooledDataSource;
58 @ComponentScan(basePackages = { "org.akraino", "org.onap" })
59 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
63 @Import({ MusicSessionConfig.class })
64 public class ExternalAppConfig extends AppConfig implements Configurable {
66 private RegistryAdapter schedulerRegistryAdapter;
67 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
70 @Import(SystemProperties.class)
71 static class InnerConfiguration {
75 * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
78 public ViewResolver viewResolver() {
79 return super.viewResolver();
83 * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
88 public void addResourceHandlers(ResourceHandlerRegistry registry) {
89 super.addResourceHandlers(registry);
93 * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
96 public DataAccessService dataAccessService() {
97 return super.dataAccessService();
102 * Creates the Application Data Source.
104 * @return DataSource Object
105 * @throws Exception on failure to create data source object
109 public DataSource dataSource() throws Exception {
113 ComboPooledDataSource dataSource = new ComboPooledDataSource();
115 dataSource.setDriverClass(SystemProperties.getProperty(SystemProperties.DB_DRIVER));
116 dataSource.setJdbcUrl("jdbc:mysql://" + System.getenv("DB_IP_PORT") + "/"
117 + PortalApiProperties.getProperty("akraino_database_name"));
118 dataSource.setUser(System.getenv("MYSQL_USER"));
119 String password = System.getenv("MYSQL_PASSWORD");
120 if (SystemProperties.containsProperty(SystemProperties.DB_ENCRYPT_FLAG)) {
121 String encryptFlag = SystemProperties.getProperty(SystemProperties.DB_ENCRYPT_FLAG);
122 if (encryptFlag != null && encryptFlag.equalsIgnoreCase("true")) {
123 password = CipherUtil.decrypt(password);
126 dataSource.setPassword(password);
128 .setMinPoolSize(Integer.parseInt(SystemProperties.getProperty(SystemProperties.DB_MIN_POOL_SIZE)));
130 .setMaxPoolSize(Integer.parseInt(SystemProperties.getProperty(SystemProperties.DB_MAX_POOL_SIZE)));
131 dataSource.setIdleConnectionTestPeriod(
132 Integer.parseInt(SystemProperties.getProperty(SystemProperties.IDLE_CONNECTION_TEST_PERIOD)));
133 dataSource.setTestConnectionOnCheckout(getConnectionOnCheckout());
134 dataSource.setPreferredTestQuery(getPreferredTestQuery());
135 } catch (Exception e) {
136 LOGGER.error(EELFLoggerDelegate.errorLogger,
137 "Error initializing database, verify database settings in properties file: "
138 + UserUtils.getStackTrace(e),
139 AlarmSeverityEnum.CRITICAL);
140 LOGGER.error(EELFLoggerDelegate.debugLogger,
141 "Error initializing database, verify database settings in properties file: "
142 + UserUtils.getStackTrace(e),
143 AlarmSeverityEnum.CRITICAL);
144 // Raise an alarm that opening a connection to the database failed.
145 LOGGER.logEcompError(AppMessagesEnum.BeDaoSystemError);
152 * Creates a new list with a single entry that is the external app
153 * definitions.xml path.
155 * @return List of String, size 1
158 public List<String> addTileDefinitions() {
159 List<String> definitions = new ArrayList<>();
160 definitions.add("/WEB-INF/defs/definitions.xml");
165 * Adds request interceptors to the specified registry by calling
166 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes certain
167 * paths from the session timeout interceptor.
170 public void addInterceptors(InterceptorRegistry registry) {
171 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
172 "/api*", "/single_signon.htm", "/single_signon", "logout", "/logout.htm", "/process_csp");
173 super.addInterceptors(registry);
177 * Creates and returns a new instance of a {@link CacheManager} class.
179 * @return New instance of {@link CacheManager}
182 public AbstractCacheManager cacheManager() {
183 return new CacheManager();
187 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
188 * populates it with triggers.
190 * @return New instance of {@link SchedulerFactoryBean}
193 // @Bean // ANNOTATION COMMENTED OUT
194 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
195 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
196 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
197 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
198 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
199 scheduler.setDataSource(dataSource());
204 * Sets the scheduler registry adapter.
206 * @param schedulerRegistryAdapter
209 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
210 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
214 public LoginStrategy loginStrategy() {
215 return new LoginStrategyImpl();
219 * Gets the value of the property {@link SystemProperties#PREFERRED_TEST_QUERY};
220 * defaults to "Select 1" if the property is not defined.
222 * @return String value that is a SQL query
224 private String getPreferredTestQuery() {
225 // Use simple default
226 String preferredTestQueryStr = "SELECT 1";
227 if (SystemProperties.containsProperty(SystemProperties.PREFERRED_TEST_QUERY)) {
228 preferredTestQueryStr = SystemProperties.getProperty(SystemProperties.PREFERRED_TEST_QUERY);
229 LOGGER.debug(EELFLoggerDelegate.debugLogger, "getPreferredTestQuery: property key {} value is {}",
230 SystemProperties.PREFERRED_TEST_QUERY, preferredTestQueryStr);
232 LOGGER.info(EELFLoggerDelegate.errorLogger,
233 "getPreferredTestQuery: property key {} not found, using default value {}",
234 SystemProperties.PREFERRED_TEST_QUERY, preferredTestQueryStr);
236 return preferredTestQueryStr;
240 * Gets the value of the property
241 * {@link SystemProperties#TEST_CONNECTION_ON_CHECKOUT}; defaults to true if the
242 * property is not defined.
244 * @return Boolean value
246 private Boolean getConnectionOnCheckout() {
247 // Default to true, always test connection
248 boolean testConnectionOnCheckout = true;
249 if (SystemProperties.containsProperty(SystemProperties.TEST_CONNECTION_ON_CHECKOUT)) {
250 testConnectionOnCheckout = Boolean
251 .valueOf(SystemProperties.getProperty(SystemProperties.TEST_CONNECTION_ON_CHECKOUT));
252 LOGGER.debug(EELFLoggerDelegate.debugLogger, "getConnectionOnCheckout: property key {} value is {}",
253 SystemProperties.TEST_CONNECTION_ON_CHECKOUT, testConnectionOnCheckout);
255 LOGGER.info(EELFLoggerDelegate.errorLogger,
256 "getConnectionOnCheckout: property key {} not found, using default value {}",
257 SystemProperties.TEST_CONNECTION_ON_CHECKOUT, testConnectionOnCheckout);
259 return testConnectionOnCheckout;