add fixes for wt sulfur
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / impl / FaultNotificationClient.java
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * Copyright (C) 2021 Samsung Electronics Intellectual Property. All rights reserved.
7  * =================================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software distributed under the License
14  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
15  * or implied. See the License for the specific language governing permissions and limitations under
16  * the License.
17  * ============LICENSE_END==========================================================================
18  */
19
20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
21
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Map;
25
26 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.MessageType.*;
27 import static org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl.MessageClient.SendMethod.*;
28
29
30 public class FaultNotificationClient extends MessageClient {
31
32     private static final String FAULT_NOTIFICATION_URI = "rests/operations/devicemanager:push-fault-notification";
33     public static final String NODE_ID = "@node-id@", COUNTER = "@counter@", TIMESTAMP = "@timestamp@",
34             OBJECT_ID = "@object-id@", PROBLEM = "@problem@", SEVERITY = "@severity@";
35     public static final List<String> REQUIRED_FIELDS = List.of(NODE_ID, COUNTER, TIMESTAMP, OBJECT_ID, PROBLEM, SEVERITY);
36
37     private static final String FAULT_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             + "    \"problem\": \"" + PROBLEM + "\",\n"
44             + "    \"severity\": \"" + SEVERITY + "\"\n"
45             + "  }\n"
46             + "}";
47
48
49     public FaultNotificationClient(String baseUrl) {
50         super(baseUrl, FAULT_NOTIFICATION_URI);
51     }
52
53     @Override
54     public String prepareMessageFromPayloadMap(Map<String, String> notificationPayloadMap) {
55         return super.prepareMessageFromPayloadMap(notificationPayloadMap, FAULT_PAYLOAD, REQUIRED_FIELDS);
56     }
57
58     @Override
59     public boolean sendNotification(String message) {
60         return super.sendNotification(message, POST, json);
61     }
62
63     public static Map<String, String> createFaultNotificationPayloadMap(String nodeId, String counter, String timestamp,
64                                                                         String objectId, String problem, String severity) {
65         HashMap<String, String> map = new HashMap<>();
66         map.put(NODE_ID, nodeId);
67         map.put(COUNTER, counter);
68         map.put(TIMESTAMP, timestamp);
69         map.put(OBJECT_ID, objectId);
70         map.put(PROBLEM, problem);
71         map.put(SEVERITY, severity);
72         return map;
73     }
74
75 }