3ebf5674a4edffa8784ca26fa99fe8b29b201d03
[integration.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * 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
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.pnfsimulator.message;
22
23 import static org.onap.pnfsimulator.message.MessageConstants.EVENT_ID;
24 import static org.onap.pnfsimulator.message.MessageConstants.INTERNAL_HEADER_FIELDS;
25 import static org.onap.pnfsimulator.message.MessageConstants.LAST_EPOCH_MICROSEC;
26 import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION;
27 import static org.onap.pnfsimulator.message.MessageConstants.NOTIFICATION_FIELDS_VERSION_VALUE;
28 import static org.onap.pnfsimulator.message.MessageConstants.PNF_LAST_SERVICE_DATE;
29 import static org.onap.pnfsimulator.message.MessageConstants.PNF_MANUFACTURE_DATE;
30 import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION;
31 import static org.onap.pnfsimulator.message.MessageConstants.PNF_REGISTRATION_FIELDS_VERSION_VALUE;
32 import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY;
33 import static org.onap.pnfsimulator.message.MessageConstants.PRIORITY_NORMAL;
34 import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE;
35 import static org.onap.pnfsimulator.message.MessageConstants.SEQUENCE_NUMBER;
36 import static org.onap.pnfsimulator.message.MessageConstants.START_EPOCH_MICROSEC;
37 import static org.onap.pnfsimulator.message.MessageConstants.VERSION;
38 import static org.onap.pnfsimulator.message.MessageConstants.VERSION_NUMBER;
39 import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION;
40 import static org.onap.pnfsimulator.message.MessageConstants.VES_EVENT_LISTENER_VERSION_NUMBER;
41
42 import org.json.JSONObject;
43
44 final class JSONObjectFactory {
45
46     static JSONObject generateConstantCommonEventHeader() {
47         JSONObject commonEventHeader = new JSONObject();
48         long timestamp = System.currentTimeMillis();
49         commonEventHeader.put(EVENT_ID, generateEventId());
50         commonEventHeader.put(LAST_EPOCH_MICROSEC, timestamp);
51         commonEventHeader.put(PRIORITY, PRIORITY_NORMAL);
52         commonEventHeader.put(SEQUENCE, SEQUENCE_NUMBER);
53         commonEventHeader.put(START_EPOCH_MICROSEC, timestamp);
54         commonEventHeader.put(INTERNAL_HEADER_FIELDS, new JSONObject());
55         commonEventHeader.put(VERSION, VERSION_NUMBER);
56         commonEventHeader.put(VES_EVENT_LISTENER_VERSION, VES_EVENT_LISTENER_VERSION_NUMBER);
57         return commonEventHeader;
58     }
59
60     static JSONObject generatePnfRegistrationFields() {
61         JSONObject pnfRegistrationFields = new JSONObject();
62         pnfRegistrationFields.put(PNF_REGISTRATION_FIELDS_VERSION, PNF_REGISTRATION_FIELDS_VERSION_VALUE);
63         pnfRegistrationFields.put(PNF_LAST_SERVICE_DATE, String.valueOf(System.currentTimeMillis()));
64         pnfRegistrationFields.put(PNF_MANUFACTURE_DATE, String.valueOf(System.currentTimeMillis()));
65         return pnfRegistrationFields;
66     }
67
68     static JSONObject generateNotificationFields() {
69         JSONObject notificationFields = new JSONObject();
70         notificationFields.put(NOTIFICATION_FIELDS_VERSION, NOTIFICATION_FIELDS_VERSION_VALUE);
71         return notificationFields;
72     }
73
74
75     static String generateEventId() {
76         String timeAsString = String.valueOf(System.currentTimeMillis());
77         return String.format("registration_%s",
78             timeAsString.substring(timeAsString.length() - 11, timeAsString.length() - 3));
79     }
80
81     private JSONObjectFactory() {
82
83     }
84
85 }