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.champ.event;
25 import java.io.IOException;
27 import org.onap.aai.champ.model.ChampObject;
28 import org.onap.aai.champ.model.ChampObjectIndex;
29 import org.onap.aai.champ.model.ChampPartition;
30 import org.onap.aai.champ.model.ChampRelationship;
31 import org.onap.aai.champ.model.ChampRelationshipIndex;
33 import com.fasterxml.jackson.annotation.JsonInclude.Include;
34 import com.fasterxml.jackson.core.JsonParseException;
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.JsonMappingException;
37 import com.fasterxml.jackson.databind.ObjectMapper;
40 public class ChampEvent {
42 public enum ChampOperation {
48 private static ObjectMapper mapper = new ObjectMapper();
50 private ChampOperation operation;
51 private long timestamp;
52 private ChampObject vertex = null;
53 private ChampRelationship relationship = null;
54 private ChampPartition partition = null;
55 private ChampObjectIndex objectIndex = null;
56 private ChampRelationshipIndex relationshipIndex = null;
59 public static Builder builder() {
63 public ChampOperation getOperation() {
67 public void setOperation(ChampOperation operation) {
68 this.operation = operation;
71 public long getTimestamp() {
75 public void setTimestamp(long timestamp) {
76 this.timestamp = timestamp;
79 public ChampObject getVertex() {
83 public void setVertex(ChampObject vertex) {
87 public ChampRelationship getRelationship() {
91 public void setRelationship(ChampRelationship relationship) {
92 this.relationship = relationship;
95 public ChampPartition getPartition() {
99 public void setPartition(ChampPartition partition) {
100 this.partition = partition;
103 public ChampObjectIndex getObjectIndex() {
107 public void setObjectIndex(ChampObjectIndex index) {
108 this.objectIndex = index;
111 public ChampRelationshipIndex getRelationshipIndex() {
112 return relationshipIndex;
115 public void setRelationshipIndex(ChampRelationshipIndex relationshipIndex) {
116 this.relationshipIndex = relationshipIndex;
119 public String toJson() {
121 ObjectMapper mapper = new ObjectMapper();
122 mapper.setSerializationInclusion(Include.NON_NULL);
125 return mapper.writeValueAsString(this);
126 } catch (JsonProcessingException e) {
127 return "Unmarshallable: " + e.getMessage();
131 public static ChampEvent fromJson(String json) throws JsonParseException, JsonMappingException, IOException {
133 mapper.setSerializationInclusion(Include.NON_NULL);
134 return mapper.readValue(json, ChampEvent.class);
137 public String toString() {
141 public static class Builder {
143 ChampEvent event = null;
147 event = new ChampEvent();
150 public Builder operation(ChampOperation operation) {
151 event.setOperation(operation);
155 public Builder entity(ChampObject entity) {
156 event.setVertex(entity);
160 public Builder entity(ChampRelationship relationship) {
161 event.relationship = relationship;
165 public Builder entity(ChampPartition partition) {
166 event.partition = partition;
170 public Builder entity(ChampObjectIndex index) {
171 event.objectIndex = index;
175 public Builder entity(ChampRelationshipIndex relationshipIndex) {
176 event.relationshipIndex = relationshipIndex;
180 public ChampEvent build() {
182 event.setTimestamp(System.currentTimeMillis());