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