2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.crud.event.envelope;
26 import java.time.Instant;
27 import java.time.ZoneOffset;
28 import java.time.format.DateTimeFormatter;
29 import java.util.Objects;
30 import java.util.UUID;
31 import org.apache.commons.lang3.builder.EqualsBuilder;
32 import com.google.gson.Gson;
33 import com.google.gson.GsonBuilder;
34 import com.google.gson.annotations.SerializedName;
36 public class GraphEventHeader {
38 @SerializedName("request-id")
39 private String requestId;
41 private String timestamp;
43 @SerializedName("source-name")
44 private String sourceName;
46 @SerializedName("event-type")
47 private String eventType;
49 @SerializedName("validation-entity-type")
50 private String validationEntityType;
52 @SerializedName("validation-top-entity-type")
53 private String validationTopEntityType;
55 @SerializedName("entity-link")
56 private String entityLink;
58 private static final String MICROSERVICE_NAME = "GIZMO";
59 private static final String EVENT_TYPE_PENDING_UPDATE = "pending-update";
60 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
62 public static class Builder {
64 private String requestId;
65 private String validationEntityType;
66 private String validationTopEntityType;
67 private String entityLink;
69 public Builder requestId(String val) {
74 public Builder validationEntityType(String val) {
75 validationEntityType = val;
79 public Builder validationTopEntityType(String val) {
80 validationTopEntityType = val;
84 public Builder entityLink(String val) {
89 public GraphEventHeader build() {
90 return new GraphEventHeader(this);
94 private GraphEventHeader(Builder builder) {
95 requestId = builder.requestId != null ? builder.requestId : UUID.randomUUID().toString();
96 timestamp = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
97 sourceName = MICROSERVICE_NAME;
98 eventType = EVENT_TYPE_PENDING_UPDATE;
100 validationEntityType = builder.validationEntityType;
101 validationTopEntityType = builder.validationTopEntityType;
102 entityLink = builder.entityLink;
106 * Serializes this object into a JSON string representation.
108 * @return a JSON format string representation of this object.
110 public String toJson() {
111 return gson.toJson(this);
114 ///////////////////////////////////////////////////////////////////////////
116 ///////////////////////////////////////////////////////////////////////////
118 public String getRequestId() {
122 public String getTimestamp() {
126 public String getSourceName() {
130 public String getEventType() {
134 public String getValidationEntityType() {
135 return validationEntityType;
138 public String getValidationTopEntityType() {
139 return validationTopEntityType;
142 public String getEntityLink() {
146 ///////////////////////////////////////////////////////////////////////////
148 ///////////////////////////////////////////////////////////////////////////
153 * @see java.lang.Object#hashCode()
156 public int hashCode() {
157 return Objects.hash(this.requestId, this.timestamp, this.sourceName, this.eventType, this.validationEntityType,
158 this.validationTopEntityType, this.entityLink);
164 * @see java.lang.Object#equals(java.lang.Object)
167 public boolean equals(Object obj) {
168 if (!(obj instanceof GraphEventHeader)) {
170 } else if (obj == this) {
173 GraphEventHeader rhs = (GraphEventHeader) obj;
175 return new EqualsBuilder()
176 .append(requestId, rhs.requestId)
177 .append(timestamp, rhs.timestamp)
178 .append(sourceName, rhs.sourceName)
179 .append(eventType, rhs.sourceName)
180 .append(validationEntityType, rhs.validationEntityType)
181 .append(validationTopEntityType, rhs.validationTopEntityType)
182 .append(entityLink, rhs.entityLink)
190 * @see java.lang.Object#toString()
193 public String toString() {
194 return this.toJson();