e2f520ad8577a7753974bc50d3d0d4ea98fb7143
[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 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 java.io.Serializable;
24 import java.time.Instant;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.UUID;
28
29 import com.google.gson.annotations.SerializedName;
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="5.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
61      *            a header that is defined by the lcm api guide that contains
62      *            information 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      * @return the timeStamp
75      */
76     public Instant getTimeStamp() {
77         return timeStamp;
78     }
79
80     /**
81      * @param timeStamp the timeStamp to set
82      */
83     public void setTimeStamp(Instant timeStamp) {
84         this.timeStamp = timeStamp;
85     }
86
87     /**
88      * @return the apiVer
89      */
90     public String getApiVer() {
91         return apiVer;
92     }
93
94     /**
95      * @param apiVer the apiVer to set
96      */
97     public void setApiVer(String apiVer) {
98         this.apiVer = apiVer;
99     }
100
101     /**
102      * @return the originatorId
103      */
104     public String getOriginatorId() {
105         return originatorId;
106     }
107
108     /**
109      * @param originatorId the originatorId to set
110      */
111     public void setOriginatorId(String originatorId) {
112         this.originatorId = originatorId;
113     }
114
115     /**
116      * @return the requestId
117      */
118     public UUID getRequestId() {
119         return requestId;
120     }
121
122     /**
123      * @param requestId the requestId to set
124      */
125     public void setRequestId(UUID requestId) {
126         this.requestId = requestId;
127     }
128
129     /**
130      * @return the subRequestId
131      */
132     public String getSubRequestId() {
133         return subRequestId;
134     }
135
136     /**
137      * @param subRequestId the subRequestId to set
138      */
139     public void setSubRequestId(String subRequestId) {
140         this.subRequestId = subRequestId;
141     }
142
143     /**
144      * @return the flags
145      */
146     public Map<String, String> getFlags() {
147         return flags;
148     }
149
150     /**
151      * @param flags the flags to set
152      */
153     public void setFlags(Map<String, String> flags) {
154         this.flags = flags;
155     }
156
157     @Override
158     public String toString() {
159         return "CommonHeader [timeStamp=" + timeStamp + ", apiVer=" + apiVer + ", originatorId=" + originatorId
160                 + ", requestId=" + requestId + ", subRequestId=" + subRequestId + ", flags=" + flags + "]";
161     }
162
163     @Override
164     public int hashCode() {
165         final int prime = 31;
166         int result = 1;
167         result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
168         result = prime * result + ((flags == null) ? 0 : flags.hashCode());
169         result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode());
170         result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
171         result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
172         result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
173         return result;
174     }
175
176     @Override
177     public boolean equals(Object obj) {
178         if (this == obj) {
179             return true;
180         }
181         if (obj == null) {
182             return false;
183         }
184         if (getClass() != obj.getClass()) {
185             return false;
186         }
187         LCMCommonHeader other = (LCMCommonHeader) obj;
188         if (apiVer == null) {
189             if (other.apiVer != null) {
190                 return false;
191             }
192         } else if (!apiVer.equals(other.apiVer)) {
193             return false;
194         }
195         if (flags == null) {
196             if (other.flags != null) {
197                 return false;
198             }
199         } else if (!flags.equals(other.flags)) {
200             return false;
201         }
202         if (originatorId == null) {
203             if (other.originatorId != null) {
204                 return false;
205             }
206         } else if (!originatorId.equals(other.originatorId)) {
207             return false;
208         }
209         if (requestId == null) {
210             if (other.requestId != null) {
211                 return false;
212             }
213         } else if (!requestId.equals(other.requestId)) {
214             return false;
215         }
216         if (subRequestId == null) {
217             if (other.subRequestId != null) {
218                 return false;
219             }
220         } else if (!subRequestId.equals(other.subRequestId)) {
221             return false;
222         }
223         if (timeStamp == null) {
224             if (other.timeStamp != null) {
225                 return false;
226             }
227         } else if (!timeStamp.equals(other.timeStamp)) {
228             return false;
229         }
230         return true;
231     }
232
233 }