Sending workflow data from UI to SO
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controller / WebConfig.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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=========================================================
20  */
21
22 package org.onap.vid.controller;
23
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;
45
46 import javax.servlet.ServletContext;
47 import java.io.File;
48 import java.io.IOException;
49
50 @Configuration
51 public class WebConfig {
52
53     /**
54      * Gets the object mapper.
55      *
56      * @return the object mapper
57      */
58     @Bean
59     public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
60         return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
61     }
62
63
64     @Bean
65     public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
66         return new VidServiceImpl(asdcClient, featureManager);
67     }
68
69     @Bean
70     public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
71         return new SchedulerServiceImpl(changeManagementService);
72     }
73
74     @Bean
75     public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
76         AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
77         return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
78     }
79
80     @Bean
81     public AaiResponseTranslator aaiResponseTranslator() {
82         return new AaiResponseTranslator();
83     }
84
85     @Bean
86     public PortDetailsTranslator portDetailsTranslator() {
87         return new PortDetailsTranslator();
88     }
89
90     @Bean
91     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
92         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
93     }
94
95     @Bean(name = "aaiRestInterface")
96     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
97         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
98     }
99
100     @Bean
101     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
102         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
103     }
104
105     @Bean
106     public SSLContextProvider sslContextProvider() {
107         return new SSLContextProvider();
108     }
109
110     @Bean
111     public SystemPropertyHelper systemPropertyHelper() {
112         return new SystemPropertyHelper();
113     }
114
115     @Bean
116     public ServletRequestHelper servletRequestHelper() {
117         return new ServletRequestHelper();
118     }
119
120     @Bean
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);
124     }
125
126     @Bean
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();
132
133         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
134     }
135
136     @Bean
137     public SyncRestClientInterface syncRestClient() {
138         return new SyncRestClient();
139     }
140
141     @Bean
142     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
143         return new VidNotionsBuilder(featureManager);
144     }
145
146     @Bean
147     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
148         return new ToscaParserImpl2(vidNotionsBuilder);
149     }
150
151     @Bean
152     public PombaService getVerifyServiceInstanceService() {
153         return new PombaServiceImpl();
154     }
155
156     @Bean
157     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
158         return new PombaClientImpl();
159     }
160
161     @Bean
162     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
163         return new ServiceInstanceStandardQuery(aaiClient);
164     }
165
166     @Bean
167     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper, SystemProperties systemProperties){
168         return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
169     }
170
171     @Bean
172     public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
173         return new ObjectMapper() {
174
175             @Override
176             public <T> T readValue(String s, Class<T> aClass) {
177                 try {
178                     return objectMapper.readValue(s, aClass);
179                 } catch (IOException e) {
180                     throw new RuntimeException(e);
181                 }
182             }
183
184             @Override
185             public String writeValue(Object o) {
186                 try {
187                     return objectMapper.writeValueAsString(o);
188                 } catch (JsonProcessingException e) {
189                     throw new RuntimeException(e);
190                 }
191             }
192         };
193
194     }
195
196 }