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