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 / JsonPropertySchema.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 import com.google.gson.annotations.SerializedName;
27
28 import java.util.Map;
29
30 import org.onap.aai.schemaif.SchemaProviderException;
31
32 public class JsonPropertySchema {
33     private static final Gson gson = new GsonBuilder().create();
34
35     private String name;
36     private Boolean required;
37     private Boolean unique;
38
39     @SerializedName("type")
40     private String dataType;
41
42     private String description;
43
44     @SerializedName("default")
45     private String defaultValue;
46
47     private Map<String, String> annotations;
48
49     public String getName() {
50         return name;
51     }
52
53     public void setName(String name) {
54         this.name = name;
55     }
56
57     public Boolean getRequired() {
58         return required;
59     }
60
61     public void setRequired(Boolean required) {
62         this.required = required;
63     }
64
65     public Boolean getUnique() {
66         return unique;
67     }
68
69     public void setUnique(Boolean unique) {
70         this.unique = unique;
71     }
72
73     public String getDataType() {
74         return dataType;
75     }
76
77     public void setDataType(String dataType) {
78         this.dataType = dataType;
79     }
80
81     public String getDefaultValue() {
82         return defaultValue;
83     }
84
85     public void setDefaultValue(String defaultValue) {
86         this.defaultValue = defaultValue;
87     }
88
89     public String getDescription() {
90         return description;
91     }
92
93     public void setDescription(String description) {
94         this.description = description;
95     }
96
97     public Map<String, String> getAnnotations() {
98         return annotations;
99     }
100
101     public void setAnnotations(Map<String, String> annotations) {
102         this.annotations = annotations;
103     }
104
105     public void validate() throws SchemaProviderException {
106         if ((getName() == null) || (getName().isEmpty())) {
107             throw new SchemaProviderException(getName() + " property has no name");
108         }
109
110         if ((getDataType() == null) || (getDataType().isEmpty())) {
111             throw new SchemaProviderException(getName() + " property has no type");
112         }
113     }
114
115     public String toJson() {
116         return gson.toJson(this);
117     }
118
119     public static JsonVertexSchema fromJson(String json) {
120         return gson.fromJson(json, JsonVertexSchema.class);
121     }
122
123     @Override
124     public String toString() {
125         return "JsonPropertySchema [name=" + name + ", required=" + required + ", unique=" + unique + ", dataType="
126                 + dataType + ", description=" + description + ", defaultValue=" + defaultValue + ", annotations="
127                 + annotations + "]";
128     }
129
130     @Override
131     public int hashCode() {
132         final int prime = 31;
133         int result = 1;
134         result = prime * result + ((annotations == null) ? 0 : annotations.hashCode());
135         result = prime * result + ((dataType == null) ? 0 : dataType.hashCode());
136         result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
137         result = prime * result + ((description == null) ? 0 : description.hashCode());
138         result = prime * result + ((name == null) ? 0 : name.hashCode());
139         result = prime * result + ((required == null) ? 0 : required.hashCode());
140         result = prime * result + ((unique == null) ? 0 : unique.hashCode());
141         return result;
142     }
143
144     @Override
145     public boolean equals(Object obj) {
146         if (this == obj)
147             return true;
148         if (obj == null)
149             return false;
150         if (getClass() != obj.getClass())
151             return false;
152         JsonPropertySchema other = (JsonPropertySchema) obj;
153         if (annotations == null) {
154             if (other.annotations != null)
155                 return false;
156         } else if (!annotations.equals(other.annotations))
157             return false;
158         if (dataType == null) {
159             if (other.dataType != null)
160                 return false;
161         } else if (!dataType.equals(other.dataType))
162             return false;
163         if (defaultValue == null) {
164             if (other.defaultValue != null)
165                 return false;
166         } else if (!defaultValue.equals(other.defaultValue))
167             return false;
168         if (description == null) {
169             if (other.description != null)
170                 return false;
171         } else if (!description.equals(other.description))
172             return false;
173         if (name == null) {
174             if (other.name != null)
175                 return false;
176         } else if (!name.equals(other.name))
177             return false;
178         if (required == null) {
179             if (other.required != null)
180                 return false;
181         } else if (!required.equals(other.required))
182             return false;
183         if (unique == null) {
184             if (other.unique != null)
185                 return false;
186         } else if (!unique.equals(other.unique))
187             return false;
188         return true;
189     }
190
191 }