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