ae51c4b978ca69f5e39e8062dcbd76e1592f8477
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / main / java / org / openecomp / appc / listener / demo / model / CommonMessage.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.openecomp.appc.listener.demo.model;
26
27 import java.io.Serializable;
28 import java.util.Collection;
29
30 import org.json.JSONObject;
31 import org.openecomp.appc.listener.util.Mapper;
32
33 import com.fasterxml.jackson.annotation.JsonIgnore;
34 import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
35 import com.fasterxml.jackson.annotation.JsonProperty;
36 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
37 import com.fasterxml.jackson.databind.annotation.JsonSerialize.Inclusion;
38 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
39 import com.fasterxml.jackson.databind.node.ObjectNode;
40
41 /**
42  * This class holds attributes that are common to DMaaP messages both coming in from DCAE and being sent out by APPC
43  *
44  */
45 @JsonSerialize(include = Inclusion.NON_NULL)
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("pg-streams")
273         private pgStreams pgStreams;
274
275         /**
276          * @return the TenantID
277          */
278
279         public String getPgStreams() {
280             String r = "{\\\"pg-streams\\\": {\\\"pg-stream\\\":[";
281             boolean first = true;
282             for(pgStream p : this.pgStreams.streams){
283                 String n = "{\\\"id\\\":\\\""+p.getId()+"\\\", \\\"is-enabled\\\":\\\""+p.getIsEnabled()+"\\\"}";
284                 if(!first){
285                         r = r.concat(",");
286                 }
287                 first = false;
288                 r = r.concat(n);
289             }
290            r=  r.concat("]}}");
291             return r;
292         }
293
294         /**
295          * @param TenantID
296          *            the TenantID to set
297          */
298         public void setPgStreams(pgStreams pgStreams) {
299             this.pgStreams = pgStreams;
300         }
301
302
303
304
305
306     };
307     @JsonIgnoreProperties(ignoreUnknown = true)
308     public static class pgStreams {
309         @JsonProperty("pg-stream")
310         private Collection<pgStream> streams;
311         
312         public Collection<pgStream> getStreams() {
313                         return streams;
314                 }
315
316                 public void setStreams(Collection<pgStream> streams) {
317                         this.streams = streams;
318                 }
319
320
321     };
322         @JsonIgnoreProperties(ignoreUnknown = true)
323         public static class pgStream{
324         public String getId() {
325                         return id;
326                 }
327                 public void setId(String id) {
328                         this.id = id;
329                 }
330                 public String getIsEnabled() {
331                         return isEnabled;
332                 }
333                 public void setIsEnabled(String isEnabled) {
334                         this.isEnabled = isEnabled;
335                 }
336                 @JsonProperty("id")
337         private String id;
338         @JsonProperty("is-enabled")
339         private String isEnabled;
340         };
341
342
343 }