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