2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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 * ============LICENSE_END=========================================================
21 package org.openecomp.vid.conf;
23 import java.util.ArrayList;
24 import java.util.List;
26 import javax.annotation.PostConstruct;
27 import javax.sql.DataSource;
29 import org.openecomp.vid.scheduler.RegistryAdapter;
30 import org.openecomp.portalapp.uebhandler.InitUebHandler;
31 import org.openecomp.portalapp.uebhandler.MainUebHandler;
32 import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler;
33 import org.openecomp.portalsdk.core.conf.AppConfig;
34 import org.openecomp.portalsdk.core.conf.Configurable;
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.logging.logic.EELFLoggerDelegate;
61 * Configures Spring features in the ECOMP Portal SDK sample application.
62 * Subclasses the ECOMP Portal SDK core AppConfig class to reuse interceptors,
63 * 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 /** The Constant LOG. */
75 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
77 /** The scheduler registry adapter. */
78 private RegistryAdapter schedulerRegistryAdapter;
80 /** The vid schema script. */
81 @Value("classpath:vid-schema.sql")
82 private Resource vidSchemaScript;
84 /** The vid data script. */
85 @Value("classpath:vid-data.sql")
86 private Resource vidDataScript;
89 * The Class InnerConfiguration.
92 @Import(SystemProperties.class)
93 static class InnerConfiguration {
99 * @return the view resolver
100 * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
102 public ViewResolver viewResolver() {
103 return super.viewResolver();
107 * Adds the resource handlers.
109 * @param registry the registry
110 * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
112 public void addResourceHandlers(ResourceHandlerRegistry registry) {
113 super.addResourceHandlers(registry);
117 * Data access service.
119 * @return the data access service
120 * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
122 public DataAccessService dataAccessService() {
123 return super.dataAccessService();
127 * Creates a new list with a single entry that is the external app
128 * definitions.xml path.
130 * @return List of String, size 1
132 public List<String> addTileDefinitions() {
133 List<String> definitions = new ArrayList<String>();
134 definitions.add("/WEB-INF/defs/definitions.xml");
139 * Adds request interceptors to the specified registry by calling
140 * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
141 * certain paths from the session timeout interceptor.
143 * @param registry the registry
146 public void addInterceptors(InterceptorRegistry registry) {
147 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
148 "/api*","/single_signon.htm","/single_signon");
149 super.addInterceptors(registry);
153 * Creates and returns a new instance of a {@link CacheManager} class.
155 * @return New instance of {@link CacheManager}
158 public AbstractCacheManager cacheManager() {
159 return new CacheManager();
163 * Inits the global local context.
166 public void initGlobalLocalContext() {
172 * Creates and returns a new instance of a {@link MainUebHandler}.
174 * @return New instance of {@link MainUebHandler}.
177 public MainUebHandler mainUebHandler() {
179 return new MainUebHandler();
183 * Creates and returns a new instance of a {@link InitUebHandler}.
185 * @return New instance of {@link InitUebHandler}.
188 public InitUebHandler initUebHandler() {
190 return new InitUebHandler();
194 * Creates and returns a new instance of a {@link WidgetNotificationHandler}
197 * @return New instance of {@link WidgetNotificationHandler}.
200 public WidgetNotificationHandler widgetNotificationHandler() {
201 return new WidgetNotificationHandler();
205 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
206 * populates it with triggers.
208 * @return New instance of {@link SchedulerFactoryBean}
209 * @throws Exception the exception
211 // @Bean // ANNOTATION COMMENTED OUT
212 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
213 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
214 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
215 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
216 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
217 scheduler.setDataSource(dataSource());
222 * Data source initializer.
224 * @param dataSource the data source
225 * @return the data source initializer
228 public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
230 LOG.info("Initializing VID data source");
232 final DataSourceInitializer initializer = new DataSourceInitializer();
233 initializer.setDataSource(dataSource);
234 initializer.setDatabasePopulator(databasePopulator());
239 * Database populator.
241 * @return the database populator
243 public DatabasePopulator databasePopulator() {
244 LOG.info("Populating VID data source");
246 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
247 populator.addScript(vidSchemaScript);
248 populator.addScript(vidDataScript);
253 * Sets the scheduler registry adapter.
255 * @param schedulerRegistryAdapter the new scheduler registry adapter
258 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
259 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
263 * Property config in dev.
265 * @return the property sources placeholder configurer
268 public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
269 return new PropertySourcesPlaceholderConfigurer();