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