actually adding the files to the initial commit
[vid.git] / vid / src / main / java / org / openecomp / vid / conf / ExternalAppConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.vid.conf;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import javax.annotation.PostConstruct;
27 import javax.sql.DataSource;
28
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;
60 /**
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.
64  */
65 @Configuration
66 @EnableWebMvc
67 @ComponentScan(basePackages = "org.openecomp")
68 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
69 @Profile("src")
70 @EnableAsync
71 @EnableScheduling
72 public class ExternalAppConfig extends AppConfig implements Configurable {
73         
74         /** The Constant LOG. */
75         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
76         
77         /** The scheduler registry adapter. */
78         private RegistryAdapter schedulerRegistryAdapter;
79
80         /** The vid schema script. */
81         @Value("classpath:vid-schema.sql")
82         private Resource vidSchemaScript;
83
84         /** The vid data script. */
85         @Value("classpath:vid-data.sql")
86         private Resource vidDataScript;
87         
88         /**
89          * The Class InnerConfiguration.
90          */
91         @Configuration
92         @Import(SystemProperties.class)
93         static class InnerConfiguration {
94         }
95
96         /**
97          * View resolver.
98          *
99          * @return the view resolver
100          * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
101          */
102         public ViewResolver viewResolver() {
103                 return super.viewResolver();
104         }
105
106         /**
107          * Adds the resource handlers.
108          *
109          * @param registry the registry
110          * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
111          */
112         public void addResourceHandlers(ResourceHandlerRegistry registry) {
113                 super.addResourceHandlers(registry);
114         }
115
116         /**
117          * Data access service.
118          *
119          * @return the data access service
120          * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
121          */
122         public DataAccessService dataAccessService() {
123                 return super.dataAccessService();
124         }
125
126         /**
127          * Creates a new list with a single entry that is the external app
128          * definitions.xml path.
129          * 
130          * @return List of String, size 1
131          */
132         public List<String> addTileDefinitions() {
133                 List<String> definitions = new ArrayList<String>();
134                 definitions.add("/WEB-INF/defs/definitions.xml");
135                 return definitions;
136         }
137
138         /**
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.
142          *
143          * @param registry the registry
144          */
145         @Override
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);
150         }
151
152         /**
153          * Creates and returns a new instance of a {@link CacheManager} class.
154          * 
155          * @return New instance of {@link CacheManager}
156          */
157         @Bean
158         public AbstractCacheManager cacheManager() {
159                 return new CacheManager();
160         }
161         
162         /**
163          * Inits the global local context.
164          */
165         @PostConstruct
166         public void initGlobalLocalContext() {
167                 LOG.init();
168         }
169
170         
171         /**
172          * Creates and returns a new instance of a {@link MainUebHandler}. 
173          * 
174          * @return New instance of {@link MainUebHandler}.
175          */
176         @Bean
177         public MainUebHandler mainUebHandler() {
178                 
179                 return new MainUebHandler();
180         }
181         
182         /**
183          * Creates and returns a new instance of a {@link InitUebHandler}.  
184          * 
185          * @return New instance of {@link InitUebHandler}.
186          */
187         @Bean
188         public InitUebHandler initUebHandler() {
189                 
190                 return new InitUebHandler();
191         }
192
193         /**
194          * Creates and returns a new instance of a {@link WidgetNotificationHandler}
195          * .
196          * 
197          * @return New instance of {@link WidgetNotificationHandler}.
198          */
199         @Bean
200         public WidgetNotificationHandler widgetNotificationHandler() {
201                 return new WidgetNotificationHandler();
202         }
203         
204         /**
205          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
206          * populates it with triggers.
207          *
208          * @return New instance of {@link SchedulerFactoryBean}
209          * @throws Exception the exception
210          */
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());
218                 return scheduler;
219         }
220
221         /**
222          * Data source initializer.
223          *
224          * @param dataSource the data source
225          * @return the data source initializer
226          */
227         @Bean
228         public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
229                 
230                 LOG.info("Initializing VID data source");
231                 
232                 final DataSourceInitializer initializer = new DataSourceInitializer();
233                 initializer.setDataSource(dataSource);
234                 initializer.setDatabasePopulator(databasePopulator());
235                 return initializer;
236         }
237         
238         /**
239          * Database populator.
240          *
241          * @return the database populator
242          */
243         public DatabasePopulator databasePopulator() {
244                 LOG.info("Populating VID data source");
245                 
246                 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
247                 populator.addScript(vidSchemaScript);
248                 populator.addScript(vidDataScript);
249                 return populator;
250         }
251         
252         /**
253          * Sets the scheduler registry adapter.
254          *
255          * @param schedulerRegistryAdapter the new scheduler registry adapter
256          */
257         @Autowired
258         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
259                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
260         }
261         
262         /**
263          * Property config in dev.
264          *
265          * @return the property sources placeholder configurer
266          */
267         @Bean
268         public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
269                 return new PropertySourcesPlaceholderConfigurer();
270         }
271 }