0f4b536a19c7758c0fc0aaf0bc6710d7076487ec
[vid.git] / vid-app-common / src / main / java / org / onap / vid / controllers / 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.controllers;
23
24 import com.fasterxml.jackson.databind.ObjectMapper;
25 import org.onap.vid.aai.AaiClient;
26 import org.onap.vid.aai.AaiClientInterface;
27 import org.onap.vid.aai.AaiResponseTranslator;
28 import org.onap.vid.aai.PombaClientImpl;
29 import org.onap.vid.aai.PombaClientInterface;
30 import org.onap.vid.aai.PombaRestInterface;
31 import org.onap.vid.aai.model.PortDetailsTranslator;
32 import org.onap.vid.aai.util.AAIRestInterface;
33 import org.onap.vid.aai.util.HttpsAuthClient;
34 import org.onap.vid.aai.util.SSLContextProvider;
35 import org.onap.vid.aai.util.ServletRequestHelper;
36 import org.onap.vid.aai.util.SystemPropertyHelper;
37 import org.onap.vid.asdc.AsdcClient;
38 import org.onap.vid.asdc.parser.ToscaParserImpl2;
39 import org.onap.vid.asdc.rest.SdcRestClient;
40 import org.onap.vid.client.SyncRestClient;
41 import org.onap.vid.client.SyncRestClientInterface;
42 import org.onap.vid.properties.AsdcClientConfiguration;
43 import org.onap.vid.services.AaiService;
44 import org.onap.vid.services.AaiServiceImpl;
45 import org.onap.vid.services.PombaService;
46 import org.onap.vid.services.PombaServiceImpl;
47 import org.onap.vid.services.VidService;
48 import org.onap.vid.services.VidServiceImpl;
49 import org.onap.vid.scheduler.SchedulerRestInterface;
50 import org.onap.vid.scheduler.SchedulerRestInterfaceIfc;
51 import org.onap.vid.services.*;
52 import org.springframework.beans.factory.annotation.Qualifier;
53 import org.springframework.context.annotation.Bean;
54 import org.springframework.context.annotation.Configuration;
55 import org.togglz.core.manager.FeatureManager;
56
57 import javax.servlet.ServletContext;
58 import java.io.File;
59
60 @Configuration
61 public class WebConfig {
62
63     /**
64      * Gets the object mapper.
65      *
66      * @return the object mapper
67      */
68     @Bean
69     public ObjectMapper getObjectMapper() {
70         return new ObjectMapper();
71     }
72
73
74     @Bean
75     public VidService vidService(AsdcClient asdcClient, FeatureManager featureManager) {
76         return new VidServiceImpl(asdcClient, featureManager);
77     }
78
79     @Bean
80     public AaiService getAaiService() {
81         return new AaiServiceImpl();
82     }
83
84     @Bean
85     public AaiResponseTranslator aaiResponseTranslator() {
86         return new AaiResponseTranslator();
87     }
88
89     @Bean
90     public PortDetailsTranslator portDetailsTranslator() {
91         return new PortDetailsTranslator();
92     }
93
94     @Bean
95     public AaiClientInterface getAaiRestInterface(@Qualifier("aaiRestInterface") AAIRestInterface restController, PortDetailsTranslator portsDetailsTranslator) {
96         return new AaiClient(restController, portsDetailsTranslator);
97     }
98
99     @Bean(name = "aaiRestInterface")
100     public AAIRestInterface aaiRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
101         return new AAIRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
102     }
103
104     @Bean
105     public PombaRestInterface getPombaRestInterface(HttpsAuthClient httpsAuthClientFactory, ServletRequestHelper servletRequestHelper, SystemPropertyHelper systemPropertyHelper) {
106         return new PombaRestInterface(httpsAuthClientFactory, servletRequestHelper, systemPropertyHelper);
107     }
108
109     @Bean
110     public SSLContextProvider sslContextProvider() {
111         return new SSLContextProvider();
112     }
113
114     @Bean
115     public SystemPropertyHelper systemPropertyHelper() {
116         return new SystemPropertyHelper();
117     }
118
119     @Bean
120     public ServletRequestHelper servletRequestHelper() {
121         return new ServletRequestHelper();
122     }
123
124     @Bean
125     public HttpsAuthClient httpsAuthClientFactory(ServletContext servletContext, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) {
126         final String certFilePath = new File(servletContext.getRealPath("/WEB-INF/cert/")).getAbsolutePath();
127         return new HttpsAuthClient(certFilePath, systemPropertyHelper, sslContextProvider);
128     }
129
130     @Bean
131     public AsdcClient sdcClient(AsdcClientConfiguration asdcClientConfiguration, SyncRestClientInterface syncRestClient) {
132         String auth = asdcClientConfiguration.getAsdcClientAuth();
133         String host = asdcClientConfiguration.getAsdcClientHost();
134         String protocol = asdcClientConfiguration.getAsdcClientProtocol();
135         int port = asdcClientConfiguration.getAsdcClientPort();
136
137         return new SdcRestClient(protocol + "://" + host + ":" + port + "/", auth, syncRestClient);
138     }
139
140     @Bean
141     public SyncRestClientInterface syncRestClient() {
142         return new SyncRestClient();
143     }
144
145     @Bean
146     public ToscaParserImpl2 getToscaParser() {
147         return new ToscaParserImpl2();
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 SchedulerRestInterfaceIfc getSchedulerRestInterface(){
162         return new SchedulerRestInterface();
163     }
164 }