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