Merge "aaiSubscriberController Test"
[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 VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
73         return new VidServiceImpl(asdcClient, featureManager);
74     }
75
76     @Bean
77     public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
78         return new SchedulerServiceImpl(changeManagementService);
79     }
80
81     @Bean
82     public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
83         AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
84         return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
85     }
86
87     @Bean
88     public AaiResponseTranslator aaiResponseTranslator() {
89         return new AaiResponseTranslator();
90     }
91
92     @Bean
93     public PortDetailsTranslator portDetailsTranslator() {
94         return new PortDetailsTranslator();
95     }
96
97     @Bean
98     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
99         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
100     }
101
102     @Bean(name = "aaiRestInterface")
103     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
104         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
105     }
106
107     @Bean
108     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
109         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
110     }
111
112     @Bean
113     public SSLContextProvider sslContextProvider() {
114         return new SSLContextProvider();
115     }
116
117     @Bean
118     public SystemPropertyHelper systemPropertyHelper() {
119         return new SystemPropertyHelper();
120     }
121
122     @Bean
123     public ServletRequestHelper servletRequestHelper() {
124         return new ServletRequestHelper();
125     }
126
127     @Bean
128     public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
129         final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
130         return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
131     }
132
133     @Bean
134     public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
135         String auth = asdcClientConfiguration.getAsdcClientAuth();
136         String host = asdcClientConfiguration.getAsdcClientHost();
137         String protocol = asdcClientConfiguration.getAsdcClientProtocol();
138         int port = asdcClientConfiguration.getAsdcClientPort();
139
140         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
141     }
142
143     @Bean
144     public SyncRestClientInterface syncRestClient() {
145         return new SyncRestClient();
146     }
147
148     @Bean
149     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
150         return new VidNotionsBuilder(featureManager);
151     }
152
153     @Bean
154     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
155         return new ToscaParserImpl2(vidNotionsBuilder);
156     }
157
158     @Bean
159     public PombaService getVerifyServiceInstanceService() {
160         return new PombaServiceImpl();
161     }
162
163     @Bean
164     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
165         return new PombaClientImpl();
166     }
167
168     @Bean
169     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
170         return new ServiceInstanceStandardQuery(aaiClient);
171     }
172
173     @Bean
174     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
175         return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
176     }
177
178     @Bean
179     public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
180         return new ObjectMapper() {
181
182             @Override
183             public <T> T readValue(String s, Class<T> aClass) {
184                 try {
185                     return objectMapper.readValue(s, aClass);
186                 } catch (IOException e) {
187                     throw new RuntimeException(e);
188                 }
189             }
190
191             @Override
192             public String writeValue(Object o) {
193                 try {
194                     return objectMapper.writeValueAsString(o);
195                 } catch (JsonProcessingException e) {
196                     throw new RuntimeException(e);
197                 }
198             }
199         };
200
201     }
202
203     @Bean
204     public Docket api(){
205         return new Docket(DocumentationType.SWAGGER_2)
206                 .select()
207                 .apis(RequestHandlerSelectors.basePackage("org.onap.vid.controller.open"))
208                 .paths(PathSelectors.any())
209                 .build();
210     }
211 }