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;
46 import javax.servlet.ServletContext;
48 import java.io.IOException;
51 public class WebConfig {
54 * Gets the object mapper.
56 * @return the object mapper
59 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
60 return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
65 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
66 return new VidServiceImpl(asdcClient, featureManager);
70 public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
71 return new SchedulerServiceImpl(changeManagementService);
75 public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
76 AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
77 return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
81 public AaiResponseTranslator aaiResponseTranslator() {
82 return new AaiResponseTranslator();
86 public PortDetailsTranslator portDetailsTranslator() {
87 return new PortDetailsTranslator();
91 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
92 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
95 @Bean(name = "aaiRestInterface")
96 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
97 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
101 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
102 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
106 public SSLContextProvider sslContextProvider() {
107 return new SSLContextProvider();
111 public SystemPropertyHelper systemPropertyHelper() {
112 return new SystemPropertyHelper();
116 public ServletRequestHelper servletRequestHelper() {
117 return new ServletRequestHelper();
121 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
122 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
123 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
127 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
128 String auth = asdcClientConfiguration.getAsdcClientAuth();
129 String host = asdcClientConfiguration.getAsdcClientHost();
130 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
131 int port = asdcClientConfiguration.getAsdcClientPort();
133 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
137 public SyncRestClientInterface syncRestClient() {
138 return new SyncRestClient();
142 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
143 return new VidNotionsBuilder(featureManager);
147 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
148 return new ToscaParserImpl2(vidNotionsBuilder);
152 public PombaService getVerifyServiceInstanceService() {
153 return new PombaServiceImpl();
157 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
158 return new PombaClientImpl();
162 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
163 return new ServiceInstanceStandardQuery(aaiClient);
167 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
168 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
172 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
173 return new ObjectMapper() {
176 public <T> T readValue(String s, Class<T> aClass) {
178 return objectMapper.readValue(s, aClass);
179 } catch (IOException e) {
180 throw new RuntimeException(e);
185 public String writeValue(Object o) {
187 return objectMapper.writeValueAsString(o);
188 } catch (JsonProcessingException e) {
189 throw new RuntimeException(e);