2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt mountpoint-registrar
4 * =================================================================================================
5 * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.POST;
23 import java.util.HashMap;
24 import java.util.List;
27 public class CMNotificationClient extends MessageClient {
29 private static final String CM_NOTIFICATION_URI = "restconf/operations/devicemanager:push-cm-notification";
30 public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@",
31 OBJECT_ID = "@object-id@", NOTIFICATION_TYPE = "@notification-type@", SOURCE_INDICATOR = "@source-indicator@",
32 NOTIFICATION_ID = "@notification-id@", PATH = "@path@", OPERATION = "@operation@", VALUE = "@value@";
33 public static final List<String> REQUIRED_FIELDS =
34 List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, NOTIFICATION_TYPE, NOTIFICATION_ID, SOURCE_INDICATOR, PATH,
37 private static final String CM_PAYLOAD = "{\n"
38 + " \"devicemanager:input\": {\n"
39 + " \"devicemanager:node-id\": \"" + NODE_ID + "\",\n"
40 + " \"devicemanager:counter\": \"" + COUNTER + "\",\n"
41 + " \"devicemanager:timestamp\": \"" + TIMESTAMP + "\",\n"
42 + " \"devicemanager:object-id\": \"" + OBJECT_ID + "\",\n"
43 + " \"devicemanager:notification-type\": \"" + NOTIFICATION_TYPE + "\",\n"
44 + " \"devicemanager:notification-id\": \"" + NOTIFICATION_ID + "\",\n"
45 + " \"devicemanager:source-indicator\": \"" + SOURCE_INDICATOR + "\",\n"
46 + " \"devicemanager:path\": \"" + PATH + "\",\n"
47 + " \"devicemanager:operation\": \"" + OPERATION + "\",\n"
48 + " \"devicemanager:value\": \"" + VALUE + "\"\n"
52 public CMNotificationClient(String baseUrl) {
53 super(baseUrl, CM_NOTIFICATION_URI);
57 public String prepareMessageFromPayloadMap(Map<String, String> notificationPayloadMap) {
58 return super.prepareMessageFromPayloadMap(notificationPayloadMap, CM_PAYLOAD, REQUIRED_FIELDS);
62 public boolean sendNotification(String message) {
63 return super.sendNotification(message, POST, MessageType.json);
67 public static Map<String, String> createCMNotificationPayloadMap(CMNotification cmNotification) {
68 HashMap<String, String> map = new HashMap<>();
69 map.put(NODE_ID, cmNotification.getBasicHeaderFields().getCmNodeId());
70 map.put(COUNTER, cmNotification.getBasicHeaderFields().getCmSequence());
71 map.put(TIMESTAMP, cmNotification.getBasicHeaderFields().getCmOccurrenceTime());
72 map.put(OBJECT_ID, cmNotification.getBasicHeaderFields().getSourceId());
73 map.put(NOTIFICATION_TYPE, cmNotification.getBasicHeaderFields().getNotificationType());
74 map.put(NOTIFICATION_ID, cmNotification.getCmNotificationId());
75 map.put(SOURCE_INDICATOR, cmNotification.getCmSourceIndicator());
76 map.put(PATH, cmNotification.getCmPath());
77 map.put(OPERATION, cmNotification.getCmOperation());
78 map.put(VALUE, cmNotification.getCmValue());