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=========================================================
22 package org.onap.aai.schemaif.json.definitions;
24 import com.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
27 import java.util.List;
29 import org.onap.aai.schemaif.SchemaProviderException;
31 public class DataTypeDefinition {
32 private static final Gson gson = new GsonBuilder().create();
35 private String description;
36 private List<JsonPropertySchema> properties;
38 public String getName() {
42 public void setName(String name) {
46 public String getDescription() {
50 public void setDescription(String description) {
51 this.description = description;
54 public List<JsonPropertySchema> getProperties() {
58 public void setProperties(List<JsonPropertySchema> properties) {
59 this.properties = properties;
62 public void validate() throws SchemaProviderException {
63 if ((getName() == null) || (getName().isEmpty())) {
64 throw new SchemaProviderException("Type definition missing a name");
67 if (getProperties() != null) {
68 for (JsonPropertySchema propSchema : getProperties()) {
69 propSchema.validate();
74 public String toJson() {
75 return gson.toJson(this);
78 public static DataTypeDefinition fromJson(String json) {
79 return gson.fromJson(json, DataTypeDefinition.class);
83 public String toString() {
84 return "DataTypeDefinition [name=" + name + ", description=" + description + ", properties=" + properties + "]";
88 public int hashCode() {
91 result = prime * result + ((description == null) ? 0 : description.hashCode());
92 result = prime * result + ((name == null) ? 0 : name.hashCode());
93 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
98 public boolean equals(Object obj) {
103 if (getClass() != obj.getClass())
105 DataTypeDefinition other = (DataTypeDefinition) obj;
106 if (description == null) {
107 if (other.description != null)
109 } else if (!description.equals(other.description))
112 if (other.name != null)
114 } else if (!name.equals(other.name))
116 if (properties == null) {
117 if (other.properties != null)
119 } else if (!properties.equals(other.properties))