Merge "Extend probe mechanism"
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / WebConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2018 - 2019 Nokia. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.vid.controller;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.module.kotlin.KotlinModule;
26 import io.joshworks.restclient.http.mapper.ObjectMapper;
27 import org.onap.portalsdk.core.util.SystemProperties;
28 import org.onap.vid.aai.*;
29 import org.onap.vid.aai.model.PortDetailsTranslator;
30 import org.onap.vid.aai.util.*;
31 import org.onap.vid.asdc.AsdcClient;
32 import org.onap.vid.asdc.parser.ToscaParserImpl2;
33 import org.onap.vid.asdc.parser.VidNotionsBuilder;
34 import org.onap.vid.asdc.rest.SdcRestClient;
35 import org.onap.vid.client.SyncRestClient;
36 import org.onap.vid.client.SyncRestClientInterface;
37 import org.onap.vid.properties.AsdcClientConfiguration;
38 import org.onap.vid.scheduler.SchedulerService;
39 import org.onap.vid.scheduler.SchedulerServiceImpl;
40 import org.onap.vid.services.*;
41 import org.springframework.beans.factory.annotation.Qualifier;
42 import org.springframework.context.annotation.Bean;
43 import org.springframework.context.annotation.Configuration;
44 import org.togglz.core.manager.FeatureManager;
45 import springfox.documentation.builders.PathSelectors;
46 import springfox.documentation.builders.RequestHandlerSelectors;
47 import springfox.documentation.spi.DocumentationType;
48 import springfox.documentation.spring.web.plugins.Docket;
49 import springfox.documentation.swagger2.annotations.EnableSwagger2;
50
51
52 import javax.servlet.ServletContext;
53 import java.io.File;
54 import java.io.IOException;
55
56 @EnableSwagger2
57 @Configuration
58 public class WebConfig {
59
60     /**
61      * Gets the object mapper.
62      *
63      * @return the object mapper
64      */
65     @Bean
66     public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
67         return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
68     }
69
70
71     @Bean
72     public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
73         return new SchedulerServiceImpl(changeManagementService);
74     }
75
76     @Bean
77     public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
78         AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
79         return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
80     }
81
82     @Bean
83     public AaiResponseTranslator aaiResponseTranslator() {
84         return new AaiResponseTranslator();
85     }
86
87     @Bean
88     public PortDetailsTranslator portDetailsTranslator() {
89         return new PortDetailsTranslator();
90     }
91
92     @Bean
93     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
94         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
95     }
96
97     @Bean(name = "aaiRestInterface")
98     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
99         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
100     }
101
102     @Bean
103     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
104         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
105     }
106
107     @Bean
108     public SSLContextProvider sslContextProvider() {
109         return new SSLContextProvider();
110     }
111
112     @Bean
113     public SystemPropertyHelper systemPropertyHelper() {
114         return new SystemPropertyHelper();
115     }
116
117     @Bean
118     public ServletRequestHelper servletRequestHelper() {
119         return new ServletRequestHelper();
120     }
121
122     @Bean
123     public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
124         final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
125         return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
126     }
127
128     @Bean
129     public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
130         String auth = asdcClientConfiguration.getAsdcClientAuth();
131         String host = asdcClientConfiguration.getAsdcClientHost();
132         String protocol = asdcClientConfiguration.getAsdcClientProtocol();
133         int port = asdcClientConfiguration.getAsdcClientPort();
134
135         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
136     }
137
138     @Bean
139     public SyncRestClientInterface syncRestClient() {
140         return new SyncRestClient();
141     }
142
143     @Bean
144     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
145         return new VidNotionsBuilder(featureManager);
146     }
147
148     @Bean
149     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
150         return new ToscaParserImpl2(vidNotionsBuilder);
151     }
152
153     @Bean
154     public PombaService getVerifyServiceInstanceService() {
155         return new PombaServiceImpl();
156     }
157
158     @Bean
159     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
160         return new PombaClientImpl();
161     }
162
163     @Bean
164     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
165         return new ServiceInstanceStandardQuery(aaiClient);
166     }
167
168     @Bean
169     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
170         return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
171     }
172
173     @Bean
174     public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
175         return new ObjectMapper() {
176
177             @Override
178             public <T> T readValue(String s, Class<T> aClass) {
179                 try {
180                     return objectMapper.readValue(s, aClass);
181                 } catch (IOException e) {
182                     throw new RuntimeException(e);
183                 }
184             }
185
186             @Override
187             public String writeValue(Object o) {
188                 try {
189                     return objectMapper.writeValueAsString(o);
190                 } catch (JsonProcessingException e) {
191                     throw new RuntimeException(e);
192                 }
193             }
194         };
195
196     }
197
198     @Bean
199     public Docket api(){
200         return new Docket(DocumentationType.SWAGGER_2)
201                 .select()
202                 .apis(RequestHandlerSelectors.basePackage("org.onap.vid.controller.open"))
203                 .paths(PathSelectors.any())
204                 .build();
205     }
206 }