2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 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============================================
21 package org.onap.champ.event;
23 import javax.ws.rs.core.Response.Status;
25 import com.google.gson.annotations.SerializedName;
27 public class GraphEvent {
29 public enum GraphEventOperation {
30 CREATE, UPDATE, DELETE
33 public enum GraphEventResult {
37 private GraphEventOperation operation;
39 @SerializedName("transaction-id")
40 private String transactionId;
42 @SerializedName("database-transaction-id")
43 private String dbTransactionId;
45 private long timestamp;
47 private GraphEventVertex vertex;
49 private GraphEventEdge edge;
51 private GraphEventResult result;
53 @SerializedName("error-message")
54 private String errorMessage;
56 private Status httpErrorStatus;
58 public static Builder builder(GraphEventOperation operation) {
59 return new Builder(operation);
62 public GraphEventOperation getOperation() {
66 public String getTransactionId() {
70 public String getDbTransactionId() {
71 return dbTransactionId;
74 public void setDbTransactionId(String id) {
78 public long getTimestamp() {
82 public GraphEventVertex getVertex() {
86 public GraphEventEdge getEdge() {
90 public GraphEventResult getResult() {
94 public String getErrorMessage() {
98 public void setResult(GraphEventResult result) {
103 public Status getHttpErrorStatus() {
104 return httpErrorStatus;
107 public void setHttpErrorStatus(Status httpErrorStatus) {
108 this.httpErrorStatus = httpErrorStatus;
111 public void setTimestamp(long timestamp) {
112 this.timestamp = timestamp;
115 public void setErrorMessage(String errorMessage) {
116 this.errorMessage = errorMessage;
119 public void setVertex(GraphEventVertex vertex) {
120 this.vertex = vertex;
123 public void setEdge(GraphEventEdge edge) {
127 public String getObjectKey() {
128 if (this.getVertex() != null) {
129 return this.getVertex().getId();
130 } else if (this.getEdge() != null) {
131 return this.getEdge().getId();
137 public String getObjectType() {
138 if (this.getVertex() != null) {
139 return "vertex->" + this.getVertex().getType();
140 } else if (this.getEdge() != null) {
141 return "edge->" + this.getEdge().getType();
147 public static class Builder {
149 GraphEvent event = null;
151 public Builder(GraphEventOperation operation) {
152 event = new GraphEvent();
153 event.operation = operation;
156 public Builder vertex(GraphEventVertex vertex) {
157 event.vertex = vertex;
161 public Builder edge(GraphEventEdge edge) {
166 public Builder result(GraphEventResult result) {
167 event.result = result;
171 public Builder errorMessage(String errorMessage) {
172 event.errorMessage = errorMessage;
176 public Builder httpErrorStatus(Status httpErrorStatus) {
177 event.httpErrorStatus = httpErrorStatus;
181 public GraphEvent build() {
183 event.timestamp = System.currentTimeMillis();
184 event.transactionId = java.util.UUID.randomUUID().toString();