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);
119 // // notification.put("name", "NAME_DUMMY");
120 // JSONObject notification = new JSONObject();
122 // notificationParams.ifPresent(jsonObject -> {
123 // copyParametersToFields(notification, notificationFields);
124 // commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION);
125 // event.put(NOTIFICATION_FIELDS, notificationFields);
129 // notificationParams.ifPresent(jsonObject -> {
130 // copyParametersToFields(jsonObject.toMap(), notificationFields);
131 // commonEventHeader.put(DOMAIN, DOMAIN_NOTIFICATION);
132 // event.put(NOTIFICATION_FIELDS, notificationFields);
135 event.put(COMMON_EVENT_HEADER, commonEventHeader);
136 JSONObject root = new JSONObject();
137 root.put(EVENT, event);
142 public JSONObject createOneVesEvent(String xnfUrl, String fileName) {
144 String notificationFields;
145 JSONObject nof = new JSONObject();
147 nof.put("notificationFieldsVersion", "2.0");
149 nof.put("changeType", "FileReady");
150 nof.put("changeIdentifier", "PM_MEAS_FILES");
152 JSONObject hm = new JSONObject();
153 hm.put("location", xnfUrl.concat(fileName));
154 hm.put("fileFormatType", "org.3GPP.32.435#measCollec");
155 hm.put("fileFormatVersion", "V10");
156 hm.put("compression", "gzip");
158 JSONObject aonh = new JSONObject();
159 aonh.put("name", fileName);
161 aonh.put("hashMap", hm);
163 nof.put("arrayOfNamedHashMap", aonh);
165 String nofString = nof.toString();
167 JSONObject ceh = new JSONObject(); // commonEventHandler
168 ceh.put("startEpochMicrosec", "1551865758690");
169 ceh.put("sourceId", "val13");
170 ceh.put("eventId", "registration_51865758");
171 ceh.put("nfcNamingCode", "oam");
172 ceh.put("priority", "Normal");
173 ceh.put("version", "4.0.1");
174 ceh.put("reportingEntityName", "NOK6061ZW3");
175 ceh.put("sequence", "0");
176 ceh.put("domain", "notification");
177 ceh.put("lastEpochMicrosec", "1551865758690");
178 ceh.put("eventName", "pnfRegistration_Nokia_5gDu");
179 ceh.put("vesEventListenerVersion", "7.0.1");
180 ceh.put("sourceName", "NOK6061ZW3");
181 ceh.put("nfNamingCode", "gNB");
183 JSONObject ihf = new JSONObject(); // internalHeaderFields
184 ceh.put("internalHeaderFields", ihf);
186 JSONObject event = new JSONObject();
187 event.put("commonEventHeader", ceh);
188 event.put("notificationFields", nof);
190 System.out.println("event: ");
191 System.out.println(event.toString());
198 "commonEventHeader": { <== "ceh"
199 "startEpochMicrosec": "1551865758690",
201 "eventId": "registration_51865758",
202 "nfcNamingCode": "oam",
203 "internalHeaderFields": {}, <== "ihf"
204 "priority": "Normal",
206 "reportingEntityName": "NOK6061ZW3",
208 "domain": "notification",
209 "lastEpochMicrosec": "1551865758690",
210 "eventName": "pnfRegistration_Nokia_5gDu",
211 "vesEventListenerVersion": "7.0.1",
212 "sourceName": "NOK6061ZW3",
213 "nfNamingCode": "gNB"
215 "notificationFields": { <== "nof"
217 "notificationFieldsVersion": "2.0",
218 "changeType": "FileReady",
219 "changeIdentifier": "PM_MEAS_FILES",
220 "arrayOfNamedHashMap": { <== "aonh"
221 "name": "A20161224.1030-1045.bin.gz",
222 "hashMap": { <== "hm"
223 "location": "ftpes://192.169.0.1:22/ftp/rop/A20161224.1030-1045.bin.gz",
224 "fileFormatType": "org.3GPP.32.435#measCollec",
225 "fileFormatVersion": "V10",
226 "compression": "gzip"