add fixes for wt sulfur
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / impl / CMNotificationClient.java
1 /*
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
20
21 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.POST;
22
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 public class CMNotificationClient extends MessageClient {
28
29     private static final String CM_NOTIFICATION_URI = "rests/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,
35             OPERATION, VALUE);
36
37     private static final String CM_PAYLOAD = "{\n"
38         + "  \"input\": {\n"
39         + "    \"node-id\": \"" + NODE_ID + "\",\n"
40         + "    \"counter\": \"" + COUNTER + "\",\n"
41         + "    \"timestamp\": \"" + TIMESTAMP + "\",\n"
42         + "    \"object-id\": \"" + OBJECT_ID + "\",\n"
43         + "    \"notification-type\": \"" + NOTIFICATION_TYPE + "\",\n"
44         + "    \"notification-id\": \"" + NOTIFICATION_ID + "\",\n"
45         + "    \"source-indicator\": \"" + SOURCE_INDICATOR + "\",\n"
46         + "    \"path\": \"" + PATH + "\",\n"
47         + "    \"operation\": \"" + OPERATION + "\",\n"
48         + "    \"value\": \"" + VALUE + "\"\n"
49         + "  }\n"
50         + "}";
51
52     public CMNotificationClient(String baseUrl) {
53         super(baseUrl, CM_NOTIFICATION_URI);
54     }
55
56     @Override
57     public String prepareMessageFromPayloadMap(Map<String, String> notificationPayloadMap) {
58         return super.prepareMessageFromPayloadMap(notificationPayloadMap, CM_PAYLOAD, REQUIRED_FIELDS);
59     }
60
61     @Override
62     public boolean sendNotification(String message) {
63         return super.sendNotification(message, POST, MessageType.json);
64     }
65
66
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());
79         return map;
80     }
81 }