2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2019 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2019 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=========================================================
22 package org.onap.aai.schemaif.json.definitions;
24 import com.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
29 import org.onap.aai.schemaif.SchemaProviderException;
31 public class JsonEdgeSchema {
32 private static final Gson gson = new GsonBuilder().create();
37 private Map<String, String> annotations;
39 public String getFrom() {
43 public void setFrom(String from) {
47 public String getTo() {
51 public void setTo(String to) {
55 public String getLabel() {
59 public void setLabel(String label) {
63 public Map<String, String> getAnnotations() {
67 public void setAnnotations(Map<String, String> annotations) {
68 this.annotations = annotations;
71 public void validate() throws SchemaProviderException {
72 if ((getTo() == null) || (getTo().isEmpty())) {
73 throw new SchemaProviderException("Edge definition missing 'to'");
76 if ((getFrom() == null) || (getFrom().isEmpty())) {
77 throw new SchemaProviderException("Edge definition missing 'from'");
80 if ((getLabel() == null) || (getLabel().isEmpty())) {
81 throw new SchemaProviderException("Edge definition missing 'label'");
85 public String toJson() {
86 return gson.toJson(this);
89 public static JsonEdgeSchema fromJson(String json) {
90 return gson.fromJson(json, JsonEdgeSchema.class);
94 public String toString() {
95 return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations=" + annotations
100 public int hashCode() {
101 final int prime = 31;
103 result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
104 result = prime * result + ((from == null) ? 0 : from.hashCode());
105 result = prime * result + ((label == null) ? 0 : label.hashCode());
106 result = prime * result + ((to == null) ? 0 : to.hashCode());
111 public boolean equals(Object obj) {
116 if (getClass() != obj.getClass())
118 JsonEdgeSchema other = (JsonEdgeSchema) obj;
119 if (annotations == null) {
120 if (other.annotations != null)
122 } else if (!annotations.equals(other.annotations))
125 if (other.from != null)
127 } else if (!from.equals(other.from))
130 if (other.label != null)
132 } else if (!label.equals(other.label))
135 if (other.to != null)
137 } else if (!to.equals(other.to))