b4dcd346a9c6091e6bb6e25ec0c4d019f1e01960
[vid.git] / epsdk-app-onap / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.conf;
39
40 import java.util.ArrayList;
41 import java.util.List;
42 import javax.sql.DataSource;
43 import liquibase.integration.spring.SpringLiquibase;
44 import org.onap.portalapp.login.LoginStrategyImpl;
45 import org.onap.portalsdk.core.auth.LoginStrategy;
46 import org.onap.portalsdk.core.conf.AppConfig;
47 import org.onap.portalsdk.core.conf.Configurable;
48 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
49 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
50 import org.onap.portalsdk.core.service.DataAccessService;
51 import org.onap.portalsdk.core.util.CacheManager;
52 import org.onap.portalsdk.core.util.SystemProperties;
53 import org.springframework.context.annotation.Bean;
54 import org.springframework.context.annotation.ComponentScan;
55 import org.springframework.context.annotation.Configuration;
56 import org.springframework.context.annotation.DependsOn;
57 import org.springframework.context.annotation.EnableAspectJAutoProxy;
58 import org.springframework.context.annotation.Import;
59 import org.springframework.context.annotation.Profile;
60 import org.springframework.context.annotation.PropertySource;
61 import org.springframework.core.annotation.Order;
62 import org.springframework.scheduling.annotation.EnableAsync;
63 import org.springframework.scheduling.annotation.EnableScheduling;
64 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
65 import org.springframework.scheduling.quartz.SpringBeanJobFactory;
66 import org.springframework.web.multipart.commons.CommonsMultipartResolver;
67 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
68 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
69
70 /**
71  * ONAP Portal SDK sample application. Extends core AppConfig class to
72  * reuse interceptors, view resolvers and other features defined there.
73  */
74 @Configuration
75 @EnableWebMvc
76 @ComponentScan(basePackages = {"org.onap"})
77 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
78 @Profile("src")
79 @EnableAsync
80 @EnableScheduling
81 @EnableAspectJAutoProxy(proxyTargetClass=true)
82 public class ExternalAppConfig extends AppConfig implements Configurable {
83
84         /** The Constant LOG. */
85     private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
86
87     /**
88      * The Class InnerConfiguration.
89      */
90         @Configuration
91         @Import(SystemProperties.class)
92         static class InnerConfiguration {
93         }
94
95         /**
96          * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
97          */
98         @Override
99         @DependsOn("liquibaseBean")
100         public DataAccessService dataAccessService() {
101                 // Echo the JDBC URL to assist developers when starting the app.
102                 LOG.info("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
103                                 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
104                 return super.dataAccessService();
105         }
106
107         /**
108          * Creates a new list with a single entry that is the external app
109          * definitions.xml path.
110          *
111          * @return List of String, size 1
112          */
113         @Override
114         public List<String> addTileDefinitions() {
115                 List<String> definitions = new ArrayList<>();
116                 definitions.add("/WEB-INF/defs/definitions.xml");
117                 return definitions;
118         }
119
120         /**
121          * Adds request interceptors to the specified registry by calling
122          * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
123          * certain paths from the session timeout interceptor.
124          */
125         @Override
126         public void addInterceptors(InterceptorRegistry registry) {
127                 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
128                                 "/api*", "/single_signon.htm", "/single_signon");
129                 super.addInterceptors(registry);
130         }
131
132         /**
133          * Creates and returns a new instance of a {@link CacheManager} class.
134          *
135          * @return New instance of {@link CacheManager}
136          */
137         @Bean
138         public AbstractCacheManager cacheManager() {
139                 return new CacheManager();
140         }
141
142         /**
143          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
144          * populates it with triggers.
145          *
146          * @return New instance of {@link SchedulerFactoryBean}
147          */
148         @Bean
149         @DependsOn("liquibaseBean")
150         public SchedulerFactoryBean schedulerFactoryBean() {
151                 SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
152                 schedulerFactory.setJobFactory(new SpringBeanJobFactory());
153                 return schedulerFactory;
154         }
155
156
157         @Bean
158         @Order(1)
159         public SpringLiquibase liquibaseBean(DataSource dataSource) {
160                 SpringLiquibase springLiquibase = new SpringLiquibase();
161                 springLiquibase.setDataSource(dataSource);
162                 springLiquibase.setChangeLog("classpath:db-master-changelog.xml");
163                 return springLiquibase;
164         }
165
166         @Bean
167         public LoginStrategy loginStrategy() {
168                 return new LoginStrategyImpl();
169         }
170
171         @Bean
172         public CommonsMultipartResolver multipartResolver() {
173                 CommonsMultipartResolver resolver=new CommonsMultipartResolver();
174                 resolver.setDefaultEncoding("utf-8");
175                 return resolver;
176         }
177
178 }