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=========================================================
21 package org.onap.aai.schemaif.json.definitions;
26 import org.onap.aai.schemaif.SchemaProviderException;
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
31 public class JsonEdgeSchema {
32 private static final Gson gson = new GsonBuilder().create();
37 private Map<String,String> annotations;
39 public String getFrom() {
42 public void setFrom(String from) {
46 public String getTo() {
49 public void setTo(String to) {
53 public String getLabel() {
56 public void setLabel(String label) {
60 public Map<String,String> getAnnotations() {
63 public void setAnnotations(Map<String,String> annotations) {
64 this.annotations = annotations;
67 public void validate() throws SchemaProviderException {
68 if ( (getTo() == null) || (getTo().isEmpty()) ) {
69 throw new SchemaProviderException("Edge definition missing 'to'");
72 if ( (getFrom() == null) || (getFrom().isEmpty()) ) {
73 throw new SchemaProviderException("Edge definition missing 'from'");
76 if ( (getLabel() == null) || (getLabel().isEmpty()) ) {
77 throw new SchemaProviderException("Edge definition missing 'label'");
81 public String toJson() {
82 return gson.toJson(this);
85 public static JsonEdgeSchema fromJson(String json) {
86 return gson.fromJson(json, JsonEdgeSchema.class);
89 public String toString() {
90 return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations="
94 public int hashCode() {
97 result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
98 result = prime * result + ((from == null) ? 0 : from.hashCode());
99 result = prime * result + ((label == null) ? 0 : label.hashCode());
100 result = prime * result + ((to == null) ? 0 : to.hashCode());
104 public boolean equals(Object obj) {
109 if (getClass() != obj.getClass())
111 JsonEdgeSchema other = (JsonEdgeSchema) obj;
112 if (annotations == null) {
113 if (other.annotations != null)
115 } else if (!annotations.equals(other.annotations))
118 if (other.from != null)
120 } else if (!from.equals(other.from))
123 if (other.label != null)
125 } else if (!label.equals(other.label))
128 if (other.to != null)
130 } else if (!to.equals(other.to))