80350293781d766e4ed4e844d66a9c5a055807e9
[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.JsonInclude;
37 import com.fasterxml.jackson.annotation.JsonProperty;
38
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 @JsonInclude(JsonInclude.Include.NON_NULL)
45
46 @JsonIgnoreProperties(ignoreUnknown = true)
47 public class CommonMessage implements Serializable {
48     /*
49      * { "CommonHeader": { "TimeStamp": "0000-00-00T00:00:00.000Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
50      * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }, "Action": "RESTART", "Payload": {
51      * "VServerSelfLink":
52      * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
53      * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
54      * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
55      * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
56      * "is-closed-loop-disabled": "false", "VM_NAME": "basx0001vm034", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" } }
57      */
58
59     private static final long serialVersionUID = 1L;
60
61     /*
62      * The common header
63      */
64     @JsonProperty("CommonHeader")
65     private CommonHeader header;
66
67     /*
68      * The payload
69      */
70     @JsonProperty("Payload")    
71     private Payload payload;
72
73     @JsonIgnore
74     private long startTime = System.currentTimeMillis();
75
76     /*
77      * Getters and Setters
78      */
79
80     public long getStartTime() {
81         return startTime;
82     }
83
84     public void setStartTime(long startTime) {
85         this.startTime = startTime;
86     }
87
88     /**
89      * @return the header
90      */
91     public CommonHeader getHeader() {
92         return header;
93     }
94
95     /**
96      * @param header
97      *            the header to set
98      */
99     public void setHeader(CommonHeader header) {
100         this.header = header;
101     }
102
103     /**
104      * @return the payload
105      */
106     public Payload getPayload() {
107         return payload;
108     }
109
110     /**
111      * @param payload
112      *            the payload to set
113      */
114     public void setPayload(Payload payload) {
115         this.payload = payload;
116     }
117
118     /**
119      * Convenience method to return a json representation of this object.
120      * 
121      * @return The json representation of this object
122      */
123     public JSONObject toJson() {
124         return Mapper.toJsonObject(this);
125     }
126
127     @JsonIgnoreProperties(ignoreUnknown = true)
128     public static class CommonHeader {
129         /*
130          * "CommonHeader": { "TimeStamp": "2016-05-11T13:53:53.146Z", "APIver": "1.01", "OriginatorID": "policy.pdp01",
131          * "RequestID": "b74d13c5-bb26-4b04-992c-4679dfc8280e", "SubrequestID": "1" }
132          */
133
134         /*
135          * The timestamp of the message
136          */
137         @JsonProperty("TimeStamp")
138         private String timeStamp;
139
140         /*
141          * The API version of the message
142          */
143         @JsonProperty("APIver")
144         private String apiVer;
145
146         /*
147          * The Originator ID of the message
148          */
149         @JsonProperty("OriginatorID")
150         private String originatorId;
151
152         /*
153          * The Request Id of the message
154          */
155         @JsonProperty("RequestID")
156         private String requestID;
157
158         /*
159          * The Subrequest Id of the message
160          */
161         @JsonProperty("SubRequestID")
162         private String subRequestId;
163
164         /**
165          * @return the timeStamp
166          */
167         public String getTimeStamp() {
168             return timeStamp;
169         }
170
171         /**
172          * @param timeStamp
173          *            the timeStamp to set
174          */
175         public void setTimeStamp(String timeStamp) {
176             this.timeStamp = timeStamp;
177         }
178
179         /**
180          * @return the apiVer
181          */
182         public String getApiVer() {
183             return apiVer;
184         }
185
186         /**
187          * @param apiVer
188          *            the apiVer to set
189          */
190         public void setApiVer(String apiVer) {
191             this.apiVer = apiVer;
192         }
193
194         /**
195          * @return the originatorId
196          */
197         public String getOriginatorId() {
198             return originatorId;
199         }
200
201         /**
202          * @param originatorId
203          *            the originatorId to set
204          */
205         public void setOriginatorId(String originatorId) {
206             this.originatorId = originatorId;
207         }
208
209         /**
210          * @return the requestID
211          */
212         public String getRequestID() {
213             return requestID;
214         }
215
216         /**
217          * @param requestID
218          *            the requestID to set
219          */
220         public void setRequestID(String requestID) {
221             this.requestID = requestID;
222         }
223
224         /**
225          * @return the subRequestId
226          */
227         public String getSubRequestId() {
228             return subRequestId;
229         }
230
231         /**
232          * @param subRequestId
233          *            the subRequestId to set
234          */
235         public void setSubRequestId(String subRequestId) {
236             this.subRequestId = subRequestId;
237         }
238     };
239
240     @JsonIgnoreProperties(ignoreUnknown = true)
241     public static class Payload {
242         /*
243          * "Payload": { "VServerSelfLink":
244          * "http://192.168.1.2:8774/v2/abcde12345fghijk6789lmnopq123rst/servers/abc12345-1234-5678-890a-abcdefg12345",
245          * "VNF_NAME": "test", "VMID": "abc12345-1234-5678-890a-abcdefg12345", "TenantID":
246          * "abcde12345fghijk6789lmnopq123rst", "LOC_ID": "Test", "in-maint": "false", "Identity":
247          * "http://example.com:5000/v2.0", "Prov_status": "ACTIVE", "OAM_IPV4": "192.168.1.2",
248          * "is-closed-loop-disabled": "false", "VM_NAME": "test", "OAM_IPV6": "aaaa::bbbb:cccc:dddd:eeee/64" }
249          */
250
251         /*
252          * The TenantID of the message
253          */
254         @JsonProperty("generic-vnf.vnf-id")
255         private String genericVnfId;
256
257         /**
258          * @return the TenantID
259          */
260         public String getGenericVnfId() {
261             return genericVnfId;
262         }
263
264         /**
265          * @param TenantID
266          *            the TenantID to set
267          */
268         public void setGenericVnfId(String genericVnfId) {
269             this.genericVnfId = genericVnfId;
270         }
271
272         @JsonProperty("streams")
273         private Streams streams;
274
275         /**
276          * @return the TenantID
277          */
278
279         public String getStreams() {
280             String r = "{\\\"streams\\\": {\\\"active-streams\\\": " + streams.getActiveStreams() +
281                     "}}";
282             return r;
283         }
284
285         /**
286          * @param TenantID
287          *            the TenantID to set
288          */
289         public void setStreams(Streams streams) {
290             this.streams = streams;
291         }
292
293
294
295
296
297     };
298     @JsonIgnoreProperties(ignoreUnknown = true)
299     public static class Streams {
300         
301         @JsonProperty("active-streams")
302         private int activeStreams;
303         
304         public int getActiveStreams() {
305             return this.activeStreams;
306         }
307
308         public void setActiveStreams(int activeStreams) {
309             this.activeStreams = activeStreams;
310         }
311         
312     };
313
314 }