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