058323412088050d8ba39e87924f1b2c092e714e
[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-2020 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.EqualsAndHashCode;
33 import lombok.Getter;
34 import lombok.Setter;
35
36 @Getter
37 @Setter
38 @EqualsAndHashCode
39 public class CommonHeader implements Serializable {
40     private static final long serialVersionUID = -3581658269910980336L;
41
42     @SerializedName("TimeStamp")
43     private Instant timeStamp = Instant.now();
44
45     @SerializedName("APIver")
46     private String apiVer = "1.01";
47
48     @SerializedName("OriginatorID")
49     private String originatorId;
50
51     @SerializedName("RequestID")
52     private UUID requestId;
53
54     @SerializedName("SubRequestID")
55     private String subRequestId;
56
57     @SerializedName("RequestTrack")
58     private Collection<String> requestTrack = new ArrayList<>();
59
60     @SerializedName("Flags")
61     private Collection<Map<String, String>> flags = new ArrayList<>();
62
63     public CommonHeader() {
64         // Default constructor
65     }
66
67     /**
68      * Construct an instance from an existing instance.
69      *
70      * @param commonHeader the existing instance
71      */
72     public CommonHeader(CommonHeader commonHeader) {
73         this.originatorId = commonHeader.originatorId;
74         this.requestId = commonHeader.requestId;
75         this.subRequestId = commonHeader.subRequestId;
76         this.timeStamp = commonHeader.getTimeStamp();
77         this.apiVer = commonHeader.getApiVer();
78         if (commonHeader.requestTrack != null) {
79             this.requestTrack.addAll(commonHeader.requestTrack);
80         }
81         if (commonHeader.flags != null) {
82             this.flags.addAll(commonHeader.flags);
83         }
84     }
85
86     @Override
87     public String toString() {
88         return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorId=" + originatorId
89                 + ", RequestId=" + requestId + ", SubrequestId=" + subRequestId + ", RequestTrack=" + requestTrack
90                 + ", Flags=" + flags + "]";
91     }
92 }