Fix sonar issues in models: sdc to vfc
[policy/models.git] / models-interactions / 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  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.sdnr;
24
25 import com.google.gson.annotations.SerializedName;
26
27 import java.io.Serializable;
28 import java.time.Instant;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32
33 public class PciCommonHeader implements Serializable {
34
35     private static final long serialVersionUID = 5435363539127062114L;
36
37     @SerializedName(value = "TimeStamp")
38     private Instant timeStamp = Instant.now();
39
40     @SerializedName(value = "APIVer")
41     private String apiVer = "1.0";
42
43     @SerializedName(value = "RequestID")
44     private UUID requestId;
45
46     @SerializedName(value = "SubRequestID")
47     private String subRequestId;
48
49     @SerializedName(value = "RequestTrack")
50     private Map<String, String> requestTrack = new HashMap<>();
51
52     @SerializedName(value = "Flags")
53     private Map<String, String> flags = new HashMap<>();
54
55     public PciCommonHeader() {
56
57     }
58
59     /**
60      * Used to copy a pci common header.
61      *
62      * @param commonHeader a header that is defined by the Pci api guide that contains information
63      *        about the request (requestId, flags, etc.)
64      */
65     public PciCommonHeader(PciCommonHeader commonHeader) {
66         this.timeStamp = commonHeader.timeStamp;
67         this.requestId = commonHeader.requestId;
68         this.subRequestId = commonHeader.subRequestId;
69         if (commonHeader.requestTrack != null) {
70             this.requestTrack.putAll(commonHeader.requestTrack);
71         }
72         if (commonHeader.flags != null) {
73             this.flags.putAll(commonHeader.flags);
74         }
75     }
76
77     /**
78      * Get the timestamp.
79      *
80      * @return the timeStamp
81      */
82     public Instant getTimeStamp() {
83         return timeStamp;
84     }
85
86     /**
87      * Set the timestamp.
88      *
89      * @param timeStamp
90      *            the timeStamp to set
91      */
92     public void setTimeStamp(Instant timeStamp) {
93         this.timeStamp = timeStamp;
94     }
95
96     /**
97      * Get the API version.
98      *
99      * @return the apiVer
100      */
101     public String getApiVer() {
102         return apiVer;
103     }
104
105     /**
106      * Set the API version.
107      *
108      * @param apiVer
109      *            the apiVer to set
110      */
111     public void setApiVer(String apiVer) {
112         this.apiVer = apiVer;
113     }
114
115     /**
116      * Get the request Id.
117      *
118      * @return the requestId
119      */
120     public UUID getRequestId() {
121         return requestId;
122     }
123
124     /**
125      * Set the request Id.
126      *
127      * @param requestId
128      *            the requestId to set
129      */
130     public void setRequestId(UUID requestId) {
131         this.requestId = requestId;
132     }
133
134     /**
135      * Get the sub request Id.
136      *
137      * @return the subRequestId
138      */
139     public String getSubRequestId() {
140         return subRequestId;
141     }
142
143     /**
144      * Set the sub request Id.
145      *
146      * @param subRequestId
147      *            the subRequestId to set
148      */
149     public void setSubRequestId(String subRequestId) {
150         this.subRequestId = subRequestId;
151     }
152
153     /**
154      * Set the request track.
155      *
156      * @param requestTrack
157      *            the requestTrack to set
158      */
159     public void setRequestTrack(Map<String, String> requestTrack) {
160         this.requestTrack = requestTrack;
161     }
162
163     /**
164      * Get the request track.
165      *
166      * @return the requestTrack
167      */
168     public Map<String, String> getRequestTrack() {
169         return requestTrack;
170     }
171
172     /**
173      * Get the flags.
174      *
175      * @return the flags
176      */
177     public Map<String, String> getFlags() {
178         return flags;
179     }
180
181     /**
182      * Set the flags.
183      *
184      * @param flags
185      *            the flags to set
186      */
187     public void setFlags(Map<String, String> flags) {
188         this.flags = flags;
189     }
190
191     @Override
192     public String toString() {
193         return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer
194                    + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", requestTrack=" + requestTrack
195                    + ", flags=" + flags + "]";
196     }
197
198     @Override
199     public int hashCode() {
200         final int prime = 31;
201         int result = 1;
202         result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
203         result = prime * result + ((flags == null) ? 0 : flags.hashCode());
204         result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
205         result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
206         result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
207         result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
208         return result;
209     }
210
211     @Override
212     public boolean equals(Object obj) {
213         if (this == obj) {
214             return true;
215         }
216         if (obj == null) {
217             return false;
218         }
219         if (getClass() != obj.getClass()) {
220             return false;
221         }
222         PciCommonHeader other = (PciCommonHeader) obj;
223         if (apiVer == null) {
224             if (other.apiVer != null) {
225                 return false;
226             }
227         } else if (!apiVer.equals(other.apiVer)) {
228             return false;
229         }
230         if (flags == null) {
231             if (other.flags != null) {
232                 return false;
233             }
234         } else if (!flags.equals(other.flags)) {
235             return false;
236         }
237         if (requestTrack == null) {
238             if (other.requestTrack != null) {
239                 return false;
240             }
241         } else if (!requestTrack.equals(other.requestTrack)) {
242             return false;
243         }
244         if (requestId == null) {
245             if (other.requestId != null) {
246                 return false;
247             }
248         } else if (!requestId.equals(other.requestId)) {
249             return false;
250         }
251         if (subRequestId == null) {
252             if (other.subRequestId != null) {
253                 return false;
254             }
255         } else if (!subRequestId.equals(other.subRequestId)) {
256             return false;
257         }
258         if (timeStamp == null) {
259             if (other.timeStamp != null) {
260                 return false;
261             }
262         } else if (!timeStamp.equals(other.timeStamp)) {
263             return false;
264         }
265         return true;
266     }
267
268 }