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