8fe7c1fa15ed4f6a8754318e3cf46b90b3af21e6
[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(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
74         AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
75         return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
76     }
77
78     @Bean
79     public AaiResponseTranslator aaiResponseTranslator() {
80         return new AaiResponseTranslator();
81     }
82
83     @Bean
84     public PortDetailsTranslator portDetailsTranslator() {
85         return new PortDetailsTranslator();
86     }
87
88     @Bean
89     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
90         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
91     }
92
93     @Bean(name = "aaiRestInterface")
94     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
95         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
96     }
97
98     @Bean
99     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
100         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
101     }
102
103     @Bean
104     public SSLContextProvider sslContextProvider() {
105         return new SSLContextProvider();
106     }
107
108     @Bean
109     public SystemPropertyHelper systemPropertyHelper() {
110         return new SystemPropertyHelper();
111     }
112
113     @Bean
114     public ServletRequestHelper servletRequestHelper() {
115         return new ServletRequestHelper();
116     }
117
118     @Bean
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);
122     }
123
124     @Bean
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();
130
131         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
132     }
133
134     @Bean
135     public SyncRestClientInterface syncRestClient() {
136         return new SyncRestClient();
137     }
138
139     @Bean
140     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
141         return new VidNotionsBuilder(featureManager);
142     }
143
144     @Bean
145     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
146         return new ToscaParserImpl2(vidNotionsBuilder);
147     }
148
149     @Bean
150     public PombaService getVerifyServiceInstanceService() {
151         return new PombaServiceImpl();
152     }
153
154     @Bean
155     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
156         return new PombaClientImpl();
157     }
158
159     @Bean
160     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
161         return new ServiceInstanceStandardQuery(aaiClient);
162     }
163
164     @Bean
165     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){
166         return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
167     }
168
169     @Bean
170     public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
171         return new ObjectMapper() {
172
173             @Override
174             public <T> T readValue(String s, Class<T> aClass) {
175                 try {
176                     return objectMapper.readValue(s, aClass);
177                 } catch (IOException e) {
178                     throw new RuntimeException(e);
179                 }
180             }
181
182             @Override
183             public String writeValue(Object o) {
184                 try {
185                     return objectMapper.writeValueAsString(o);
186                 } catch (JsonProcessingException e) {
187                     throw new RuntimeException(e);
188                 }
189             }
190         };
191
192     }
193
194 }