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 / definitions / PropertySchema.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.definitions;
23
24 import java.util.Map;
25
26 import org.onap.aai.schemaif.SchemaProviderException;
27 import org.onap.aai.schemaif.definitions.types.DataType;
28
29 public class PropertySchema {
30     protected String name;
31     protected DataType dataType;
32     protected Boolean required;
33     protected String defaultValue;
34     protected Boolean unique;
35     protected Boolean isReserved;
36     protected Map<String, String> annotations;
37
38     public String getName() {
39         return name;
40     }
41
42     public DataType getDataType() {
43         return dataType;
44     }
45
46     public Boolean isRequired() {
47         return required;
48     }
49
50     public Boolean isKey() {
51         return (unique && required);
52     }
53
54     public Boolean isUnique() {
55         return unique;
56     }
57
58     public String getDefaultValue() {
59         return defaultValue;
60     }
61
62     public Boolean isReserved() {
63         return isReserved;
64     }
65
66     public String getAnnotationValue(String annotation) {
67         return annotations.get(annotation.toLowerCase());
68     }
69
70     public Map<String, String> getAnnotations() {
71         return annotations;
72     }
73
74     public Object validateValue(String value) throws SchemaProviderException {
75         Object obj = dataType.validateValue(value);
76         if (obj == null) {
77             throw new SchemaProviderException("Invalid value for porperty '" + name + "': " + value);
78         }
79
80         return obj;
81     }
82
83     public String toString() {
84         StringBuilder sb = new StringBuilder();
85         sb.append("    property: " + getName() + "\n");
86         sb.append("      datatype: " + dataType.toString() + "\n");
87         sb.append("      required: " + isRequired() + "\n");
88         sb.append("      key: " + isKey() + "\n");
89         sb.append("      reserved: " + isReserved() + "\n");
90         sb.append("      default: " + getDefaultValue() + "\n");
91         sb.append("      annotations: " + "\n");
92
93         for (String annotation : annotations.keySet()) {
94             sb.append("        " + annotation + ": " + annotations.get(annotation) + "\n");
95         }
96
97         return sb.toString();
98     }
99 }