2 * ============LICENSE_START=======================================================
3 * PNF-REGISTRATION-HANDLER
4 * ================================================================================ Copyright (C)
5 * 2018 NOKIA Intellectual Property. All rights reserved.
6 * ================================================================================ Licensed under
7 * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
8 * 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
15 * the License. ============LICENSE_END=========================================================
18 package org.onap.pnfsimulator.message;
20 import static org.onap.pnfsimulator.message.MessageConstants.COMMON_EVENT_HEADER;
21 import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN;
22 import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_NOTIFICATION;
23 import static org.onap.pnfsimulator.message.MessageConstants.DOMAIN_PNF_REGISTRATION;
24 import static org.onap.pnfsimulator.message.MessageConstants.EVENT;
25 import static org.onap.pnfsimulator.message.MessageConstants.EVENT_TYPE;
26 import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS;
27 import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS;
28 import java.util.HashMap;
30 import java.util.Optional;
31 import org.json.JSONArray;
32 import org.json.JSONObject;
34 public class MessageProvider {
36 public JSONObject createMessage(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams,
37 Optional<JSONObject> notificationParams) {
39 if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) {
40 throw new IllegalArgumentException(
41 "Both PNF registration and notification parameters objects are not present");
43 JSONObject event = new JSONObject();
45 JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
46 Map<String, Object> commonEventHeaderFields = commonEventHeaderParams.toMap();
47 commonEventHeaderFields.forEach((key, value) -> {
48 commonEventHeader.put(key, value);
51 JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
52 pnfRegistrationParams.ifPresent(jsonObject -> {
53 copyParametersToFields(jsonObject.toMap(), pnfRegistrationFields);
54 commonEventHeader.put(DOMAIN, DOMAIN_PNF_REGISTRATION);
55 commonEventHeader.put(EVENT_TYPE, DOMAIN_PNF_REGISTRATION);
56 event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields);
59 JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
60 notificationParams.ifPresent(jsonObject -> {
61 copyParametersToFields(jsonObject.toMap(), notificationFields);
62 commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION);
63 event.put(NOTIFICATION_FIELDS, notificationFields);
66 event.put(COMMON_EVENT_HEADER, commonEventHeader);
67 JSONObject root = new JSONObject();
68 root.put(EVENT, event);
72 private void copyParametersToFields(Map<String, Object> paramersMap, JSONObject fieldsJsonObject) {
73 paramersMap.forEach((key, value) -> {
74 fieldsJsonObject.put(key, value);
78 public JSONObject createOneVes(JSONObject commonEventHeaderParams, Optional<JSONObject> pnfRegistrationParams,
79 Optional<JSONObject> notificationParams, String url, String fileName) {
82 if (!pnfRegistrationParams.isPresent() && !notificationParams.isPresent()) {
83 throw new IllegalArgumentException(
84 "Both PNF registration and notification parameters objects are not present");
86 JSONObject event = new JSONObject();
88 JSONObject commonEventHeader = JSONObjectFactory.generateConstantCommonEventHeader();
89 Map<String, Object> commonEventHeaderFields = commonEventHeaderParams.toMap();
90 commonEventHeaderFields.forEach((key, value) -> {
91 commonEventHeader.put(key, value);
94 JSONObject pnfRegistrationFields = JSONObjectFactory.generatePnfRegistrationFields();
95 pnfRegistrationParams.ifPresent(jsonObject -> {
96 copyParametersToFields(jsonObject.toMap(), pnfRegistrationFields);
97 commonEventHeader.put(DOMAIN, DOMAIN_PNF_REGISTRATION);
98 commonEventHeader.put(EVENT_TYPE, DOMAIN_PNF_REGISTRATION);
99 event.put(PNF_REGISTRATION_FIELDS, pnfRegistrationFields);
102 JSONObject notificationFields = JSONObjectFactory.generateNotificationFields();
104 Map hashMap = new HashMap();
105 hashMap.put("location", "LOCATION_DUMMY");
106 hashMap.put("fileFormatType", "org.3GPP.32.435#measCollec");
107 hashMap.put("fileFormatVersion", "V10");
108 hashMap.put("compression", "gzip");
111 JSONObject jsonHashMap = new JSONObject();
112 jsonHashMap.put("hashmap", jsonHashMap);
114 JSONArray jsonArrayOfNamedHashMap = new JSONArray();
115 jsonArrayOfNamedHashMap.put(jsonHashMap);
117 event.put(COMMON_EVENT_HEADER, commonEventHeader);
118 JSONObject root = new JSONObject();
119 root.put(EVENT, event);
124 public JSONObject createOneVesEvent(String xnfUrl, String fileName) {
126 JSONObject nof = new JSONObject();
128 nof.put("notificationFieldsVersion", "2.0");
130 nof.put("changeType", "FileReady");
131 nof.put("changeIdentifier", "PM_MEAS_FILES");
133 JSONObject hm = new JSONObject();
134 hm.put("location", "ftpes://".concat(xnfUrl).concat(fileName));
135 hm.put("fileFormatType", "org.3GPP.32.435#measCollec");
136 hm.put("fileFormatVersion", "V10");
137 hm.put("compression", "gzip");
139 JSONObject aonhElement = new JSONObject();
140 aonhElement.put("name", fileName);
141 aonhElement.put("hashMap", hm);
143 JSONArray aonh = new JSONArray();
144 aonh.put(aonhElement);
146 nof.put("arrayOfNamedHashMap", aonh);
148 JSONObject ceh = new JSONObject(); // commonEventHandler
149 ceh.put("startEpochMicrosec", "1551865758690");
150 ceh.put("sourceId", "val13");
151 ceh.put("eventId", "registration_51865758");
152 ceh.put("nfcNamingCode", "oam");
153 ceh.put("priority", "Normal");
154 ceh.put("version", "4.0.1");
155 ceh.put("reportingEntityName", "NOK6061ZW3");
156 ceh.put("sequence", "0");
157 ceh.put("domain", "notification");
158 ceh.put("lastEpochMicrosec", "1551865758690");
159 ceh.put("eventName", "pnfRegistration_Nokia_5gDu");
160 ceh.put("vesEventListenerVersion", "7.0.1");
161 ceh.put("sourceName", "NOK6061ZW3");
162 ceh.put("nfNamingCode", "gNB");
164 JSONObject ihf = new JSONObject(); // internalHeaderFields
165 ceh.put("internalHeaderFields", ihf);
167 JSONObject eventContent = new JSONObject();
168 eventContent.put("commonEventHeader", ceh);
169 eventContent.put("notificationFields", nof);
172 JSONObject event = new JSONObject();
173 event.put("event", eventContent);
175 System.out.println("VES messages to be sent: ");
176 System.out.println(event.toString());
184 "commonEventHeader": { <== "ceh"
185 "startEpochMicrosec": "1551865758690",
187 "eventId": "registration_51865758",
188 "nfcNamingCode": "oam",
189 "internalHeaderFields": {}, <== "ihf"
190 "priority": "Normal",
192 "reportingEntityName": "NOK6061ZW3",
194 "domain": "notification",
195 "lastEpochMicrosec": "1551865758690",
196 "eventName": "pnfRegistration_Nokia_5gDu",
197 "vesEventListenerVersion": "7.0.1",
198 "sourceName": "NOK6061ZW3",
199 "nfNamingCode": "gNB"
201 "notificationFields": { <== "nof"
203 "notificationFieldsVersion": "2.0",
204 "changeType": "FileReady",
205 "changeIdentifier": "PM_MEAS_FILES",
206 "arrayOfNamedHashMap": [ <== "aonh"
208 "name": "A20161224.1030-1045.bin.gz",
209 "hashMap": { <== "hm"
210 "location": "ftpes://192.169.0.1:22/ftp/rop/A20161224.1030-1045.bin.gz",
211 "fileFormatType": "org.3GPP.32.435#measCollec",
212 "fileFormatVersion": "V10",
213 "compression": "gzip"