2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\r
5 * Licensed under the Apache License, Version 2.0 (the "License");
\r
6 * you may not use this file except in compliance with the License.
\r
7 * You may obtain a copy of the License at
\r
9 * http://www.apache.org/licenses/LICENSE-2.0
\r
11 * Unless required by applicable law or agreed to in writing, software
\r
12 * distributed under the License is distributed on an "AS IS" BASIS,
\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
14 * See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
18 package org.onap.ccsdk.features.model.validator;
\r
20 import java.util.Map;
\r
21 import org.apache.commons.lang3.StringUtils;
\r
22 import org.onap.ccsdk.features.model.ConfigModelException;
\r
23 import org.onap.ccsdk.features.model.ValidTypes;
\r
24 import org.onap.ccsdk.features.model.data.DataType;
\r
25 import org.onap.ccsdk.features.model.data.PropertyDefinition;
\r
28 * PropertyDefinitionValidator.java Purpose: Provide Configuration Generator
\r
29 * PropertyDefinitionValidator
\r
33 public class PropertyDefinitionValidator {
\r
35 StringBuilder message = new StringBuilder();
\r
37 public PropertyDefinitionValidator(StringBuilder message) {
\r
38 this.message = message;
\r
43 * This is a validatePropertyDefinition stored in database
\r
45 * @param stDataTypes
\r
48 * @throws ConfigModelException
\r
50 @SuppressWarnings({"squid:S00112", "squid:S3776", "squid:S1192"})
\r
51 public boolean validatePropertyDefinition(Map<String, DataType> stDataTypes,
\r
52 Map<String, PropertyDefinition> properties) {
\r
54 if (stDataTypes != null && properties != null) {
\r
55 properties.forEach((propertyKey, prop) -> {
\r
56 if (propertyKey != null && prop != null) {
\r
58 String propertType = prop.getType();
\r
59 message.append("\n Validating (" + propertyKey + ") " + prop);
\r
61 if (!ValidTypes.getValidPropertType().contains(propertType)
\r
62 && !stDataTypes.containsKey(propertType)) {
\r
63 throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType
\r
64 + ") is not a valid type.");
\r
65 } else if (ValidTypes.getListPropertType().contains(propertType)) {
\r
66 if (prop.getEntrySchema() == null || StringUtils.isBlank(prop.getEntrySchema().getType())) {
\r
67 throw new ConfigModelException("Data Type (" + propertyKey + ") -> type (" + propertType
\r
68 + ") Entity Schema is not defined.");
\r
71 String entitySchemaType = prop.getEntrySchema().getType();
\r
73 if (!ValidTypes.getValidPropertType().contains(entitySchemaType)
\r
74 && !stDataTypes.containsKey(entitySchemaType)) {
\r
75 message.append("\n Present Data Type " + stDataTypes);
\r
76 throw new ConfigModelException("Data Type (" + propertyKey + ") -> type(" + propertType
\r
77 + ") -> entitySchema(" + entitySchemaType + ") is not defined.");
\r
80 } catch (ConfigModelException e) {
\r
81 throw new RuntimeException(e);
\r