Merge "Add debugging of REST call"
[policy/drools-applications.git] / controlloop / common / model-impl / appc / src / main / java / org / onap / policy / appc / CommonHeader.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
4  * ================================================================================
5  * Copyright (C) 2017-2019 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.appc;
22
23 import com.google.gson.annotations.SerializedName;
24
25 import java.io.Serializable;
26 import java.time.Instant;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Map;
30 import java.util.UUID;
31
32 public class CommonHeader implements Serializable {
33     private static final long serialVersionUID = -3581658269910980336L;
34
35     @SerializedName("TimeStamp")
36     private Instant timeStamp = Instant.now();
37
38     @SerializedName("APIver")
39     private String apiVer = "1.01";
40
41     @SerializedName("OriginatorID")
42     private String originatorId;
43
44     @SerializedName("RequestID")
45     private UUID requestId;
46
47     @SerializedName("SubRequestID")
48     private String subRequestId;
49
50     @SerializedName("RequestTrack")
51     private Collection<String> requestTrack = new ArrayList<>();
52
53     @SerializedName("Flags")
54     private Collection<Map<String, String>> flags = new ArrayList<>();
55
56     public CommonHeader() {}
57
58     /**
59      * Construct an instance from an existing instance.
60      * 
61      * @param commonHeader the existing instance
62      */
63     public CommonHeader(CommonHeader commonHeader) {
64         this.originatorId = commonHeader.originatorId;
65         this.requestId = commonHeader.requestId;
66         this.subRequestId = commonHeader.subRequestId;
67         if (commonHeader.requestTrack != null) {
68             this.requestTrack.addAll(commonHeader.requestTrack);
69         }
70         if (commonHeader.flags != null) {
71             this.flags.addAll(commonHeader.flags);
72         }
73     }
74
75     public Instant getTimeStamp() {
76         return timeStamp;
77     }
78
79     public void setTimeStamp(Instant timeStamp) {
80         this.timeStamp = timeStamp;
81     }
82
83     public String getApiVer() {
84         return apiVer;
85     }
86
87     public void setApiVer(String apiVer) {
88         this.apiVer = apiVer;
89     }
90
91     public String getOriginatorId() {
92         return originatorId;
93     }
94
95     public void setOriginatorId(String originatorId) {
96         this.originatorId = originatorId;
97     }
98
99     public UUID getRequestId() {
100         return requestId;
101     }
102
103     public void setRequestId(UUID requestId) {
104         this.requestId = requestId;
105     }
106
107     public String getSubRequestId() {
108         return subRequestId;
109     }
110
111     public void setSubRequestId(String subRequestId) {
112         this.subRequestId = subRequestId;
113     }
114
115     public Collection<String> getRequestTrack() {
116         return requestTrack;
117     }
118
119     public void setRequestTrack(Collection<String> requestTrack) {
120         this.requestTrack = requestTrack;
121     }
122
123     public Collection<Map<String, String>> getFlags() {
124         return flags;
125     }
126
127     public void setFlags(Collection<Map<String, String>> flags) {
128         this.flags = flags;
129     }
130
131     @Override
132     public String toString() {
133         return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorId=" + originatorId
134                 + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
135                 + ", Flags=" + flags + "]";
136     }
137
138     @Override
139     public int hashCode() {
140         final int prime = 31;
141         int result = 1;
142         result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
143         result = prime * result + ((flags == null) ? 0 : flags.hashCode());
144         result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode());
145         result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
146         result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
147         result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
148         result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
149         return result;
150     }
151
152     @Override
153     public boolean equals(Object obj) {
154         if (this == obj) {
155             return true;
156         }
157         if (obj == null) {
158             return false;
159         }
160         if (getClass() != obj.getClass()) {
161             return false;
162         }
163         CommonHeader other = (CommonHeader) obj;
164         if (apiVer == null) {
165             if (other.apiVer != null) {
166                 return false;
167             }
168         } else if (!apiVer.equals(other.apiVer)) {
169             return false;
170         }
171         if (flags == null) {
172             if (other.flags != null) {
173                 return false;
174             }
175         } else if (!flags.equals(other.flags)) {
176             return false;
177         }
178         if (originatorId == null) {
179             if (other.originatorId != null) {
180                 return false;
181             }
182         } else if (!originatorId.equals(other.originatorId)) {
183             return false;
184         }
185         if (requestId == null) {
186             if (other.requestId != null) {
187                 return false;
188             }
189         } else if (!requestId.equals(other.requestId)) {
190             return false;
191         }
192         if (requestTrack == null) {
193             if (other.requestTrack != null) {
194                 return false;
195             }
196         } else if (!requestTrack.equals(other.requestTrack)) {
197             return false;
198         }
199         if (subRequestId == null) {
200             if (other.subRequestId != null) {
201                 return false;
202             }
203         } else if (!subRequestId.equals(other.subRequestId)) {
204             return false;
205         }
206         if (timeStamp == null) {
207             if (other.timeStamp != null) {
208                 return false;
209             }
210         } else if (!timeStamp.equals(other.timeStamp)) {
211             return false;
212         }
213         return true;
214     }
215
216 }