2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2018 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.vid.aai.*;
28 import org.onap.vid.aai.model.PortDetailsTranslator;
29 import org.onap.vid.aai.util.*;
30 import org.onap.vid.asdc.AsdcClient;
31 import org.onap.vid.asdc.parser.ToscaParserImpl2;
32 import org.onap.vid.asdc.parser.VidNotionsBuilder;
33 import org.onap.vid.asdc.rest.SdcRestClient;
34 import org.onap.vid.client.SyncRestClient;
35 import org.onap.vid.client.SyncRestClientInterface;
36 import org.onap.vid.properties.AsdcClientConfiguration;
37 import org.onap.vid.scheduler.SchedulerService;
38 import org.onap.vid.scheduler.SchedulerServiceImpl;
39 import org.onap.vid.services.*;
40 import org.springframework.beans.factory.annotation.Qualifier;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.togglz.core.manager.FeatureManager;
45 import javax.servlet.ServletContext;
47 import java.io.IOException;
50 public class WebConfig {
53 * Gets the object mapper.
55 * @return the object mapper
58 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
59 return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
64 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
65 return new VidServiceImpl(asdcClient, featureManager);
69 public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
70 return new SchedulerServiceImpl(changeManagementService);
74 public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
75 AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
76 return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
80 public AaiResponseTranslator aaiResponseTranslator() {
81 return new AaiResponseTranslator();
85 public PortDetailsTranslator portDetailsTranslator() {
86 return new PortDetailsTranslator();
90 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
91 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
94 @Bean(name = "aaiRestInterface")
95 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
96 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
100 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
101 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
105 public SSLContextProvider sslContextProvider() {
106 return new SSLContextProvider();
110 public SystemPropertyHelper systemPropertyHelper() {
111 return new SystemPropertyHelper();
115 public ServletRequestHelper servletRequestHelper() {
116 return new ServletRequestHelper();
120 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
121 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
122 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
126 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
127 String auth = asdcClientConfiguration.getAsdcClientAuth();
128 String host = asdcClientConfiguration.getAsdcClientHost();
129 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
130 int port = asdcClientConfiguration.getAsdcClientPort();
132 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
136 public SyncRestClientInterface syncRestClient() {
137 return new SyncRestClient();
141 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
142 return new VidNotionsBuilder(featureManager);
146 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
147 return new ToscaParserImpl2(vidNotionsBuilder);
151 public PombaService getVerifyServiceInstanceService() {
152 return new PombaServiceImpl();
156 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
157 return new PombaClientImpl();
161 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
162 return new ServiceInstanceStandardQuery(aaiClient);
166 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){
167 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
171 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
172 return new ObjectMapper() {
175 public <T> T readValue(String s, Class<T> aClass) {
177 return objectMapper.readValue(s, aClass);
178 } catch (IOException e) {
179 throw new RuntimeException(e);
184 public String writeValue(Object o) {
186 return objectMapper.writeValueAsString(o);
187 } catch (JsonProcessingException e) {
188 throw new RuntimeException(e);