22bbef9c013c52f2d21fa8164c33a1e323f22611
[so.git] / adapters / etsi-sol003-adapter / etsi-sol003-pkgm / etsi-sol003-pkgm-adapter / src / main / java / org / onap / so / adapters / etsisol003adapter / pkgm / extclients / vnfm / VnfmHttpServiceProviderConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Ericsson. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm;
21
22 import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
23 import java.time.LocalDateTime;
24 import java.time.OffsetDateTime;
25 import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration;
26 import org.onap.so.adapters.etsisol003adapter.pkgm.JSON;
27 import org.onap.so.adapters.etsisol003adapter.pkgm.rest.EtsiSubscriptionNotificationController;
28 import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
29 import org.onap.so.rest.service.HttpRestServiceProvider;
30 import org.onap.so.rest.service.HttpRestServiceProviderImpl;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Qualifier;
33 import org.springframework.context.annotation.Bean;
34 import org.springframework.context.annotation.Configuration;
35 import org.springframework.web.client.RestTemplate;
36 import com.google.gson.Gson;
37
38 /**
39  * @author Waqas Ikram (waqas.ikram@est.tech)
40  *
41  */
42 @Configuration
43 public class VnfmHttpServiceProviderConfiguration extends AbstractServiceProviderConfiguration {
44     private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter();
45
46     public static final String VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN = "vnfmAdapterHttpServiceProvider";
47
48     @Bean
49     @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN)
50     public HttpRestServiceProvider vnfmAdapterHttpRestServiceProvider(
51             @Autowired @Qualifier(CONFIGURABLE_REST_TEMPLATE) RestTemplate restTemplate) {
52         setGsonMessageConverter(restTemplate);
53         return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders());
54     }
55
56     @Override
57     protected Gson getGson() {
58         return JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
59                 .registerTypeAdapter(LocalDateTime.class,
60                         new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter())
61                 .create();
62     }
63
64 }