2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.appc;
24 import com.google.gson.annotations.SerializedName;
26 import java.io.Serializable;
27 import java.time.Instant;
28 import java.util.ArrayList;
29 import java.util.Collection;
31 import java.util.UUID;
37 public class CommonHeader implements Serializable {
38 private static final long serialVersionUID = -3581658269910980336L;
40 @SerializedName("TimeStamp")
41 private Instant timeStamp = Instant.now();
43 @SerializedName("APIver")
44 private String apiVer = "1.01";
46 @SerializedName("OriginatorID")
47 private String originatorId;
49 @SerializedName("RequestID")
50 private UUID requestId;
52 @SerializedName("SubRequestID")
53 private String subRequestId;
55 @SerializedName("RequestTrack")
56 private Collection<String> requestTrack = new ArrayList<>();
58 @SerializedName("Flags")
59 private Collection<Map<String, String>> flags = new ArrayList<>();
61 public CommonHeader() {}
64 * Construct an instance from an existing instance.
66 * @param commonHeader the existing instance
68 public CommonHeader(CommonHeader commonHeader) {
69 this.originatorId = commonHeader.originatorId;
70 this.requestId = commonHeader.requestId;
71 this.subRequestId = commonHeader.subRequestId;
72 this.timeStamp = commonHeader.getTimeStamp();
73 this.apiVer = commonHeader.getApiVer();
74 if (commonHeader.requestTrack != null) {
75 this.requestTrack.addAll(commonHeader.requestTrack);
77 if (commonHeader.flags != null) {
78 this.flags.addAll(commonHeader.flags);
83 public String toString() {
84 return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorId=" + originatorId
85 + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
86 + ", Flags=" + flags + "]";
90 public int hashCode() {
93 result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
94 result = prime * result + ((flags == null) ? 0 : flags.hashCode());
95 result = prime * result + ((originatorId == null) ? 0 : originatorId.hashCode());
96 result = prime * result + ((requestId == null) ? 0 : requestId.hashCode());
97 result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
98 result = prime * result + ((subRequestId == null) ? 0 : subRequestId.hashCode());
99 result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
104 public boolean equals(Object obj) {
111 if (getClass() != obj.getClass()) {
114 CommonHeader other = (CommonHeader) obj;
115 if (apiVer == null) {
116 if (other.apiVer != null) {
119 } else if (!apiVer.equals(other.apiVer)) {
123 if (other.flags != null) {
126 } else if (!flags.equals(other.flags)) {
129 if (originatorId == null) {
130 if (other.originatorId != null) {
133 } else if (!originatorId.equals(other.originatorId)) {
136 if (requestId == null) {
137 if (other.requestId != null) {
140 } else if (!requestId.equals(other.requestId)) {
143 if (requestTrack == null) {
144 if (other.requestTrack != null) {
147 } else if (!requestTrack.equals(other.requestTrack)) {
150 if (subRequestId == null) {
151 if (other.subRequestId != null) {
154 } else if (!subRequestId.equals(other.subRequestId)) {
157 if (timeStamp == null) {
158 return other.timeStamp == null;
160 return timeStamp.equals(other.timeStamp);