Merge "[AAI] Fix doc config files"
[aai/aai-common.git] / aai-schema-abstraction / src / main / java / org / onap / aai / schemaif / json / definitions / JsonEdgeSchema.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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  */
21
22 package org.onap.aai.schemaif.json.definitions;
23
24 import com.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
26
27 import java.util.Map;
28
29 import org.onap.aai.schemaif.SchemaProviderException;
30
31 public class JsonEdgeSchema {
32     private static final Gson gson = new GsonBuilder().create();
33
34     private String from;
35     private String to;
36     private String label;
37     private Map<String, String> annotations;
38
39     public String getFrom() {
40         return from;
41     }
42
43     public void setFrom(String from) {
44         this.from = from;
45     }
46
47     public String getTo() {
48         return to;
49     }
50
51     public void setTo(String to) {
52         this.to = to;
53     }
54
55     public String getLabel() {
56         return label;
57     }
58
59     public void setLabel(String label) {
60         this.label = label;
61     }
62
63     public Map<String, String> getAnnotations() {
64         return annotations;
65     }
66
67     public void setAnnotations(Map<String, String> annotations) {
68         this.annotations = annotations;
69     }
70
71     public void validate() throws SchemaProviderException {
72         if ((getTo() == null) || (getTo().isEmpty())) {
73             throw new SchemaProviderException("Edge definition missing 'to'");
74         }
75
76         if ((getFrom() == null) || (getFrom().isEmpty())) {
77             throw new SchemaProviderException("Edge definition missing 'from'");
78         }
79
80         if ((getLabel() == null) || (getLabel().isEmpty())) {
81             throw new SchemaProviderException("Edge definition missing 'label'");
82         }
83     }
84
85     public String toJson() {
86         return gson.toJson(this);
87     }
88
89     public static JsonEdgeSchema fromJson(String json) {
90         return gson.fromJson(json, JsonEdgeSchema.class);
91     }
92
93     @Override
94     public String toString() {
95         return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations=" + annotations
96                 + "]";
97     }
98
99     @Override
100     public int hashCode() {
101         final int prime = 31;
102         int result = 1;
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());
107         return result;
108     }
109
110     @Override
111     public boolean equals(Object obj) {
112         if (this == obj)
113             return true;
114         if (obj == null)
115             return false;
116         if (getClass() != obj.getClass())
117             return false;
118         JsonEdgeSchema other = (JsonEdgeSchema) obj;
119         if (annotations == null) {
120             if (other.annotations != null)
121                 return false;
122         } else if (!annotations.equals(other.annotations))
123             return false;
124         if (from == null) {
125             if (other.from != null)
126                 return false;
127         } else if (!from.equals(other.from))
128             return false;
129         if (label == null) {
130             if (other.label != null)
131                 return false;
132         } else if (!label.equals(other.label))
133             return false;
134         if (to == null) {
135             if (other.to != null)
136                 return false;
137         } else if (!to.equals(other.to))
138             return false;
139         return true;
140     }
141
142 }