[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 package org.onap.aai.schemaif.json.definitions;
22
23
24 import java.util.Map;
25
26 import org.onap.aai.schemaif.SchemaProviderException;
27
28 import com.google.gson.Gson;
29 import com.google.gson.GsonBuilder;
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     public void setFrom(String from) {
43         this.from = from;
44     }
45     
46     public String getTo() {
47         return to;
48     }
49     public void setTo(String to) {
50         this.to = to;
51     }
52     
53     public String getLabel() {
54         return label;
55     }
56     public void setLabel(String label) {
57         this.label = label;
58     }
59     
60     public Map<String,String> getAnnotations() {
61         return annotations;
62     }
63     public void setAnnotations(Map<String,String> annotations) {
64         this.annotations = annotations;
65     }
66     
67     public void validate() throws SchemaProviderException {
68         if ( (getTo() == null) || (getTo().isEmpty()) ) {
69             throw new SchemaProviderException("Edge definition missing 'to'");
70         }
71         
72         if ( (getFrom() == null) || (getFrom().isEmpty()) ) {
73             throw new SchemaProviderException("Edge definition missing 'from'");
74         }
75         
76         if ( (getLabel() == null) || (getLabel().isEmpty()) ) {
77             throw new SchemaProviderException("Edge definition missing 'label'");
78         }
79     }
80     
81     public String toJson() {
82         return gson.toJson(this);
83     }
84     
85     public static JsonEdgeSchema fromJson(String json) {
86         return gson.fromJson(json, JsonEdgeSchema.class);
87     }
88     @Override
89     public String toString() {
90         return "JsonEdgeSchema [from=" + from + ", to=" + to + ", label=" + label + ", annotations="
91             + annotations + "]";
92     }
93     @Override
94     public int hashCode() {
95         final int prime = 31;
96         int result = 1;
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());
101         return result;
102     }
103     @Override
104     public boolean equals(Object obj) {
105         if (this == obj)
106             return true;
107         if (obj == null)
108             return false;
109         if (getClass() != obj.getClass())
110             return false;
111         JsonEdgeSchema other = (JsonEdgeSchema) obj;
112         if (annotations == null) {
113             if (other.annotations != null)
114                 return false;
115         } else if (!annotations.equals(other.annotations))
116             return false;
117         if (from == null) {
118             if (other.from != null)
119                 return false;
120         } else if (!from.equals(other.from))
121             return false;
122         if (label == null) {
123             if (other.label != null)
124                 return false;
125         } else if (!label.equals(other.label))
126             return false;
127         if (to == null) {
128             if (other.to != null)
129                 return false;
130         } else if (!to.equals(other.to))
131             return false;
132         return true;
133     }
134     
135 }