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;
25 import java.io.IOException;
27 import org.onap.aai.champcore.model.ChampObject;
28 import org.onap.aai.champcore.model.ChampObjectIndex;
29 import org.onap.aai.champcore.model.ChampPartition;
30 import org.onap.aai.champcore.model.ChampRelationship;
31 import org.onap.aai.champcore.model.ChampRelationshipIndex;
33 import com.fasterxml.jackson.annotation.JsonInclude.Include;
34 import com.fasterxml.jackson.annotation.JsonProperty;
35 import com.fasterxml.jackson.core.JsonParseException;
36 import com.fasterxml.jackson.core.JsonProcessingException;
37 import com.fasterxml.jackson.databind.JsonMappingException;
38 import com.fasterxml.jackson.databind.ObjectMapper;
41 public class ChampEvent {
43 public enum ChampOperation {
49 private static ObjectMapper mapper = new ObjectMapper();
51 private ChampOperation operation;
52 private long timestamp;
53 private String transactionId = null;
54 private ChampObject vertex = null;
55 private ChampRelationship relationship = null;
56 private ChampPartition partition = null;
57 private ChampObjectIndex objectIndex = null;
58 private ChampRelationshipIndex relationshipIndex = null;
59 private String dbTransactionId = null;
62 public static Builder builder() {
66 public ChampOperation getOperation() {
70 public void setOperation(ChampOperation operation) {
71 this.operation = operation;
74 public long getTimestamp() {
78 public void setTimestamp(long timestamp) {
79 this.timestamp = timestamp;
82 @JsonProperty("transaction-id")
83 public String getTransactionId() {
87 public void setTransactionId(String transactionId) {
88 this.transactionId = transactionId;
91 public ChampObject getVertex() {
95 public void setVertex(ChampObject vertex) {
99 public ChampRelationship getRelationship() {
103 public void setRelationship(ChampRelationship relationship) {
104 this.relationship = relationship;
107 public ChampPartition getPartition() {
111 public void setPartition(ChampPartition partition) {
112 this.partition = partition;
115 public ChampObjectIndex getObjectIndex() {
119 public void setObjectIndex(ChampObjectIndex index) {
120 this.objectIndex = index;
123 public ChampRelationshipIndex getRelationshipIndex() {
124 return relationshipIndex;
127 public void setRelationshipIndex(ChampRelationshipIndex relationshipIndex) {
128 this.relationshipIndex = relationshipIndex;
131 @JsonProperty("database-transaction-id")
132 public String getDbTransactionId () { return dbTransactionId; }
135 public void setDbTransactionId ( String id ) { this.dbTransactionId = id; }
139 public String toJson() {
141 ObjectMapper mapper = new ObjectMapper();
142 mapper.setSerializationInclusion(Include.NON_NULL);
145 return mapper.writeValueAsString(this);
146 } catch (JsonProcessingException e) {
147 return "Unmarshallable: " + e.getMessage();
151 public static ChampEvent fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
153 mapper.setSerializationInclusion(Include.NON_NULL);
154 return mapper.readValue(json, ChampEvent.class);
157 public String toString() {
162 public static class Builder {
164 ChampEvent event = null;
168 event = new ChampEvent();
171 public Builder operation(ChampOperation operation) {
172 event.setOperation(operation);
176 public Builder entity(ChampObject entity) {
177 event.setVertex(entity);
181 public Builder entity(ChampRelationship relationship) {
182 event.relationship = relationship;
186 public Builder entity(ChampPartition partition) {
187 event.partition = partition;
191 public Builder entity(ChampObjectIndex index) {
192 event.objectIndex = index;
196 public Builder entity(ChampRelationshipIndex relationshipIndex) {
197 event.relationshipIndex = relationshipIndex;
202 public ChampEvent build() {
204 event.setTimestamp(System.currentTimeMillis());
206 // Set a unique transaction id on this event that can be used by downstream entities
207 // for log correlation.
208 event.setTransactionId(java.util.UUID.randomUUID().toString());