[AAI] Fix doc config files
[aai/aai-common.git] / aai-schema-abstraction / src / main / java / org / onap / aai / schemaif / json / definitions / DataTypeDefinition.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
25 import org.onap.aai.schemaif.SchemaProviderException;
26
27 import com.google.gson.Gson;
28 import com.google.gson.GsonBuilder;
29
30 public class DataTypeDefinition {
31     private static final Gson gson = new GsonBuilder().create();
32     
33     private String name;
34     private String description;
35     private List<JsonPropertySchema> properties;
36     
37     public String getName() {
38         return name;
39     }
40
41     public void setName(String name) {
42         this.name = name;
43     }
44
45     public String getDescription() {
46         return description;
47     }
48
49     public void setDescription(String description) {
50         this.description = description;
51     }
52
53     public List<JsonPropertySchema> getProperties() {
54         return properties;
55     }
56
57     public void setProperties(List<JsonPropertySchema> properties) {
58         this.properties = properties;
59     }
60     
61     public void validate() throws SchemaProviderException {
62         if ( (getName() == null) || (getName().isEmpty()) ) {
63             throw new SchemaProviderException("Type definition missing a name");
64         }
65
66         if (getProperties() != null) {
67             for (JsonPropertySchema propSchema : getProperties()) {
68                 propSchema.validate();
69             }
70         }
71     }
72     
73     public String toJson() {
74         return gson.toJson(this);
75     }
76     
77     public static DataTypeDefinition fromJson(String json) {
78         return gson.fromJson(json, DataTypeDefinition.class);
79     }
80
81     @Override
82     public String toString() {
83         return "DataTypeDefinition [name=" + name + ", description=" + description + ", properties="
84             + properties + "]";
85     }
86
87     @Override
88     public int hashCode() {
89         final int prime = 31;
90         int result = 1;
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());
94         return result;
95     }
96
97     @Override
98     public boolean equals(Object obj) {
99         if (this == obj)
100             return true;
101         if (obj == null)
102             return false;
103         if (getClass() != obj.getClass())
104             return false;
105         DataTypeDefinition other = (DataTypeDefinition) obj;
106         if (description == null) {
107             if (other.description != null)
108                 return false;
109         } else if (!description.equals(other.description))
110             return false;
111         if (name == null) {
112             if (other.name != null)
113                 return false;
114         } else if (!name.equals(other.name))
115             return false;
116         if (properties == null) {
117             if (other.properties != null)
118                 return false;
119         } else if (!properties.equals(other.properties))
120             return false;
121         return true;
122     }
123     
124     
125 }