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.fasterxml.jackson.annotation.JsonInclude.Include;
31 import com.fasterxml.jackson.annotation.JsonProperty;
32 import com.fasterxml.jackson.core.JsonProcessingException;
33 import com.fasterxml.jackson.databind.ObjectMapper;
35 public class ChampEventHeader {
37 private static final String SOURCE_NAME = "CHAMP";
39 public enum EventType {
40 UPDATE_RESULT("update-result"),
41 UPDATE_NOTIFICATION("update-notification-raw");
43 private final String name;
45 EventType(String name) {
49 public String getName() {
54 @JsonProperty("request-id")
55 private String requestId;
57 private String timestamp;
59 @JsonProperty("source-name")
60 private String sourceName;
62 @JsonProperty("event-type")
63 private String eventType;
65 @JsonProperty("validation-entity-type")
66 private String validationEntityType;
68 @JsonProperty("validation-top-entity-type")
69 private String validationTopEntityType;
71 @JsonProperty("entity-link")
72 private String entityLink;
74 public static class Builder {
76 private final EventType eventType;
78 private String requestId;
79 private String validationEntityType;
80 private String validationTopEntityType;
81 private String entityLink;
83 public Builder(EventType eventType) {
84 this.eventType = eventType;
87 public Builder requestId(String val) {
92 public Builder validationEntityType(String val) {
93 validationEntityType = val;
97 public Builder validationTopEntityType(String val) {
98 validationTopEntityType = val;
102 public Builder entityLink(String val) {
107 public ChampEventHeader build() {
108 return new ChampEventHeader(this);
112 private ChampEventHeader(Builder builder) {
113 requestId = builder.requestId != null ? builder.requestId : UUID.randomUUID().toString();
114 timestamp = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX").withZone(ZoneOffset.UTC).format(Instant.now());
115 sourceName = SOURCE_NAME;
116 eventType = builder.eventType.getName();
118 validationEntityType = builder.validationEntityType;
119 validationTopEntityType = builder.validationTopEntityType;
120 entityLink = builder.entityLink;
124 * Serializes this object into a JSON string representation.
126 * @return a JSON format string representation of this object.
128 public String toJson() {
129 ObjectMapper mapper = new ObjectMapper();
130 mapper.setSerializationInclusion(Include.NON_NULL);
133 return mapper.writeValueAsString(this);
134 } catch (JsonProcessingException e) {
135 return "Unmarshallable: " + e.getMessage();
139 ///////////////////////////////////////////////////////////////////////////
140 // GETTERS AND SETTERS
141 ///////////////////////////////////////////////////////////////////////////
143 public String getRequestId() {
147 public void setRequestId(String requestId) {
148 this.requestId = requestId;
151 public String getTimestamp() {
155 public void setTimestamp(String timestamp) {
156 this.timestamp = timestamp;
159 public String getSourceName() {
163 public void setSourceName(String sourceName) {
164 this.sourceName = sourceName;
167 public String getEventType() {
171 public void setEventType(String eventType) {
172 this.eventType = eventType;
175 public String getValidationEntityType() {
176 return validationEntityType;
179 public void setValidationEntityType(String validationEntityType) {
180 this.validationEntityType = validationEntityType;
183 public String getValidationTopEntityType() {
184 return validationTopEntityType;
187 public void setValidationTopEntityType(String validationTopEntityType) {
188 this.validationTopEntityType = validationTopEntityType;
191 public String getEntityLink() {
195 public void setEntityLink(String entityLink) {
196 this.entityLink = entityLink;
199 ///////////////////////////////////////////////////////////////////////////
201 ///////////////////////////////////////////////////////////////////////////
206 * @see java.lang.Object#hashCode()
209 public int hashCode() {
210 return Objects.hash(this.requestId, this.timestamp, this.sourceName, this.eventType, this.validationEntityType,
211 this.validationTopEntityType, this.entityLink);
217 * @see java.lang.Object#equals(java.lang.Object)
220 public boolean equals(Object obj) {
221 if (!(obj instanceof ChampEventHeader)) {
223 } else if (obj == this) {
226 ChampEventHeader rhs = (ChampEventHeader) obj;
228 return new EqualsBuilder()
229 .append(requestId, rhs.requestId)
230 .append(timestamp, rhs.timestamp)
231 .append(sourceName, rhs.sourceName)
232 .append(eventType, rhs.eventType)
233 .append(validationEntityType, rhs.validationEntityType)
234 .append(validationTopEntityType, rhs.validationTopEntityType)
235 .append(entityLink, rhs.entityLink)
243 * @see java.lang.Object#toString()
246 public String toString() {
247 return this.toJson();