blob: da07bba575961aec1eac9aa1004b89b3c6a1bdaf [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
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
22
23package org.onap.portalapp.conf;
24
25import javax.sql.DataSource;
26
27import org.onap.portalapp.login.LoginStrategyImpl;
28import org.onap.portalapp.scheduler.RegistryAdapter;
29import org.onap.portalsdk.core.auth.LoginStrategy;
30import org.onap.portalsdk.core.conf.AppConfig;
31import org.onap.portalsdk.core.conf.Configurable;
32import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
33import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
34import org.onap.portalsdk.core.service.DataAccessService;
35import org.onap.portalsdk.core.util.CacheManager;
36import org.onap.portalsdk.core.util.SystemProperties;
37import org.springframework.beans.factory.annotation.Autowired;
38import org.springframework.beans.factory.annotation.Value;
39import org.springframework.context.annotation.Bean;
40import org.springframework.context.annotation.ComponentScan;
41import org.springframework.context.annotation.Configuration;
42import org.springframework.context.annotation.DependsOn;
43import org.springframework.context.annotation.Import;
44import org.springframework.context.annotation.Profile;
45import org.springframework.context.annotation.PropertySource;
46import org.springframework.scheduling.annotation.EnableAsync;
47import org.springframework.scheduling.annotation.EnableScheduling;
48import org.springframework.scheduling.quartz.SchedulerFactoryBean;
49import org.springframework.scheduling.quartz.SpringBeanJobFactory;
50import org.springframework.web.multipart.commons.CommonsMultipartResolver;
51import org.springframework.web.servlet.ViewResolver;
52import org.springframework.web.servlet.config.annotation.EnableWebMvc;
53import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
54import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
55import org.springframework.core.io.Resource;
56import org.springframework.jdbc.datasource.init.DataSourceInitializer;
57import org.springframework.jdbc.datasource.init.DatabasePopulator;
58import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
59
60/**
61 * ONAP Portal SDK sample application. Extends core AppConfig class to
62 * reuse interceptors, view resolvers and other features defined there.
63 */
64@Configuration
65@EnableWebMvc
66@ComponentScan(basePackages = {"org.onap"})
67@PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
68@Profile("src")
69@EnableAsync
70@EnableScheduling
71public class ExternalAppConfig extends AppConfig implements Configurable {
72
73 private RegistryAdapter schedulerRegistryAdapter;
74 /** The Constant LOG. */
75 private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
76
77 /** The vid schema script. */
78 @Value("classpath:osam-core-schema.sql")
79 private Resource osamCoreSchemaScript;
80
81 /** The vid data script. */
82 @Value("classpath:osam-core-data.sql")
83 private Resource osamCoreDataScript;
84
85 /**
86 * The Class InnerConfiguration.
87 */
88 @Configuration
89 @Import(SystemProperties.class)
90 static class InnerConfiguration {
91 }
92
93 /**
94 * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
95 */
96 @Override
97 public ViewResolver viewResolver() {
98 return super.viewResolver();
99 }
100
101 /**
102 * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
103 *
104 * @param registry
105 */
106 @Override
107 public void addResourceHandlers(ResourceHandlerRegistry registry) {
108 super.addResourceHandlers(registry);
109 }
110
111 /**
112 * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
113 */
114 @Override
115 public DataAccessService dataAccessService() {
116 // Echo the JDBC URL to assist developers when starting the app.
117 System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
118 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
119 return super.dataAccessService();
120 }
121
122 /**
123 * Creates a new list with a single entry that is the external app
124 * definitions.xml path.
125 *
126 * @return List of String, size 1
127 */
128 /*@Override
129 public List<String> addTileDefinitions() {
130 List<String> definitions = new ArrayList<>();
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 * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
159 * populates it with triggers.
160 *
161 * @return New instance of {@link SchedulerFactoryBean}
162 * @throws Exception
163 */
164 @Bean // ANNOTATION COMMENTED OUT
165 // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
166 @DependsOn("dataSourceInitializer")
167 public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
168 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
169 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
170 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
171 scheduler.setDataSource(dataSource());
172 scheduler.setJobFactory(new SpringBeanJobFactory());
173 return scheduler;
174 }
175
176
177 /**
178 * Data source initializer.
179 *
180 * @param dataSource the data source
181 * @return the data source initializer
182 */
183 @Bean
184 public DataSourceInitializer dataSourceInitializer(DataSource dataSource) {
185
186 LOG.info("Initializing OSAM CORE data source");
187
188 final DataSourceInitializer initializer = new DataSourceInitializer();
189 initializer.setDataSource(dataSource);
190 initializer.setDatabasePopulator(databasePopulator());
191 return initializer;
192 }
193
194 /**
195 * Database populator.
196 *
197 * @return the database populator
198 */
199 public DatabasePopulator databasePopulator() {
200 LOG.info("Populating OSAM CORE data source");
201
202 final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
203 populator.addScript(osamCoreSchemaScript);
204 populator.addScript(osamCoreDataScript);
205 return populator;
206 }
207
208
209 /*@Bean
210 public SpringLiquibase liquibaseBean(DataSource dataSource) {
211 SpringLiquibase springLiquibase = new SpringLiquibase();
212 springLiquibase.setDataSource(dataSource);
213 springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
214 return springLiquibase;
215 }*/
216
217 /**
218 * Sets the scheduler registry adapter.
219 *
220 * @param schedulerRegistryAdapter
221 */
222 @Autowired
223 public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
224 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
225 }
226
227 @Bean
228 public LoginStrategy loginStrategy() {
229 return new LoginStrategyImpl();
230 }
231
232 @Bean
233 public CommonsMultipartResolver multipartResolver() {
234 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
235 resolver.setDefaultEncoding("utf-8");
236 return resolver;
237 }
238
239}