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 io.joshworks.restclient.http.mapper.ObjectMapper;
26 import org.onap.vid.aai.*;
27 import org.onap.vid.aai.model.PortDetailsTranslator;
28 import org.onap.vid.aai.util.*;
29 import org.onap.vid.asdc.AsdcClient;
30 import org.onap.vid.asdc.parser.ToscaParserImpl2;
31 import org.onap.vid.asdc.parser.VidNotionsBuilder;
32 import org.onap.vid.asdc.rest.SdcRestClient;
33 import org.onap.vid.client.SyncRestClient;
34 import org.onap.vid.client.SyncRestClientInterface;
35 import org.onap.vid.properties.AsdcClientConfiguration;
36 import org.onap.vid.scheduler.SchedulerService;
37 import org.onap.vid.scheduler.SchedulerServiceImpl;
38 import org.onap.vid.services.*;
39 import org.springframework.beans.factory.annotation.Qualifier;
40 import org.springframework.context.annotation.Bean;
41 import org.springframework.context.annotation.Configuration;
42 import org.togglz.core.manager.FeatureManager;
44 import javax.servlet.ServletContext;
46 import java.io.IOException;
49 public class WebConfig {
52 * Gets the object mapper.
54 * @return the object mapper
57 public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
58 return new com.fasterxml.jackson.databind.ObjectMapper();
63 public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
64 return new VidServiceImpl(asdcClient, featureManager);
68 public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
69 return new SchedulerServiceImpl(changeManagementService);
73 public AaiService getAaiService() {
74 return new AaiServiceImpl();
78 public AaiResponseTranslator aaiResponseTranslator() {
79 return new AaiResponseTranslator();
83 public PortDetailsTranslator portDetailsTranslator() {
84 return new PortDetailsTranslator();
88 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
89 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
92 @Bean(name = "aaiRestInterface")
93 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
94 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
98 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
99 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
103 public SSLContextProvider sslContextProvider() {
104 return new SSLContextProvider();
108 public SystemPropertyHelper systemPropertyHelper() {
109 return new SystemPropertyHelper();
113 public ServletRequestHelper servletRequestHelper() {
114 return new ServletRequestHelper();
118 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
119 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
120 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
124 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
125 String auth = asdcClientConfiguration.getAsdcClientAuth();
126 String host = asdcClientConfiguration.getAsdcClientHost();
127 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
128 int port = asdcClientConfiguration.getAsdcClientPort();
130 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
134 public SyncRestClientInterface syncRestClient() {
135 return new SyncRestClient();
139 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
140 return new VidNotionsBuilder(featureManager);
144 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
145 return new ToscaParserImpl2(vidNotionsBuilder);
149 public PombaService getVerifyServiceInstanceService() {
150 return new PombaServiceImpl();
154 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
155 return new PombaClientImpl();
159 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
160 return new ServiceInstanceStandardQuery(aaiClient);
164 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){
165 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
169 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
170 return new ObjectMapper() {
173 public <T> T readValue(String s, Class<T> aClass) {
175 return objectMapper.readValue(s, aClass);
176 } catch (IOException e) {
177 throw new RuntimeException(e);
182 public String writeValue(Object o) {
184 return objectMapper.writeValueAsString(o);
185 } catch (JsonProcessingException e) {
186 throw new RuntimeException(e);