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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=======================================================================
19 package org.commscope.tr069adapter.mapper.ves;
21 import java.util.ArrayList;
22 import java.util.List;
24 import org.commscope.tr069adapter.acs.common.DeviceInform;
25 import org.commscope.tr069adapter.acs.common.DeviceRPCRequest;
26 import org.commscope.tr069adapter.acs.common.DeviceRPCResponse;
27 import org.commscope.tr069adapter.acs.common.ParameterDTO;
28 import org.commscope.tr069adapter.mapper.MapperConfigProperties;
29 import org.commscope.tr069adapter.mapper.acs.impl.PnPPreProvisioningHandler;
30 import org.commscope.tr069adapter.mapper.model.NetConfServerDetails;
31 import org.commscope.tr069adapter.mapper.model.VESNotification;
32 import org.commscope.tr069adapter.mapper.model.VESNotificationResponse;
33 import org.commscope.tr069adapter.mapper.util.MOMetaDataUtil;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.stereotype.Component;
38 import org.springframework.web.client.RestTemplate;
41 public class VESNotificationSender {
43 private static final Logger LOG = LoggerFactory.getLogger(VESNotificationSender.class);
46 MapperConfigProperties config;
49 PnPPreProvisioningHandler pnpPreProvisioningHandler;
52 VESNotificationSender vesnotiSender;
55 RestTemplate restTemplate;
58 MOMetaDataUtil metaDataUtil;
60 public VESNotificationResponse sendNotification(DeviceInform deviceInform,
61 NetConfServerDetails serverInfo) {
62 final String uri = getUri();
63 LOG.debug("Posting ves event to ves notifier {}", uri);
65 VESNotification vesNotifi = new VESNotification();
66 if (deviceInform != null) {
67 // Replace TR-069 parameter names with NETCONF parameter names
68 List<ParameterDTO> parameters = deviceInform.getParameters();
69 if (parameters != null && !parameters.isEmpty()) {
70 List<ParameterDTO> netconfParameters = new ArrayList<>();
71 for (ParameterDTO param : parameters) {
72 String paramXPath = metaDataUtil.getNetconfXPathNameByTR69NameWithIndexes(
73 param.getParamName(), deviceInform.getDeviceDetails().getSoftwareVersion(),
74 deviceInform.getDeviceDetails().getHardwareVersion());
75 if (paramXPath != null)
77 .add(new ParameterDTO(paramXPath, param.getParamValue(), param.getDataType()));
79 LOG.warn("Skipping param {}, as it is not present in mapping configuration",
80 param.getParamName());
83 vesNotifi.setNetconfParameters(netconfParameters);
85 vesNotifi.seteNodeBName(
86 pnpPreProvisioningHandler.getEnodeBName(deviceInform.getDeviceDetails().getDeviceId(),
87 deviceInform.getDeviceDetails().getSoftwareVersion(),
88 deviceInform.getDeviceDetails().getHardwareVersion()));
90 vesNotifi.seteNodeBName(serverInfo.getEnodeBName());
92 vesNotifi.setNetconfDetails(serverInfo);
93 vesNotifi.setDevnotification(deviceInform);
95 return restTemplate.postForObject(uri, vesNotifi, VESNotificationResponse.class);
98 public DeviceRPCResponse sendEditConfigNotification(DeviceRPCRequest deviceRPCRequest) {
99 final String uri = config.getVerConfigUri() + "/editConfig";
100 LOG.debug("Posting edit config request to ves agent {}", uri);
101 return restTemplate.postForObject(uri, deviceRPCRequest, DeviceRPCResponse.class);
104 public DeviceRPCResponse sendGetConfigNotification(DeviceRPCRequest deviceRPCRequest) {
105 final String uri = config.getVerConfigUri() + "/getConfig";
106 LOG.debug("Posting get config request to ves agent {}", uri);
107 return restTemplate.postForObject(uri, deviceRPCRequest, DeviceRPCResponse.class);
111 private String getUri() {
112 return config.getVesUri();