org.onap migration
[vid.git] / epsdk-app-onap / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*-
2  * ================================================================================
3  * ECOMP Portal SDK
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
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  * ================================================================================
19  */
20 package org.onap.portalapp.conf;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import javax.annotation.PostConstruct;
25 import javax.sql.DataSource;
26
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;
61 /**
62  * ECOMP Portal SDK sample application. ECOMP Portal SDK core AppConfig class to
63  * reuse interceptors, 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         private RegistryAdapter schedulerRegistryAdapter;
75         /** The Constant LOG. */
76         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
77
78         /** The vid schema script. */
79         @Value("classpath:vid-schema.sql")
80         private Resource vidSchemaScript;
81
82         /** The vid data script. */
83         @Value("classpath:vid-data.sql")
84         private Resource vidDataScript;
85         
86         /**
87          * The Class InnerConfiguration.
88          */
89         @Configuration
90         @Import(SystemProperties.class)
91         static class InnerConfiguration {
92         }
93
94         /**
95          * View resolver.
96          *
97          * @return the view resolver
98          * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
99          */
100         public ViewResolver viewResolver() {
101                 return super.viewResolver();
102         }
103
104         /**
105          * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
106          * 
107          * @param registry
108          */
109         public void addResourceHandlers(ResourceHandlerRegistry registry) {
110                 super.addResourceHandlers(registry);
111         }
112
113         /**
114          * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
115          */
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();
121         }
122
123         /**
124          * Creates a new list with a single entry that is the external app
125          * definitions.xml path.
126          * 
127          * @return List of String, size 1
128          */
129         public List<String> addTileDefinitions() {
130                 List<String> definitions = new ArrayList<String>();
131                 definitions.add("/WEB-INF/defs/definitions.xml");
132                 return definitions;
133         }
134
135         /**
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.
139          */
140         @Override
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);
145         }
146
147         /**
148          * Creates and returns a new instance of a {@link CacheManager} class.
149          * 
150          * @return New instance of {@link CacheManager}
151          */
152         @Bean
153         public AbstractCacheManager cacheManager() {
154                 return new CacheManager();
155         }
156
157         
158
159
160        /**
161          * Creates and returns a new instance of a {@link FusionLicenseManager}.
162          * 
163          * @return New instance of {@link FusionLicenseManager}.
164          */
165 //      @Bean
166 //      public FusionLicenseManager fusionLicenseManager() {
167 //              return new FusionLicenseManagerImpl();
168 //      }
169
170         /**
171          * Creates and returns a new instance of a
172          * {@link FusionLicenseManagerUtils}.
173          * 
174          * @return New instance of {@link FusionLicenseManagerUtils}.
175          */
176 //      @Bean
177 //      public FusionLicenseManagerUtils fusionLicenseManagerUtils() {
178 //              return new FusionLicenseManagerUtils();
179 //      }
180
181         /**
182          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
183          * populates it with triggers.
184          * 
185          * @return New instance of {@link SchedulerFactoryBean}
186          * @throws Exception
187          */
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());
195                 return scheduler;
196         }
197
198         /**
199          * Data source initializer.
200          *
201          * @param dataSource the data source
202          * @return the data source initializer
203          */
204         @Bean
205         public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
206                 
207                 LOG.info("Initializing VID data source");
208                 
209                 final DataSourceInitializer initializer = new DataSourceInitializer();
210                 initializer.setDataSource(dataSource);
211                 initializer.setDatabasePopulator(databasePopulator());
212                 return initializer;
213         }
214         
215         /**
216          * Database populator.
217          *
218          * @return the database populator
219          */
220         public DatabasePopulator databasePopulator() {
221                 LOG.info("Populating VID data source");
222                 
223                 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
224                 populator.addScript(vidSchemaScript);
225                 populator.addScript(vidDataScript);
226                 return populator;
227         }
228         
229         /**
230          * Sets the scheduler registry adapter.
231          * 
232          * @param schedulerRegistryAdapter
233          */
234         @Autowired
235         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
236                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
237         }
238
239         /**
240          * Creates the LoginStrategy
241          * @return instance of LoginStrategy
242          */
243         @Bean
244         public LoginStrategy loginStrategy() {
245
246                 return new LoginStrategyImpl();
247         }
248 }