Use lombok annotations for objects in models-interaction/models-impl module
[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 import lombok.Getter;
33 import lombok.Setter;
34
35 @Getter
36 @Setter
37 public class CommonHeader implements Serializable {
38     private static final long serialVersionUID = -3581658269910980336L;
39
40     @SerializedName("TimeStamp")
41     private Instant timeStamp = Instant.now();
42
43     @SerializedName("APIver")
44     private String apiVer = "1.01";
45
46     @SerializedName("OriginatorID")
47     private String originatorId;
48
49     @SerializedName("RequestID")
50     private UUID requestId;
51
52     @SerializedName("SubRequestID")
53     private String subRequestId;
54
55     @SerializedName("RequestTrack")
56     private Collection<String> requestTrack = new ArrayList<>();
57
58     @SerializedName("Flags")
59     private Collection<Map<String, String>> flags = new ArrayList<>();
60
61     public CommonHeader() {}
62
63     /**
64      * Construct an instance from an existing instance.
65      *
66      * @param commonHeader the existing instance
67      */
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);
76         }
77         if (commonHeader.flags != null) {
78             this.flags.addAll(commonHeader.flags);
79         }
80     }
81
82     @Override
83     public String toString() {
84         return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorId=" + originatorId
85                 + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
86                 + ", Flags=" + flags + "]";
87     }
88
89     @Override
90     public int hashCode() {
91         final int prime = 31;
92         int result = 1;
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());
100         return result;
101     }
102
103     @Override
104     public boolean equals(Object obj) {
105         if (this == obj) {
106             return true;
107         }
108         if (obj == null) {
109             return false;
110         }
111         if (getClass() != obj.getClass()) {
112             return false;
113         }
114         CommonHeader other = (CommonHeader) obj;
115         if (apiVer == null) {
116             if (other.apiVer != null) {
117                 return false;
118             }
119         } else if (!apiVer.equals(other.apiVer)) {
120             return false;
121         }
122         if (flags == null) {
123             if (other.flags != null) {
124                 return false;
125             }
126         } else if (!flags.equals(other.flags)) {
127             return false;
128         }
129         if (originatorId == null) {
130             if (other.originatorId != null) {
131                 return false;
132             }
133         } else if (!originatorId.equals(other.originatorId)) {
134             return false;
135         }
136         if (requestId == null) {
137             if (other.requestId != null) {
138                 return false;
139             }
140         } else if (!requestId.equals(other.requestId)) {
141             return false;
142         }
143         if (requestTrack == null) {
144             if (other.requestTrack != null) {
145                 return false;
146             }
147         } else if (!requestTrack.equals(other.requestTrack)) {
148             return false;
149         }
150         if (subRequestId == null) {
151             if (other.subRequestId != null) {
152                 return false;
153             }
154         } else if (!subRequestId.equals(other.subRequestId)) {
155             return false;
156         }
157         if (timeStamp == null) {
158             return other.timeStamp == null;
159         } else {
160             return timeStamp.equals(other.timeStamp);
161         }
162     }
163 }