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.aai.champcore.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 ChampEventHeader {
36 private static final String SOURCE_NAME = "CHAMP";
38 public enum EventType {
39 UPDATE_RESULT("update-result"),
40 UPDATE_NOTIFICATION("update-notification-raw");
42 private final String name;
44 EventType(String name) {
48 public String getName() {
53 @SerializedName("request-id")
54 private String requestId;
56 private String timestamp;
58 @SerializedName("source-name")
59 private String sourceName;
61 @SerializedName("event-type")
62 private String eventType;
64 @SerializedName("validation-entity-type")
65 private String validationEntityType;
67 @SerializedName("validation-top-entity-type")
68 private String validationTopEntityType;
70 @SerializedName("entity-link")
71 private String entityLink;
73 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
75 public static class Builder {
77 private final EventType eventType;
79 private String requestId;
80 private String validationEntityType;
81 private String validationTopEntityType;
82 private String entityLink;
84 public Builder(EventType eventType) {
85 this.eventType = eventType;
88 public Builder requestId(String val) {
93 public Builder validationEntityType(String val) {
94 validationEntityType = val;
98 public Builder validationTopEntityType(String val) {
99 validationTopEntityType = val;
103 public Builder entityLink(String val) {
108 public ChampEventHeader build() {
109 return new ChampEventHeader(this);
113 private ChampEventHeader(Builder builder) {
114 requestId = builder.requestId != null ? builder.requestId : UUID.randomUUID().toString();
115 timestamp = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
116 sourceName = SOURCE_NAME;
117 eventType = builder.eventType.getName();
119 validationEntityType = builder.validationEntityType;
120 validationTopEntityType = builder.validationTopEntityType;
121 entityLink = builder.entityLink;
125 * Serializes this object into a JSON string representation.
127 * @return a JSON format string representation of this object.
129 public String toJson() {
130 return gson.toJson(this);
133 ///////////////////////////////////////////////////////////////////////////
134 // GETTERS AND SETTERS
135 ///////////////////////////////////////////////////////////////////////////
137 public String getRequestId() {
141 public void setRequestId(String requestId) {
142 this.requestId = requestId;
145 public String getTimestamp() {
149 public void setTimestamp(String timestamp) {
150 this.timestamp = timestamp;
153 public String getSourceName() {
157 public void setSourceName(String sourceName) {
158 this.sourceName = sourceName;
161 public String getEventType() {
165 public void setEventType(String eventType) {
166 this.eventType = eventType;
169 public String getValidationEntityType() {
170 return validationEntityType;
173 public void setValidationEntityType(String validationEntityType) {
174 this.validationEntityType = validationEntityType;
177 public String getValidationTopEntityType() {
178 return validationTopEntityType;
181 public void setValidationTopEntityType(String validationTopEntityType) {
182 this.validationTopEntityType = validationTopEntityType;
185 public String getEntityLink() {
189 public void setEntityLink(String entityLink) {
190 this.entityLink = entityLink;
193 ///////////////////////////////////////////////////////////////////////////
195 ///////////////////////////////////////////////////////////////////////////
200 * @see java.lang.Object#hashCode()
203 public int hashCode() {
204 return Objects.hash(this.requestId, this.timestamp, this.sourceName, this.eventType, this.validationEntityType,
205 this.validationTopEntityType, this.entityLink);
211 * @see java.lang.Object#equals(java.lang.Object)
214 public boolean equals(Object obj) {
215 if (!(obj instanceof ChampEventHeader)) {
217 } else if (obj == this) {
220 ChampEventHeader rhs = (ChampEventHeader) obj;
222 return new EqualsBuilder()
223 .append(requestId, rhs.requestId)
224 .append(timestamp, rhs.timestamp)
225 .append(sourceName, rhs.sourceName)
226 .append(eventType, rhs.eventType)
227 .append(validationEntityType, rhs.validationEntityType)
228 .append(validationTopEntityType, rhs.validationTopEntityType)
229 .append(entityLink, rhs.entityLink)
237 * @see java.lang.Object#toString()
240 public String toString() {
241 return this.toJson();