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.aai.spike.event.outgoing;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
25 import com.google.gson.JsonElement;
26 import com.google.gson.annotations.SerializedName;
27 import org.onap.aai.spike.exception.SpikeException;
30 * This class provides a generic representation of a Vertex as provided by the graph data store.
33 public class SpikeVertex {
36 * The unique identifier used to identify this vertex in the graph data store.
38 @SerializedName("key")
41 @SerializedName("schema-version")
42 private String modelVersion;
44 /** Type label assigned to this vertex. */
47 /** Map of all of the properties assigned to this vertex. */
48 private JsonElement properties;
50 /** Marshaller/unmarshaller for converting to/from JSON. */
51 private static final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
53 public String getId() {
57 public void setId(String id) {
61 public String getType() {
65 public void setType(String type) {
69 public JsonElement getProperties() {
73 public void setProperties(JsonElement properties) {
74 this.properties = properties;
77 public String getModelVersion() {
81 public void setModelVersion(String modelVersion) {
82 this.modelVersion = modelVersion;
86 * Unmarshalls this Vertex object into a JSON string.
88 * @return - A JSON format string representation of this Vertex.
90 public String toJson() {
91 return gson.toJson(this);
95 * Marshalls the provided JSON string into a Vertex object.
97 * @param json - The JSON string to produce the Vertex from.
99 * @return - A Vertex object.
101 * @throws SpikeException
103 public static SpikeVertex fromJson(String json) throws SpikeException {
107 // Make sure that we were actually provided a non-empty string
110 if (json == null || json.isEmpty()) {
111 throw new SpikeException("Empty or null JSON string.");
114 // Marshall the string into a Vertex object.
115 return gson.fromJson(json, SpikeVertex.class);
117 } catch (Exception ex) {
118 throw new SpikeException("Unable to parse JSON string: " + ex.getMessage());
123 public String toString() {