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
 
  11  * http://www.apache.org/licenses/LICENSE-2.0
 
  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
 
  17  * ============LICENSE_END==========================================================================
 
  20 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.impl;
 
  22 import java.util.HashMap;
 
  23 import java.util.List;
 
  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.*;
 
  30 public class FaultNotificationClient extends MessageClient {
 
  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);
 
  37     private static final String FAULT_PAYLOAD = "{\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"
 
  49     public FaultNotificationClient(String baseUrl) {
 
  50         super(baseUrl, FAULT_NOTIFICATION_URI);
 
  54     public String prepareMessageFromPayloadMap(Map<String, String> notificationPayloadMap) {
 
  55         return super.prepareMessageFromPayloadMap(notificationPayloadMap, FAULT_PAYLOAD, REQUIRED_FIELDS);
 
  59     public boolean sendNotification(String message) {
 
  60         return super.sendNotification(message, POST, json);
 
  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);