2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schemaif.json.definitions;
25 import org.onap.aai.schemaif.SchemaProviderException;
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29 import com.google.gson.annotations.SerializedName;
31 public class JsonPropertySchema {
32 private static final Gson gson = new GsonBuilder().create();
35 private Boolean required;
36 private Boolean unique;
38 @SerializedName("type")
39 private String dataType;
41 private String description;
43 @SerializedName("default")
44 private String defaultValue;
46 private Map<String,String> annotations;
48 public String getName() {
52 public void setName(String name) {
56 public Boolean getRequired() {
60 public void setRequired(Boolean required) {
61 this.required = required;
64 public Boolean getUnique() {
68 public void setUnique(Boolean unique) {
72 public String getDataType() {
76 public void setDataType(String dataType) {
77 this.dataType = dataType;
80 public String getDefaultValue() {
84 public void setDefaultValue(String defaultValue) {
85 this.defaultValue = defaultValue;
88 public String getDescription() {
92 public void setDescription(String description) {
93 this.description = description;
96 public Map<String,String> getAnnotations() {
100 public void setAnnotations(Map<String,String> annotations) {
101 this.annotations = annotations;
104 public void validate() throws SchemaProviderException {
105 if ( (getName() == null) || (getName().isEmpty()) ) {
106 throw new SchemaProviderException(getName() + " property has no name");
109 if ( (getDataType() == null) || (getDataType().isEmpty()) ) {
110 throw new SchemaProviderException(getName() + " property has no type");
115 public String toJson() {
116 return gson.toJson(this);
119 public static JsonVertexSchema fromJson(String json) {
120 return gson.fromJson(json, JsonVertexSchema.class);
124 public String toString() {
125 return "JsonPropertySchema [name=" + name + ", required=" + required + ", unique=" + unique
126 + ", dataType=" + dataType + ", description=" + description + ", defaultValue="
127 + defaultValue + ", annotations=" + annotations + "]";
131 public int hashCode() {
132 final int prime = 31;
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());
145 public boolean equals(Object obj) {
150 if (getClass() != obj.getClass())
152 JsonPropertySchema other = (JsonPropertySchema) obj;
153 if (annotations == null) {
154 if (other.annotations != null)
156 } else if (!annotations.equals(other.annotations))
158 if (dataType == null) {
159 if (other.dataType != null)
161 } else if (!dataType.equals(other.dataType))
163 if (defaultValue == null) {
164 if (other.defaultValue != null)
166 } else if (!defaultValue.equals(other.defaultValue))
168 if (description == null) {
169 if (other.description != null)
171 } else if (!description.equals(other.description))
174 if (other.name != null)
176 } else if (!name.equals(other.name))
178 if (required == null) {
179 if (other.required != null)
181 } else if (!required.equals(other.required))
183 if (unique == null) {
184 if (other.unique != null)
186 } else if (!unique.equals(other.unique))