e0dbbab67597e806ff38e4900c86c141c9175e1f
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / onap / appc / listener / demo / model / CommonMessage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * ================================================================================
9  * Modifications Copyright (C) 2019 Ericsson
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.listener.demo.model;
27
28 import java.io.Serializable;
29 import java.util.Collection;
30
31 import org.json.JSONObject;
32 import org.onap.appc.listener.util.Mapper;
33
34 import com.fasterxml.jackson.annotation.JsonIgnore;
35 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
36 import com.fasterxml.jackson.annotation.JsonProperty;
37 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
38 import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
39
40 /**
41  * This class holds attributes that are common to DMaaP messages both coming in from DCAE and being sent out by APPC
42  *
43  */
44 @JsonSerialize(include = Inclusion.NON_NULL)
45 @JsonIgnoreProperties(ignoreUnknown = true)
46 public class CommonMessage implements Serializable {
47     /*
48      * { "CommonHeader": { "TimeStamp": "0000-00-00T00:00:00.000Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
49      * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }, "Action": "RESTART", "Payload": {
50      * "VServerSelfLink":
51      * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
52      * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
53      * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
54      * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
55      * "is-closed-loop-disabled": "false", "VM_NAME": "basx0001vm034", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" } }
56      */
57
58     private static final long serialVersionUID = 1L;
59
60     /*
61      * The common header
62      */
63     @JsonProperty("CommonHeader")
64     private CommonHeader header;
65
66     /*
67      * The payload
68      */
69     @JsonProperty("Payload")    
70     private Payload payload;
71
72     @JsonIgnore
73     private long startTime = System.currentTimeMillis();
74
75     /*
76      * Getters and Setters
77      */
78
79     public long getStartTime() {
80         return startTime;
81     }
82
83     public void setStartTime(long startTime) {
84         this.startTime = startTime;
85     }
86
87     /**
88      * @return the header
89      */
90     public CommonHeader getHeader() {
91         return header;
92     }
93
94     /**
95      * @param header
96      *            the header to set
97      */
98     public void setHeader(CommonHeader header) {
99         this.header = header;
100     }
101
102     /**
103      * @return the payload
104      */
105     public Payload getPayload() {
106         return payload;
107     }
108
109     /**
110      * @param payload
111      *            the payload to set
112      */
113     public void setPayload(Payload payload) {
114         this.payload = payload;
115     }
116
117     /**
118      * Convenience method to return a json representation of this object.
119      * 
120      * @return The json representation of this object
121      */
122     public JSONObject toJson() {
123         return Mapper.toJsonObject(this);
124     }
125
126     @JsonIgnoreProperties(ignoreUnknown = true)
127     public static class CommonHeader {
128         /*
129          * "CommonHeader": { "TimeStamp": "2016-05-11T13:53:53.146Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
130          * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }
131          */
132
133         /*
134          * The timestamp of the message
135          */
136         @JsonProperty("TimeStamp")
137         private String timeStamp;
138
139         /*
140          * The API version of the message
141          */
142         @JsonProperty("APIver")
143         private String apiVer;
144
145         /*
146          * The Originator ID of the message
147          */
148         @JsonProperty("OriginatorID")
149         private String originatorId;
150
151         /*
152          * The Request Id of the message
153          */
154         @JsonProperty("RequestID")
155         private String requestID;
156
157         /*
158          * The Subrequest Id of the message
159          */
160         @JsonProperty("SubRequestID")
161         private String subRequestId;
162
163         /**
164          * @return the timeStamp
165          */
166         public String getTimeStamp() {
167             return timeStamp;
168         }
169
170         /**
171          * @param timeStamp
172          *            the timeStamp to set
173          */
174         public void setTimeStamp(String timeStamp) {
175             this.timeStamp = timeStamp;
176         }
177
178         /**
179          * @return the apiVer
180          */
181         public String getApiVer() {
182             return apiVer;
183         }
184
185         /**
186          * @param apiVer
187          *            the apiVer to set
188          */
189         public void setApiVer(String apiVer) {
190             this.apiVer = apiVer;
191         }
192
193         /**
194          * @return the originatorId
195          */
196         public String getOriginatorId() {
197             return originatorId;
198         }
199
200         /**
201          * @param originatorId
202          *            the originatorId to set
203          */
204         public void setOriginatorId(String originatorId) {
205             this.originatorId = originatorId;
206         }
207
208         /**
209          * @return the requestID
210          */
211         public String getRequestID() {
212             return requestID;
213         }
214
215         /**
216          * @param requestID
217          *            the requestID to set
218          */
219         public void setRequestID(String requestID) {
220             this.requestID = requestID;
221         }
222
223         /**
224          * @return the subRequestId
225          */
226         public String getSubRequestId() {
227             return subRequestId;
228         }
229
230         /**
231          * @param subRequestId
232          *            the subRequestId to set
233          */
234         public void setSubRequestId(String subRequestId) {
235             this.subRequestId = subRequestId;
236         }
237     };
238
239     @JsonIgnoreProperties(ignoreUnknown = true)
240     public static class Payload {
241         /*
242          * "Payload": { "VServerSelfLink":
243          * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
244          * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
245          * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
246          * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
247          * "is-closed-loop-disabled": "false", "VM_NAME": "test", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" }
248          */
249
250         /*
251          * The TenantID of the message
252          */
253         @JsonProperty("generic-vnf.vnf-id")
254         private String genericVnfId;
255
256         /**
257          * @return the TenantID
258          */
259         public String getGenericVnfId() {
260             return genericVnfId;
261         }
262
263         /**
264          * @param TenantID
265          *            the TenantID to set
266          */
267         public void setGenericVnfId(String genericVnfId) {
268             this.genericVnfId = genericVnfId;
269         }
270
271         @JsonProperty("streams")
272         private Streams streams;
273
274         /**
275          * @return the TenantID
276          */
277
278         public String getStreams() {
279             String r = "{\\\"streams\\\": {\\\"active-streams\\\": " + streams.getActiveStreams() +
280                     "}}";
281             return r;
282         }
283
284         /**
285          * @param TenantID
286          *            the TenantID to set
287          */
288         public void setStreams(Streams streams) {
289             this.streams = streams;
290         }
291
292
293
294
295
296     };
297     @JsonIgnoreProperties(ignoreUnknown = true)
298     public static class Streams {
299         
300         @JsonProperty("active-streams")
301         private int activeStreams;
302         
303         public int getActiveStreams() {
304             return this.activeStreams;
305         }
306
307         public void setActiveStreams(int activeStreams) {
308             this.activeStreams = activeStreams;
309         }
310         
311     };
312
313 }