Development of NETCONF RPCs for tr-069 adapter to
[oam/tr069-adapter.git] / mapper / src / main / java / org / commscope / tr069adapter / mapper / acs / ACSRequestSender.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : tr-069-adapter
4  * =================================================================================================
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.
6  * =================================================================================================
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
9  * may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ===============LICENSE_END=======================================================================
17  */
18
19 package org.commscope.tr069adapter.mapper.acs;
20
21 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
22 import org.commscope.tr069adapter.acs.common.utils.ConnectionStatusPOJO;
23 import org.commscope.tr069adapter.mapper.MapperConfigProperties;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.http.HttpEntity;
26 import org.springframework.http.HttpHeaders;
27 import org.springframework.http.MediaType;
28 import org.springframework.stereotype.Component;
29 import org.springframework.web.client.RestTemplate;
30
31 @Component
32 public class ACSRequestSender {
33
34   private RestTemplate restTemplate = new RestTemplate();
35
36   @Autowired
37   MapperConfigProperties config;
38
39   public Long sendRequest(DeviceRPCRequest deviceRPCRequest) {
40     String uri = getUri();
41     return restTemplate.postForObject(uri, deviceRPCRequest, Long.class);
42   }
43
44   public ConnectionStatusPOJO sendConnectionStatusReq(String deviceId) {
45     HttpHeaders headers = new HttpHeaders();
46     headers.setContentType(MediaType.APPLICATION_JSON);
47     HttpEntity<String> entity = new HttpEntity<>(deviceId, headers);
48     return restTemplate.postForObject(getUriForConnStatus(), entity, ConnectionStatusPOJO.class);
49   }
50
51   private String getUri() {
52     return config.getSbiUri();
53   }
54
55   private String getUriForConnStatus() {
56     return config.getConnStatusUri();
57   }
58 }