2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.vid.controller;
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;
52 import javax.servlet.ServletContext;
54 import java.io.IOException;
58 public class WebConfig {
61 * Gets the object mapper.
63 * @return the object mapper
66 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
67 return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
72 public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
73 return new SchedulerServiceImpl(changeManagementService);
77 public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
78 AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
79 return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
83 public AaiResponseTranslator aaiResponseTranslator() {
84 return new AaiResponseTranslator();
88 public PortDetailsTranslator portDetailsTranslator() {
89 return new PortDetailsTranslator();
93 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
94 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
97 @Bean(name = "aaiRestInterface")
98 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
99 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
103 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
104 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
108 public SSLContextProvider sslContextProvider() {
109 return new SSLContextProvider();
113 public SystemPropertyHelper systemPropertyHelper() {
114 return new SystemPropertyHelper();
118 public ServletRequestHelper servletRequestHelper() {
119 return new ServletRequestHelper();
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);
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();
135 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
139 public SyncRestClientInterface syncRestClient() {
140 return new SyncRestClient();
144 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
145 return new VidNotionsBuilder(featureManager);
149 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
150 return new ToscaParserImpl2(vidNotionsBuilder);
154 public PombaService getVerifyServiceInstanceService() {
155 return new PombaServiceImpl();
159 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
160 return new PombaClientImpl();
164 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
165 return new ServiceInstanceStandardQuery(aaiClient);
169 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
170 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
174 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
175 return new ObjectMapper() {
178 public <T> T readValue(String s, Class<T> aClass) {
180 return objectMapper.readValue(s, aClass);
181 } catch (IOException e) {
182 throw new RuntimeException(e);
187 public String writeValue(Object o) {
189 return objectMapper.writeValueAsString(o);
190 } catch (JsonProcessingException e) {
191 throw new RuntimeException(e);
200 return new Docket(DocumentationType.SWAGGER_2)
202 .apis(RequestHandlerSelectors.basePackage("org.onap.vid.controller.open"))
203 .paths(PathSelectors.any())