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