2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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============================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.champ.event.envelope;
24 import java.time.Instant;
25 import java.time.ZoneOffset;
26 import java.time.format.DateTimeFormatter;
27 import java.util.Objects;
28 import java.util.UUID;
29 import org.apache.commons.lang3.builder.EqualsBuilder;
30 import com.google.gson.Gson;
31 import com.google.gson.GsonBuilder;
32 import com.google.gson.annotations.SerializedName;
34 public class GraphEventHeader {
36 private static final String SOURCE_NAME = "CHAMP";
38 private static final String EVENT_TYPE = "db-update-result";
40 @SerializedName("request-id")
41 private String requestId;
43 private String timestamp;
45 @SerializedName("source-name")
46 private String sourceName;
48 @SerializedName("event-type")
49 private String eventType;
51 @SerializedName("validation-entity-type")
52 private String validationEntityType;
54 @SerializedName("validation-top-entity-type")
55 private String validationTopEntityType;
57 @SerializedName("entity-link")
58 private String entityLink;
60 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
62 public static Builder builder() {
66 public static class Builder {
68 private String requestId;
69 private String validationEntityType;
70 private String validationTopEntityType;
71 private String entityLink;
73 public Builder requestId(String val) {
78 public Builder validationEntityType(String val) {
79 validationEntityType = val;
83 public Builder validationTopEntityType(String val) {
84 validationTopEntityType = val;
88 public Builder entityLink(String val) {
93 public GraphEventHeader build() {
94 return new GraphEventHeader(this);
98 private GraphEventHeader(Builder builder) {
99 requestId = builder.requestId != null ? builder.requestId : UUID.randomUUID().toString();
100 timestamp = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
101 sourceName = SOURCE_NAME;
102 eventType = EVENT_TYPE;
104 validationEntityType = builder.validationEntityType;
105 validationTopEntityType = builder.validationTopEntityType;
106 entityLink = builder.entityLink;
110 * Serializes this object into a JSON string representation.
112 * @return a JSON format string representation of this object.
114 public String toJson() {
115 return gson.toJson(this);
118 ///////////////////////////////////////////////////////////////////////////
119 // GETTERS AND SETTERS
120 ///////////////////////////////////////////////////////////////////////////
122 public String getRequestId() {
126 public void setRequestId(String requestId) {
127 this.requestId = requestId;
130 public String getTimestamp() {
134 public void setTimestamp(String timestamp) {
135 this.timestamp = timestamp;
138 public String getSourceName() {
142 public void setSourceName(String sourceName) {
143 this.sourceName = sourceName;
146 public String getEventType() {
150 public void setEventType(String eventType) {
151 this.eventType = eventType;
154 public String getValidationEntityType() {
155 return validationEntityType;
158 public void setValidationEntityType(String validationEntityType) {
159 this.validationEntityType = validationEntityType;
162 public String getValidationTopEntityType() {
163 return validationTopEntityType;
166 public void setValidationTopEntityType(String validationTopEntityType) {
167 this.validationTopEntityType = validationTopEntityType;
170 public String getEntityLink() {
174 public void setEntityLink(String entityLink) {
175 this.entityLink = entityLink;
178 ///////////////////////////////////////////////////////////////////////////
180 ///////////////////////////////////////////////////////////////////////////
185 * @see java.lang.Object#hashCode()
188 public int hashCode() {
189 return Objects.hash(this.requestId, this.timestamp, this.sourceName, this.eventType, this.validationEntityType,
190 this.validationTopEntityType, this.entityLink);
196 * @see java.lang.Object#equals(java.lang.Object)
199 public boolean equals(Object obj) {
200 if (!(obj instanceof GraphEventHeader)) {
202 } else if (obj == this) {
205 GraphEventHeader rhs = (GraphEventHeader) obj;
207 return new EqualsBuilder()
208 .append(requestId, rhs.requestId)
209 .append(timestamp, rhs.timestamp)
210 .append(sourceName, rhs.sourceName)
211 .append(eventType, rhs.sourceName)
212 .append(validationEntityType, rhs.validationEntityType)
213 .append(validationTopEntityType, rhs.validationTopEntityType)
214 .append(entityLink, rhs.entityLink)
222 * @see java.lang.Object#toString()
225 public String toString() {
226 return this.toJson();