d9e59ad3ba35b0959e6999de70ec49ef7a423755
[policy/drools-applications.git] / controlloop / common / model-impl / sdnr / src / main / java / org / onap / policy / sdnr / PciCommonHeader.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * sdnr
4  * ================================================================================
5  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.sdnr;
22
23 import com.google.gson.annotations.SerializedName;
24
25 import java.io.Serializable;
26 import java.time.Instant;
27 import java.util.HashMap;
28 import java.util.Map;
29 import java.util.UUID;
30
31 public class PciCommonHeader implements Serializable {
32
33     private static final long serialVersionUID = 5435363539127062114L;
34
35     @SerializedName(value = "TimeStamp")
36     private Instant timeStamp = Instant.now();
37
38     @SerializedName(value = "APIVer")
39     private String apiVer = "1.0";
40
41     @SerializedName(value = "RequestID")
42     private UUID requestId;
43
44     @SerializedName(value = "SubRequestID")
45     private String subRequestId;
46
47     @SerializedName(value = "RequestTrack")
48     private Map<String, String> requestTrack = new HashMap<>();
49
50     @SerializedName(value = "Flags")
51     private Map<String, String> flags = new HashMap<>();
52
53     public PciCommonHeader() {
54
55     }
56
57     /**
58      * Used to copy a pci common header.
59      * 
60      * @param commonHeader a header that is defined by the Pci api guide that contains information
61      *        about the request (requestId, flags, etc.)
62      */
63     public PciCommonHeader(PciCommonHeader commonHeader) {
64         this.timeStamp = commonHeader.timeStamp;
65         this.requestId = commonHeader.requestId;
66         this.subRequestId = commonHeader.subRequestId;
67         if (commonHeader.requestTrack != null) {
68             this.requestTrack.putAll(commonHeader.requestTrack);
69         }
70         if (commonHeader.flags != null) {
71             this.flags.putAll(commonHeader.flags);
72         }
73     }
74
75     /**
76      * Get the timestamp.
77      * 
78      * @return the timeStamp
79      */
80     public Instant getTimeStamp() {
81         return timeStamp;
82     }
83
84     /**
85      * Set the timestamp.
86      * 
87      * @param timeStamp
88      *            the timeStamp to set
89      */
90     public void setTimeStamp(Instant timeStamp) {
91         this.timeStamp = timeStamp;
92     }
93
94     /**
95      * Get the API version.
96      * 
97      * @return the apiVer
98      */
99     public String getApiVer() {
100         return apiVer;
101     }
102
103     /**
104      * Set the API version.
105      * 
106      * @param apiVer
107      *            the apiVer to set
108      */
109     public void setApiVer(String apiVer) {
110         this.apiVer = apiVer;
111     }
112
113     /**
114      * Get the request Id.
115      * 
116      * @return the requestId
117      */
118     public UUID getRequestId() {
119         return requestId;
120     }
121
122     /**
123      * Set the request Id.
124      * 
125      * @param requestId
126      *            the requestId to set
127      */
128     public void setRequestId(UUID requestId) {
129         this.requestId = requestId;
130     }
131
132     /**
133      * Get the sub request Id.
134      * 
135      * @return the subRequestId
136      */
137     public String getSubRequestId() {
138         return subRequestId;
139     }
140
141     /**
142      * Set the sub request Id.
143      * 
144      * @param subRequestId
145      *            the subRequestId to set
146      */
147     public void setSubRequestId(String subRequestId) {
148         this.subRequestId = subRequestId;
149     }
150     /**
151      * Set the request track.
152      * 
153      * @param requestTrack
154      *            the requestTrack to set
155      */
156     public void setRequestTrack(Map<String, String> requestTrack) {
157         this.requestTrack = requestTrack;
158     }
159     /**
160      * Get the request track.
161      * 
162      * @return the requestTrack
163      */
164     public Map<String, String> getRequestTrack() {
165         return requestTrack;
166     }
167
168     /**
169      * Get the flags.
170      * 
171      * @return the flags
172      */
173     public Map<String, String> getFlags() {
174         return flags;
175     }
176
177     /**
178      * Set the flags.
179      * 
180      * @param flags
181      *            the flags to set
182      */
183     public void setFlags(Map<String, String> flags) {
184         this.flags = flags;
185     }
186
187     @Override
188     public String toString() {
189         return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer 
190                    + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack
191                    + ", flags=" + flags + "]";
192     }
193
194     @Override
195     public int hashCode() {
196         final int prime = 31;
197         int result = 1;
198         result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
199         result = prime * result + ((flags == null) ? 0 : flags.hashCode());
200         result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
201         result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
202         result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
203         result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
204         return result;
205     }
206
207     @Override
208     public boolean equals(Object obj) {
209         if (this == obj) {
210             return true;
211         }
212         if (obj == null) {
213             return false;
214         }
215         if (getClass() != obj.getClass()) {
216             return false;
217         }
218         PciCommonHeader other = (PciCommonHeader) obj;
219         if (apiVer == null) {
220             if (other.apiVer != null) {
221                 return false;
222             }
223         } else if (!apiVer.equals(other.apiVer)) {
224             return false;
225         }
226         if (flags == null) {
227             if (other.flags != null) {
228                 return false;
229             }
230         } else if (!flags.equals(other.flags)) {
231             return false;
232         }
233         if (requestTrack == null) {
234             if (other.requestTrack != null) {
235                 return false;
236             }
237         } else if (!requestTrack.equals(other.requestTrack)) {
238             return false;
239         }
240         if (requestId == null) {
241             if (other.requestId != null) {
242                 return false;
243             }
244         } else if (!requestId.equals(other.requestId)) {
245             return false;
246         }
247         if (subRequestId == null) {
248             if (other.subRequestId != null) {
249                 return false;
250             }
251         } else if (!subRequestId.equals(other.subRequestId)) {
252             return false;
253         }
254         if (timeStamp == null) {
255             if (other.timeStamp != null) {
256                 return false;
257             }
258         } else if (!timeStamp.equals(other.timeStamp)) {
259             return false;
260         }
261         return true;
262     }
263
264 }