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