2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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=========================================================
21 package org.onap.aai.spike.event.envelope;
23 import java.time.Instant;
24 import java.time.ZoneOffset;
25 import java.time.format.DateTimeFormatter;
26 import java.util.Objects;
27 import java.util.UUID;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
30 import com.google.gson.annotations.SerializedName;
31 import org.apache.commons.lang3.builder.EqualsBuilder;
33 public class EventHeader {
35 @SerializedName("request-id")
36 private String requestId;
38 private String timestamp;
40 @SerializedName("source-name")
41 private String sourceName;
43 @SerializedName("event-type")
44 private String eventType;
46 @SerializedName("validation-entity-type")
47 private String validationEntityType;
49 @SerializedName("validation-top-entity-type")
50 private String validationTopEntityType;
52 @SerializedName("entity-link")
53 private String entityLink;
55 private static final String MICROSERVICE_NAME = "SPIKE";
56 private static final String EVENT_TYPE_PENDING_UPDATE = "update-notification";
57 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
59 public static class Builder {
61 private String requestId;
62 private String validationEntityType;
63 private String validationTopEntityType;
64 private String entityLink;
66 public Builder requestId(String val) {
71 public Builder validationEntityType(String val) {
72 validationEntityType = val;
76 public Builder validationTopEntityType(String val) {
77 validationTopEntityType = val;
81 public Builder entityLink(String val) {
86 public EventHeader build() {
87 return new EventHeader(this);
91 private EventHeader(Builder builder) {
92 requestId = builder.requestId != null ? builder.requestId : UUID.randomUUID().toString();
93 timestamp = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
94 sourceName = MICROSERVICE_NAME;
95 eventType = EVENT_TYPE_PENDING_UPDATE;
97 validationEntityType = builder.validationEntityType;
98 validationTopEntityType = builder.validationTopEntityType;
99 entityLink = builder.entityLink;
103 * Serializes this object into a JSON string representation.
105 * @return a JSON format string representation of this object.
107 public String toJson() {
108 return gson.toJson(this);
111 ///////////////////////////////////////////////////////////////////////////
113 ///////////////////////////////////////////////////////////////////////////
115 public String getRequestId() {
119 public String getTimestamp() {
123 public String getSourceName() {
127 public String getEventType() {
131 public String getValidationEntityType() {
132 return validationEntityType;
135 public String getValidationTopEntityType() {
136 return validationTopEntityType;
139 public String getEntityLink() {
143 ///////////////////////////////////////////////////////////////////////////
145 ///////////////////////////////////////////////////////////////////////////
150 * @see java.lang.Object#hashCode()
153 public int hashCode() {
154 return Objects.hash(this.requestId, this.timestamp, this.sourceName, this.eventType, this.validationEntityType,
155 this.validationTopEntityType, this.entityLink);
161 * @see java.lang.Object#equals(java.lang.Object)
164 public boolean equals(Object obj) {
165 if (!(obj instanceof EventHeader)) {
167 } else if (obj == this) {
170 EventHeader rhs = (EventHeader) obj;
172 return new EqualsBuilder()
173 .append(requestId, rhs.requestId)
174 .append(timestamp, rhs.timestamp)
175 .append(sourceName, rhs.sourceName)
176 .append(eventType, rhs.eventType)
177 .append(validationEntityType, rhs.validationEntityType)
178 .append(validationTopEntityType, rhs.validationTopEntityType)
179 .append(entityLink, rhs.entityLink)
187 * @see java.lang.Object#toString()
190 public String toString() {
191 return this.toJson();