Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / java / org / openecomp / 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.openecomp.portalapp.conf;
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.openecomp.portalapp.scheduler.RegistryAdapter;
26 import org.openecomp.portalapp.uebhandler.InitUebHandler;
27 import org.openecomp.portalapp.uebhandler.MainUebHandler;
28 import org.openecomp.portalapp.uebhandler.WidgetNotificationHandler;
29 import org.openecomp.portalsdk.core.conf.AppConfig;
30 import org.openecomp.portalsdk.core.conf.Configurable;
31 import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
32 import org.openecomp.portalsdk.core.service.DataAccessService;
33 import org.openecomp.portalsdk.core.util.CacheManager;
34 import org.openecomp.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  * Configures Spring features in the ECOMP Portal SDK sample application.
52  * Subclasses the ECOMP Portal SDK core AppConfig class to reuse interceptors,
53  * view resolvers and other features defined there.
54  */
55 @Configuration
56 @EnableWebMvc
57 @ComponentScan(basePackages = "org.openecomp")
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         private RegistryAdapter schedulerRegistryAdapter;
65
66         @Configuration
67         @Import(SystemProperties.class)
68         static class InnerConfiguration {
69         }
70
71         /**
72          * @see org.openecomp.portalsdk.core.conf.AppConfig#viewResolver()
73          */
74         public ViewResolver viewResolver() {
75                 return super.viewResolver();
76         }
77
78         /**
79          * @see org.openecomp.portalsdk.core.conf.AppConfig#addResourceHandlers(ResourceHandlerRegistry)
80          * 
81          * @param registry
82          */
83         public void addResourceHandlers(ResourceHandlerRegistry registry) {
84                 super.addResourceHandlers(registry);
85         }
86
87         /**
88          * @see org.openecomp.portalsdk.core.conf.AppConfig#dataAccessService()
89          */
90         public DataAccessService dataAccessService() {
91                 return super.dataAccessService();
92         }
93
94         /**
95          * Creates a new list with a single entry that is the external app
96          * definitions.xml path.
97          * 
98          * @return List of String, size 1
99          */
100         public List<String> addTileDefinitions() {
101                 List<String> definitions = new ArrayList<String>();
102                 definitions.add("/WEB-INF/defs/definitions.xml");
103                 return definitions;
104         }
105
106         /**
107          * Adds request interceptors to the specified registry by calling
108          * {@link AppConfig#addInterceptors(InterceptorRegistry)}, but excludes
109          * certain paths from the session timeout interceptor.
110          */
111         @Override
112         public void addInterceptors(InterceptorRegistry registry) {
113                 super.setExcludeUrlPathsForSessionTimeout("/login_external", "*/login_external.htm", "login", "/login.htm",
114                                 "/api*","/single_signon.htm","/single_signon");
115                 super.addInterceptors(registry);
116         }
117
118         /**
119          * Creates and returns a new instance of a {@link CacheManager} class.
120          * 
121          * @return New instance of {@link CacheManager}
122          */
123         @Bean
124         public AbstractCacheManager cacheManager() {
125                 return new CacheManager();
126         }
127         
128         /**
129          * Creates and returns a new instance of a {@link MainUebHandler}. 
130          * 
131          * @return New instance of {@link MainUebHandler}.
132          */
133         @Bean
134         public MainUebHandler mainUebHandler() {
135                 
136                 return new MainUebHandler();
137         }
138         
139         /**
140          * Creates and returns a new instance of a {@link InitUebHandler}.  
141          * 
142          * @return New instance of {@link InitUebHandler}.
143          */
144         @Bean
145         public InitUebHandler initUebHandler() {
146                 
147                 return new InitUebHandler();
148         }
149
150         /**
151          * Creates and returns a new instance of a {@link WidgetNotificationHandler}
152          * .
153          * 
154          * @return New instance of {@link WidgetNotificationHandler}.
155          */
156         @Bean
157         public WidgetNotificationHandler widgetNotificationHandler() {
158                 return new WidgetNotificationHandler();
159         }
160         
161         /**
162          * Creates and returns a new instance of a {@link SchedulerFactoryBean} and
163          * populates it with triggers.
164          * 
165          * @return New instance of {@link SchedulerFactoryBean}
166          * @throws Exception 
167          */
168         // @Bean // ANNOTATION COMMENTED OUT 
169         // APPLICATIONS REQUIRING QUARTZ SHOULD RESTORE ANNOTATION
170         public SchedulerFactoryBean schedulerFactoryBean() throws Exception {
171                 SchedulerFactoryBean scheduler = new SchedulerFactoryBean();
172                 scheduler.setTriggers(schedulerRegistryAdapter.getTriggers());
173                 scheduler.setConfigLocation(appApplicationContext.getResource("WEB-INF/conf/quartz.properties"));
174                 scheduler.setDataSource(dataSource());
175                 return scheduler;
176         }
177
178         
179         /**
180          * Sets the scheduler registry adapter.
181          * 
182          * @param schedulerRegistryAdapter
183          */
184         @Autowired
185         public void setSchedulerRegistryAdapter(final RegistryAdapter schedulerRegistryAdapter) {
186                 this.schedulerRegistryAdapter = schedulerRegistryAdapter;
187         }
188 }