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 static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
26 import static org.apache.commons.lang3.StringUtils.isEmpty;
28 import com.fasterxml.jackson.core.JsonProcessingException;
29 import com.fasterxml.jackson.module.kotlin.KotlinModule;
30 import io.joshworks.restclient.http.mapper.ObjectMapper;
32 import java.io.IOException;
33 import javax.servlet.ServletContext;
34 import java.util.concurrent.Executors;
35 import org.onap.portalsdk.core.util.SystemProperties;
36 import org.onap.vid.aai.AaiClient;
37 import org.onap.vid.aai.AaiClientInterface;
38 import org.onap.vid.aai.AaiOverTLSClient;
39 import org.onap.vid.aai.AaiOverTLSClientInterface;
40 import org.onap.vid.aai.AaiOverTLSPropertySupplier;
41 import org.onap.vid.aai.AaiResponseTranslator;
42 import org.onap.vid.aai.PombaClientImpl;
43 import org.onap.vid.aai.PombaClientInterface;
44 import org.onap.vid.aai.PombaRestInterface;
45 import org.onap.vid.aai.model.PortDetailsTranslator;
46 import org.onap.vid.aai.util.AAIRestInterface;
47 import org.onap.vid.aai.util.CacheProvider;
48 import org.onap.vid.aai.util.HttpsAuthClient;
49 import org.onap.vid.aai.util.SSLContextProvider;
50 import org.onap.vid.aai.util.ServiceInstanceStandardQuery;
51 import org.onap.vid.aai.util.ServletRequestHelper;
52 import org.onap.vid.aai.util.SystemPropertyHelper;
53 import org.onap.vid.asdc.AsdcClient;
54 import org.onap.vid.asdc.parser.ToscaParserImpl2;
55 import org.onap.vid.asdc.parser.VidNotionsBuilder;
56 import org.onap.vid.asdc.rest.SdcRestClient;
57 import org.onap.vid.client.SyncRestClient;
58 import org.onap.vid.client.SyncRestClientInterface;
59 import org.onap.vid.properties.AsdcClientConfiguration;
60 import org.onap.vid.properties.VidProperties;
61 import org.onap.vid.scheduler.SchedulerService;
62 import org.onap.vid.scheduler.SchedulerServiceImpl;
63 import org.onap.vid.services.AAIServiceTree;
64 import org.onap.vid.services.AAITreeNodeBuilder;
65 import org.onap.vid.services.AaiService;
66 import org.onap.vid.services.AaiServiceImpl;
67 import org.onap.vid.services.ChangeManagementService;
68 import org.onap.vid.services.PombaService;
69 import org.onap.vid.services.PombaServiceImpl;
70 import org.springframework.beans.factory.annotation.Qualifier;
71 import org.springframework.context.annotation.Bean;
72 import org.springframework.context.annotation.Configuration;
73 import org.togglz.core.manager.FeatureManager;
74 import springfox.documentation.builders.PathSelectors;
75 import springfox.documentation.builders.RequestHandlerSelectors;
76 import springfox.documentation.spi.DocumentationType;
77 import springfox.documentation.spring.web.plugins.Docket;
78 import springfox.documentation.swagger2.annotations.EnableSwagger2;
81 import javax.servlet.ServletContext;
83 import java.io.IOException;
84 import java.util.concurrent.ExecutorService;
88 public class WebConfig {
91 * Gets the object mapper.
93 * @return the object mapper
96 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
97 return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
102 public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
103 return new SchedulerServiceImpl(changeManagementService);
107 public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
108 AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree, ExecutorService executorService) {
109 return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree, executorService);
113 public AaiResponseTranslator aaiResponseTranslator() {
114 return new AaiResponseTranslator();
118 public PortDetailsTranslator portDetailsTranslator() {
119 return new PortDetailsTranslator();
123 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
124 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
127 @Bean(name = "aaiRestInterface")
128 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
129 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
133 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
134 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
138 public SSLContextProvider sslContextProvider() {
139 return new SSLContextProvider();
143 public SystemPropertyHelper systemPropertyHelper() {
144 return new SystemPropertyHelper();
148 public ServletRequestHelper servletRequestHelper() {
149 return new ServletRequestHelper();
153 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
154 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
155 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
159 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
160 String auth = asdcClientConfiguration.getAsdcClientAuth();
161 String host = asdcClientConfiguration.getAsdcClientHost();
162 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
163 int port = asdcClientConfiguration.getAsdcClientPort();
165 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
169 public SyncRestClientInterface syncRestClient() {
170 return new SyncRestClient();
174 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
175 return new VidNotionsBuilder(featureManager);
179 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
180 return new ToscaParserImpl2(vidNotionsBuilder);
184 public PombaService getVerifyServiceInstanceService() {
185 return new PombaServiceImpl();
189 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
190 return new PombaClientImpl();
194 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
195 return new ServiceInstanceStandardQuery(aaiClient);
199 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
200 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
204 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
205 return new ObjectMapper() {
208 public <T> T readValue(String s, Class<T> aClass) {
210 return isEmpty(s) ? null : objectMapper.readValue(s, aClass);
211 } catch (IOException e) {
212 throw new RuntimeException(e);
217 public String writeValue(Object o) {
219 return objectMapper.writeValueAsString(o);
220 } catch (JsonProcessingException e) {
221 throw new RuntimeException(e);
230 return new Docket(DocumentationType.SWAGGER_2)
232 .apis(RequestHandlerSelectors.basePackage("org.onap.vid.controller.open"))
233 .paths(PathSelectors.any())
238 public ExecutorService executorService() {
239 int threadsCount = defaultIfNull(Integer.parseInt(SystemProperties.getProperty(VidProperties.VID_THREAD_COUNT)), 1);
240 return Executors.newFixedThreadPool(threadsCount);