[AAI] Fix doc config files
[aai/aai-common.git] / aai-schema-abstraction / src / main / java / org / onap / aai / schemaif / json / definitions / JsonVertexSchema.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 import java.util.List;
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 JsonVertexSchema {
32     private static final Gson gson = new GsonBuilder().create();
33     
34     private String name;
35     private String description;
36     private List<JsonPropertySchema> properties;
37     private Map<String,String> annotations;
38     
39     public String getName() {
40         return name;
41     }
42
43     public void setName(String name) {
44         this.name = name;
45     }
46
47     public String getDescription() {
48         return description;
49     }
50
51     public void setDescription(String description) {
52         this.description = description;
53     }
54
55     public List<JsonPropertySchema> getProperties() {
56         return properties;
57     }
58
59     public void setProperties(List<JsonPropertySchema> properties) {
60         this.properties = properties;
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 ( (getName() == null) || (getName().isEmpty()) ) {
73             throw new SchemaProviderException("Node definition missing a name");
74         }
75
76         if (getProperties() != null) {
77             for (JsonPropertySchema propSchema : getProperties()) {
78                 propSchema.validate();
79             }
80         }
81     }
82     
83     public String toJson() {
84         return gson.toJson(this);
85     }
86     
87     public static JsonVertexSchema fromJson(String json) {
88         return gson.fromJson(json, JsonVertexSchema.class);
89     }
90
91     @Override
92     public String toString() {
93         return "JsonVertexSchema [name=" + name + ", description=" + description + ", properties="
94             + properties + ", annotations=" + annotations + "]";
95     }
96
97     @Override
98     public int hashCode() {
99         final int prime = 31;
100         int result = 1;
101         result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
102         result = prime * result + ((description == null) ? 0 : description.hashCode());
103         result = prime * result + ((name == null) ? 0 : name.hashCode());
104         result = prime * result + ((properties == null) ? 0 : properties.hashCode());
105         return result;
106     }
107
108     @Override
109     public boolean equals(Object obj) {
110         if (this == obj)
111             return true;
112         if (obj == null)
113             return false;
114         if (getClass() != obj.getClass())
115             return false;
116         JsonVertexSchema other = (JsonVertexSchema) obj;
117         if (annotations == null) {
118             if (other.annotations != null)
119                 return false;
120         } else if (!annotations.equals(other.annotations))
121             return false;
122         if (description == null) {
123             if (other.description != null)
124                 return false;
125         } else if (!description.equals(other.description))
126             return false;
127         if (name == null) {
128             if (other.name != null)
129                 return false;
130         } else if (!name.equals(other.name))
131             return false;
132         if (properties == null) {
133             if (other.properties != null)
134                 return false;
135         } else if (!properties.equals(other.properties))
136             return false;
137         return true;
138     }
139     
140     
141 }