2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ================================================================================
20 package org.onap.portalapp.conf;
22 import java.util.ArrayList;
23 import java.util.List;
24 import javax.annotation.PostConstruct;
25 import javax.sql.DataSource;
27 import org.onap.portalapp.login.LoginStrategyImpl;
28 import org.onap.portalapp.scheduler.RegistryAdapter;
29 import org.openecomp.portalsdk.core.auth.LoginStrategy;
30 import org.openecomp.portalsdk.core.conf.AppConfig;
31 import org.openecomp.portalsdk.core.conf.Configurable;
32 import org.openecomp.portalsdk.core.lm.FusionLicenseManager;
33 import org.openecomp.portalsdk.core.lm.FusionLicenseManagerUtils;
34 //import org.openecomp.portalsdk.core.lm.LicenseableClassImpl;
35 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
36 import org.openecomp.portalsdk.core.service.DataAccessService;
37 import org.openecomp.portalsdk.core.util.CacheManager;
38 import org.openecomp.portalsdk.core.util.SystemProperties;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.beans.factory.annotation.Value;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.ComponentScan;
43 import org.springframework.context.annotation.Configuration;
44 import org.springframework.context.annotation.Import;
45 import org.springframework.context.annotation.Profile;
46 import org.springframework.context.annotation.PropertySource;
47 import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
48 import org.springframework.core.io.Resource;
49 import org.springframework.jdbc.datasource.init.DataSourceInitializer;
50 import org.springframework.jdbc.datasource.init.DatabasePopulator;
51 import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
52 import org.springframework.scheduling.annotation.EnableAsync;
53 import org.springframework.scheduling.annotation.EnableScheduling;
54 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
55 import org.springframework.web.servlet.ViewResolver;
56 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
57 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
58 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
59 import org.openecomp.portalsdk.core.service.DataAccessService;
60 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;
62 * ECOMP Portal SDK sample application. ECOMP Portal SDK core AppConfig class to
63 * reuse interceptors, view resolvers and other features defined there.
67 @ComponentScan(basePackages = "org.openecomp")
68 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
72 public class ExternalAppConfig extends AppConfig implements Configurable {
74 private RegistryAdapter schedulerRegistryAdapter;
75 /** The Constant LOG. */
76 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
78 /** The vid schema script. */
79 @Value("classpath:vid-schema.sql")
80 private Resource vidSchemaScript;
82 /** The vid data script. */
83 @Value("classpath:vid-data.sql")
84 private Resource vidDataScript;
87 * The Class InnerConfiguration.
90 @Import(SystemProperties.class)
91 static class InnerConfiguration {
97 * @return the view resolver
98 * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
100 public ViewResolver viewResolver() {
101 return super.viewResolver();
105 * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
109 public void addResourceHandlers(ResourceHandlerRegistry registry) {
110 super.addResourceHandlers(registry);
114 * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
116 public DataAccessService dataAccessService() {
117 // Echo the JDBC URL to assist developers when starting the app.
118 System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
119 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
120 return super.dataAccessService();
124 * Creates a new list with a single entry that is the external app
125 * definitions.xml path.
127 * @return List of String, size 1
129 public List<String> addTileDefinitions() {
130 List<String> definitions = new ArrayList<String>();
131 definitions.add("/WEB-INF/defs/definitions.xml");
136 * Adds request interceptors to the specified registry by calling
137 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
138 * certain paths from the session timeout interceptor.
141 public void addInterceptors(InterceptorRegistry registry) {
142 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
143 "/api*", "/single_signon.htm", "/single_signon");
144 super.addInterceptors(registry);
148 * Creates and returns a new instance of a {@link CacheManager} class.
150 * @return New instance of {@link CacheManager}
153 public AbstractCacheManager cacheManager() {
154 return new CacheManager();
161 * Creates and returns a new instance of a {@link FusionLicenseManager}.
163 * @return New instance of {@link FusionLicenseManager}.
166 // public FusionLicenseManager fusionLicenseManager() {
167 // return new FusionLicenseManagerImpl();
171 * Creates and returns a new instance of a
172 * {@link FusionLicenseManagerUtils}.
174 * @return New instance of {@link FusionLicenseManagerUtils}.
177 // public FusionLicenseManagerUtils fusionLicenseManagerUtils() {
178 // return new FusionLicenseManagerUtils();
182 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
183 * populates it with triggers.
185 * @return New instance of {@link SchedulerFactoryBean}
188 // @Bean // ANNOTATION COMMENTED OUT
189 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
190 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
191 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
192 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
193 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
194 scheduler.setDataSource(dataSource());
199 * Data source initializer.
201 * @param dataSource the data source
202 * @return the data source initializer
205 public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
207 LOG.info("Initializing VID data source");
209 final DataSourceInitializer initializer = new DataSourceInitializer();
210 initializer.setDataSource(dataSource);
211 initializer.setDatabasePopulator(databasePopulator());
216 * Database populator.
218 * @return the database populator
220 public DatabasePopulator databasePopulator() {
221 LOG.info("Populating VID data source");
223 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
224 populator.addScript(vidSchemaScript);
225 populator.addScript(vidDataScript);
230 * Sets the scheduler registry adapter.
232 * @param schedulerRegistryAdapter
235 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
236 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
240 * Creates the LoginStrategy
241 * @return instance of LoginStrategy
244 public LoginStrategy loginStrategy() {
246 return new LoginStrategyImpl();