20601724ce30497bbc34e0fc92ce68202bec3a0a
[policy/engine.git] / ONAP-SDK-APP / src / main / java / org / onap / portalapp / conf / ExternalAppConfig.java
1 /*-
2  * ================================================================================
3  * ONAP 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
25 import org.onap.portalapp.login.LoginStrategyImpl;
26 import org.onap.portalapp.scheduler.RegistryAdapter;
27 import org.onap.portalsdk.core.auth.LoginStrategy;
28 import org.onap.portalsdk.core.conf.AppConfig;
29 import org.onap.portalsdk.core.conf.Configurable;
30 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
31 import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
32 import org.onap.portalsdk.core.service.DataAccessService;
33 import org.onap.portalsdk.core.util.CacheManager;
34 import org.onap.portalsdk.core.util.SystemProperties;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.context.annotation.Bean;
37 import org.springframework.context.annotation.ComponentScan;
38 import org.springframework.context.annotation.Configuration;
39 import org.springframework.context.annotation.Import;
40 import org.springframework.context.annotation.Profile;
41 import org.springframework.context.annotation.PropertySource;
42 import org.springframework.scheduling.annotation.EnableAsync;
43 import org.springframework.scheduling.annotation.EnableScheduling;
44 import org.springframework.scheduling.quartz.SchedulerFactoryBean;
45 import org.springframework.web.servlet.ViewResolver;
46 import org.springframework.web.servlet.config.annotation.EnableWebMvc;
47 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
48 import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
49
50 /**
51  * ONAP Portal SDK sample application. Extends core AppConfig class to
52  * reuse interceptors, view resolvers and other features defined there.
53  */
54 @Configuration
55 @EnableWebMvc
56 @ComponentScan(basePackages = "org.onap")
57 @PropertySource(value = { "${container.classpath:}/WEB-INF/conf/app/test.properties" }, ignoreResourceNotFound = true)
58 @Profile("src")
59 @EnableAsync
60 @EnableScheduling
61 public class ExternalAppConfig extends AppConfig implements Configurable {
62
63         EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ExternalAppConfig.class);
64         
65         private RegistryAdapter schedulerRegistryAdapter;
66
67         @Configuration
68         @Import(SystemProperties.class)
69         static class InnerConfiguration {
70         }
71
72         /**
73          * @see org.onap.portalsdk.core.conf.AppConfig#viewResolver()
74          */
75         @Override
76         public ViewResolver viewResolver() {
77                 return super.viewResolver();
78         }
79
80         /**
81          * @see org.onap.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
82          * 
83          * @param registry
84          */
85         @Override
86         public void addResourceHandlers(ResourceHandlerRegistry registry) {
87                 super.addResourceHandlers(registry);
88         }
89
90         /**
91          * @see org.onap.portalsdk.core.conf.AppConfig#dataAccessService()
92          */
93         @Override
94         public DataAccessService dataAccessService() {
95                 // Echo the JDBC URL to assist developers when starting the app.
96                 System.out.println("ExternalAppConfig: " + SystemProperties.DB_CONNECTIONURL + " is "
97                                 + SystemProperties.getProperty(SystemProperties.DB_CONNECTIONURL));
98                 return super.dataAccessService();
99         }
100
101         /**
102          * Creates a new list with a single entry that is the external app
103          * definitions.xml path.
104          * 
105          * @return List of String, size 1
106          */
107         @Override
108         public List<String> addTileDefinitions() {
109                 List<String> definitions = new ArrayList<>();
110                 definitions.add("/WEB-INF/defs/definitions.xml");
111                 return definitions;
112         }
113
114         /**
115          * Adds request interceptors to the specified registry by calling
116          * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
117          * certain paths from the session timeout interceptor.
118          */
119         @Override
120         public void addInterceptors(InterceptorRegistry registry) {
121                 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
122                                 "/api*", "/single_signon.htm", "/single_signon");
123                 super.addInterceptors(registry);
124         }
125
126         /**
127          * Creates and returns a new instance of a {@link CacheManager} class.
128          * 
129          * @return New instance of {@link CacheManager}
130          */
131         @Bean
132         public AbstractCacheManager cacheManager() {
133                 return new CacheManager();
134         }
135
136         /**
137          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
138          * populates it with triggers.
139          * 
140          * @return New instance of {@link SchedulerFactoryBean}
141          * @throws Exception
142          */
143         // @Bean // ANNOTATION COMMENTED OUT
144         // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
145         public SchedulerFactoryBean schedulerFactoryBean(){
146                 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
147                 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
148                 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
149                 try {
150                         scheduler.setDataSource(dataSource());
151                 } catch (Exception e) {
152                         logger.error("Exception occured While Setting DataSource for schedulerfactorybean"+e);
153                         return null;
154                 }
155                 return scheduler;
156         }
157
158         /**
159          * Sets the scheduler registry adapter.
160          * 
161          * @param schedulerRegistryAdapter
162          */
163         @Autowired
164         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
165                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
166         }
167
168         @Bean
169         public LoginStrategy loginStrategy() {
170                 return new LoginStrategyImpl();
171         }
172 }