Stepping to springboot 3
[nonrtric.git] / pmlog / src / main / java / org / oran / pmlog / PmReport.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2023 Nordix Foundation
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.oran.pmlog;
22
23 import com.google.gson.annotations.Expose;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27
28 import lombok.Builder;
29 import lombok.Getter;
30 import lombok.Setter;
31
32 @Builder(toBuilder = true)
33 public class PmReport {
34
35     private static com.google.gson.Gson gson = new com.google.gson.GsonBuilder() //
36             .disableHtmlEscaping() //
37             .create();
38
39     public static PmReport parse(DataFromKafkaTopic data) {
40         return gson.fromJson(data.valueAsString(), PmReport.class);
41     }
42
43     public long lastTimeEpochMili() {
44         return event.commonEventHeader.lastEpochMicrosec / 1000;
45     }
46
47     public String fullDistinguishedName(PmReport.MeasValuesList measValueList) {
48         return event.getPerf3gppFields().getMeasDataCollection().getMeasuredEntityDn() + ","
49                 + measValueList.getMeasObjInstId();
50     }
51
52     @Expose
53     public Event event;
54
55     public static class CommonEventHeader {
56         @Expose
57         private String domain;
58
59         @Expose
60         private String eventId;
61
62         @Expose
63         private String eventName;
64
65         @Expose
66         @Getter
67         private String sourceName;
68
69         @Expose
70         private String reportingEntityName;
71
72         @Expose
73         private long startEpochMicrosec;
74
75         @Expose
76         @Setter
77         private long lastEpochMicrosec;
78
79         @Expose
80         private String timeZoneOffset;
81
82         /* Not reported elements */
83         int sequence;
84         String priority;
85         String version;
86         String vesEventListenerVersion;
87     }
88
89     public static class MeasInfoId {
90         @Expose
91         private String sMeasInfoId = "";
92     }
93
94     public static class MeasTypes {
95         public String getMeasType(int pValue) {
96             if (pValue > sMeasTypesList.size()) {
97                 return "MeasTypeIndexOutOfBounds:" + pValue;
98             }
99             return sMeasTypesList.get(pValue - 1);
100         }
101
102         @Expose
103         protected ArrayList<String> sMeasTypesList = new ArrayList<>();
104     }
105
106     @Getter
107     @Builder(toBuilder = true)
108     public static class MeasResult {
109         @Expose
110         @Setter
111         private int p;
112
113         @Expose
114         @Setter
115         private String sValue;
116     }
117
118     @Builder(toBuilder = true)
119     public static class MeasValuesList {
120         @Expose
121         @Getter
122         private String measObjInstId;
123
124         @Expose
125         @Getter
126         private String suspectFlag;
127
128         @Expose
129         @Getter
130         private Collection<MeasResult> measResults;
131
132         public boolean isEmpty() {
133             return this.measResults.isEmpty();
134         }
135
136         static MeasValuesList emptyList = MeasValuesList.builder().measResults(new ArrayList<>()).build();
137
138         public static MeasValuesList empty() {
139             return emptyList;
140         }
141     }
142
143     @Getter
144     @Builder(toBuilder = true)
145     public static class MeasInfoList {
146         @Expose
147         private MeasInfoId measInfoId;
148
149         @Expose
150         private MeasTypes measTypes;
151
152         @Expose
153         private Collection<MeasValuesList> measValuesList;
154
155     }
156
157     @Builder(toBuilder = true)
158     @Getter
159     public static class MeasDataCollection {
160         @Expose
161         private int granularityPeriod;
162
163         @Expose
164         private String measuredEntityUserName;
165
166         @Expose
167         private String measuredEntityDn;
168
169         @Expose
170         private String measuredEntitySoftwareVersion;
171
172         @Expose
173         private Collection<MeasInfoList> measInfoList;
174     }
175
176     @Builder(toBuilder = true)
177     @Getter
178     public static class Perf3gppFields {
179         @Expose
180         private String perf3gppFieldsVersion;
181
182         @Expose
183         private MeasDataCollection measDataCollection;
184     }
185
186     @Getter
187     @Builder(toBuilder = true)
188     public static class Event {
189         @Expose
190         private CommonEventHeader commonEventHeader;
191
192         @Expose
193         private Perf3gppFields perf3gppFields;
194     }
195
196 }