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(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
74 AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
75 return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
79 public AaiResponseTranslator aaiResponseTranslator() {
80 return new AaiResponseTranslator();
84 public PortDetailsTranslator portDetailsTranslator() {
85 return new PortDetailsTranslator();
89 public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
90 return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
93 @Bean(name = "aaiRestInterface")
94 public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
95 return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
99 public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
100 return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
104 public SSLContextProvider sslContextProvider() {
105 return new SSLContextProvider();
109 public SystemPropertyHelper systemPropertyHelper() {
110 return new SystemPropertyHelper();
114 public ServletRequestHelper servletRequestHelper() {
115 return new ServletRequestHelper();
119 public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
120 final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
121 return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
125 public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
126 String auth = asdcClientConfiguration.getAsdcClientAuth();
127 String host = asdcClientConfiguration.getAsdcClientHost();
128 String protocol = asdcClientConfiguration.getAsdcClientProtocol();
129 int port = asdcClientConfiguration.getAsdcClientPort();
131 return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
135 public SyncRestClientInterface syncRestClient() {
136 return new SyncRestClient();
140 public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
141 return new VidNotionsBuilder(featureManager);
145 public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
146 return new ToscaParserImpl2(vidNotionsBuilder);
150 public PombaService getVerifyServiceInstanceService() {
151 return new PombaServiceImpl();
155 public PombaClientInterface getVerifyServiceInstanceClientInterface() {
156 return new PombaClientImpl();
160 public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
161 return new ServiceInstanceStandardQuery(aaiClient);
165 public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){
166 return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
170 public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
171 return new ObjectMapper() {
174 public <T> T readValue(String s, Class<T> aClass) {
176 return objectMapper.readValue(s, aClass);
177 } catch (IOException e) {
178 throw new RuntimeException(e);
183 public String writeValue(Object o) {
185 return objectMapper.writeValueAsString(o);
186 } catch (JsonProcessingException e) {
187 throw new RuntimeException(e);