76c8305a22b3670f5db69e600a2815819dcc5849
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.service;
23
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.ObjectMapper;
26 import java.time.Instant;
27 import java.util.HashMap;
28 import java.util.Map;
29 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESCommonEventHeaderPOJO;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESFaultFieldsPOJO;
31 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESNotificationFieldsPOJO;
32 import org.onap.ccsdk.features.sdnr.wt.devicemanager.types.VESPNFRegistrationFieldsPOJO;
33 import org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.NetconfBindingAccessor;
34 import org.opendaylight.yangtools.yang.binding.Notification;
35
36 /*
37  * Interface for mapping ODL notification to VES event fields grouped by event type.
38  * Also includes the commonEventHeader which is applicable for all events.
39  * Ex: fault event, notification event.
40  *
41  * No base implementation exists for this interface. Clients that need to map their data into VES formats must implement this interface.
42  */
43
44 public abstract class VESEventMapper<N extends Notification,F extends Notification,T extends Notification> {
45
46     /**
47      * Creates VESEvent mapping
48      */
49     public abstract String createMapping(NetconfBindingAccessor netconfAccessor,
50             VESCollectorService vesCollectorService, Notification notification, String notifName, int sequenceNo,
51             Instant eventTime);
52
53     /**
54      * Returns VES commonEventHeader fields
55      */
56     public abstract VESCommonEventHeaderPOJO mapCommonEventHeader(N notification);
57
58     /**
59      * Returns VES faultFields
60      */
61     public abstract VESFaultFieldsPOJO mapFaultFields(F notification);
62
63     /**
64      * Returns VES Notification Fields
65      */
66     public abstract VESNotificationFieldsPOJO mapNotificationFields(T notification);
67
68     /**
69      * Returns VES pnfRegistration domain fields
70      *
71      * @return
72      */
73     public abstract VESPNFRegistrationFieldsPOJO mapPNFRegistrationFields();
74
75     /**
76      * Generates VES Event JSON containing commonEventHeader and notificationFields fields
77      *
78      * @param commonEventHeader
79      * @param notifFields
80      * @return String - representing the VESEvent JSON
81      */
82     String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESNotificationFieldsPOJO notifFields) {
83         Map<String, Object> innerEvent = new HashMap<String, Object>();
84         innerEvent.put("commonEventHeader", commonEventHeader);
85         innerEvent.put("notificationFields", notifFields);
86
87         Map<String, Object> outerEvent = new HashMap<String, Object>();
88         outerEvent.put("event", innerEvent);
89         try {
90             ObjectMapper objMapper = new ObjectMapper();
91             return objMapper.writeValueAsString(outerEvent);
92         } catch (JsonProcessingException e) {
93             e.printStackTrace();
94         }
95         return null;
96     }
97
98     /**
99      * Generates VES Event JSON containing commonEventHeader and faultFields fields
100      *
101      * @param commonEventHeader
102      * @param faultFields
103      * @return String - representing the VES Event JSON
104      */
105     String generateVESEvent(VESCommonEventHeaderPOJO commonEventHeader, VESFaultFieldsPOJO faultFields) {
106         Map<String, Object> innerEvent = new HashMap<String, Object>();
107         innerEvent.put("commonEventHeader", commonEventHeader);
108         innerEvent.put("faultFields", faultFields);
109
110         Map<String, Object> outerEvent = new HashMap<String, Object>();
111         outerEvent.put("event", innerEvent);
112         try {
113             ObjectMapper objMapper = new ObjectMapper();
114             return objMapper.writeValueAsString(outerEvent);
115         } catch (JsonProcessingException e) {
116             e.printStackTrace();
117         }
118         return null;
119     }
120
121 }