Introduced dynamic workflow properties in VID FE
[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 com.fasterxml.jackson.module.kotlin.KotlinModule;
26 import io.joshworks.restclient.http.mapper.ObjectMapper;
27 import org.onap.vid.aai.*;
28 import org.onap.vid.aai.model.PortDetailsTranslator;
29 import org.onap.vid.aai.util.*;
30 import org.onap.vid.asdc.AsdcClient;
31 import org.onap.vid.asdc.parser.ToscaParserImpl2;
32 import org.onap.vid.asdc.parser.VidNotionsBuilder;
33 import org.onap.vid.asdc.rest.SdcRestClient;
34 import org.onap.vid.client.SyncRestClient;
35 import org.onap.vid.client.SyncRestClientInterface;
36 import org.onap.vid.properties.AsdcClientConfiguration;
37 import org.onap.vid.scheduler.SchedulerService;
38 import org.onap.vid.scheduler.SchedulerServiceImpl;
39 import org.onap.vid.services.*;
40 import org.springframework.beans.factory.annotation.Qualifier;
41 import org.springframework.context.annotation.Bean;
42 import org.springframework.context.annotation.Configuration;
43 import org.togglz.core.manager.FeatureManager;
44
45 import javax.servlet.ServletContext;
46 import java.io.File;
47 import java.io.IOException;
48
49 @Configuration
50 public class WebConfig {
51
52     /**
53      * Gets the object mapper.
54      *
55      * @return the object mapper
56      */
57     @Bean
58     public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() {
59         return new com.fasterxml.jackson.databind.ObjectMapper().registerModule(new KotlinModule());
60     }
61
62
63     @Bean
64     public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
65         return new VidServiceImpl(asdcClient, featureManager);
66     }
67
68     @Bean
69     public SchedulerService schedulerService(ChangeManagementService changeManagementService) {
70         return new SchedulerServiceImpl(changeManagementService);
71     }
72
73     @Bean
74     public AaiService getAaiService(AaiClientInterface aaiClient, AaiOverTLSClientInterface aaiOverTLSClient,
75         AaiResponseTranslator aaiResponseTranslator, AAITreeNodeBuilder aaiTreeNode, AAIServiceTree aaiServiceTree) {
76         return new AaiServiceImpl(aaiClient, aaiOverTLSClient, aaiResponseTranslator, aaiTreeNode, aaiServiceTree);
77     }
78
79     @Bean
80     public AaiResponseTranslator aaiResponseTranslator() {
81         return new AaiResponseTranslator();
82     }
83
84     @Bean
85     public PortDetailsTranslator portDetailsTranslator() {
86         return new PortDetailsTranslator();
87     }
88
89     @Bean
90     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator, CacheProvider cacheProvider) {
91         return new AaiClient(restController, portsDetailsTranslator, cacheProvider);
92     }
93
94     @Bean(name = "aaiRestInterface")
95     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
96         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
97     }
98
99     @Bean
100     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
101         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
102     }
103
104     @Bean
105     public SSLContextProvider sslContextProvider() {
106         return new SSLContextProvider();
107     }
108
109     @Bean
110     public SystemPropertyHelper systemPropertyHelper() {
111         return new SystemPropertyHelper();
112     }
113
114     @Bean
115     public ServletRequestHelper servletRequestHelper() {
116         return new ServletRequestHelper();
117     }
118
119     @Bean
120     public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider ,FeatureManager featureManager) {
121         final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
122         return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider, featureManager);
123     }
124
125     @Bean
126     public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
127         String auth = asdcClientConfiguration.getAsdcClientAuth();
128         String host = asdcClientConfiguration.getAsdcClientHost();
129         String protocol = asdcClientConfiguration.getAsdcClientProtocol();
130         int port = asdcClientConfiguration.getAsdcClientPort();
131
132         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
133     }
134
135     @Bean
136     public SyncRestClientInterface syncRestClient() {
137         return new SyncRestClient();
138     }
139
140     @Bean
141     public VidNotionsBuilder vidNotionsBuilder(FeatureManager featureManager) {
142         return new VidNotionsBuilder(featureManager);
143     }
144
145     @Bean
146     public ToscaParserImpl2 getToscaParser(VidNotionsBuilder vidNotionsBuilder) {
147         return new ToscaParserImpl2(vidNotionsBuilder);
148     }
149
150     @Bean
151     public PombaService getVerifyServiceInstanceService() {
152         return new PombaServiceImpl();
153     }
154
155     @Bean
156     public PombaClientInterface getVerifyServiceInstanceClientInterface() {
157         return new PombaClientImpl();
158     }
159
160     @Bean
161     public ServiceInstanceStandardQuery serviceInstanceStandardQuery(AaiClientInterface aaiClient) {
162         return new ServiceInstanceStandardQuery(aaiClient);
163     }
164
165     @Bean
166     public AaiOverTLSClientInterface aaiOverTLSClient(ObjectMapper unirestObjectMapper){
167         return new AaiOverTLSClient(new SyncRestClient(unirestObjectMapper), new AaiOverTLSPropertySupplier());
168     }
169
170     @Bean
171     public ObjectMapper unirestFasterxmlObjectMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) {
172         return new ObjectMapper() {
173
174             @Override
175             public <T> T readValue(String s, Class<T> aClass) {
176                 try {
177                     return objectMapper.readValue(s, aClass);
178                 } catch (IOException e) {
179                     throw new RuntimeException(e);
180                 }
181             }
182
183             @Override
184             public String writeValue(Object o) {
185                 try {
186                     return objectMapper.writeValueAsString(o);
187                 } catch (JsonProcessingException e) {
188                     throw new RuntimeException(e);
189                 }
190             }
191         };
192
193     }
194
195 }