VFC Property default value enforced forced to comply with restraints
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / datamodel / utils / PropertyValueConstraintValidationUtil.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.openecomp.sdc.be.datamodel.utils;
17
18 import com.fasterxml.jackson.core.JsonProcessingException;
19 import com.fasterxml.jackson.core.type.TypeReference;
20 import com.fasterxml.jackson.databind.ObjectMapper;
21 import fj.data.Either;
22 import java.io.IOException;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Objects;
29 import org.apache.commons.collections4.CollectionUtils;
30 import org.apache.commons.collections4.ListUtils;
31 import org.apache.commons.collections4.MapUtils;
32 import org.apache.commons.lang3.ArrayUtils;
33 import org.apache.commons.lang3.StringUtils;
34 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
35 import org.openecomp.sdc.be.dao.api.ActionStatus;
36 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
37 import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
38 import org.openecomp.sdc.be.model.ComponentInstanceInput;
39 import org.openecomp.sdc.be.model.DataTypeDefinition;
40 import org.openecomp.sdc.be.model.InputDefinition;
41 import org.openecomp.sdc.be.model.PropertyConstraint;
42 import org.openecomp.sdc.be.model.PropertyDefinition;
43 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
44 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
45 import org.openecomp.sdc.be.model.tosca.ToscaType;
46 import org.openecomp.sdc.be.model.tosca.constraints.ConstraintUtil;
47 import org.openecomp.sdc.be.model.tosca.constraints.LengthConstraint;
48 import org.openecomp.sdc.be.model.tosca.constraints.MaxLengthConstraint;
49 import org.openecomp.sdc.be.model.tosca.constraints.MinLengthConstraint;
50 import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintValueDoNotMatchPropertyTypeException;
51 import org.openecomp.sdc.be.model.tosca.constraints.exception.ConstraintViolationException;
52 import org.openecomp.sdc.exception.ResponseFormat;
53 import org.slf4j.Logger;
54 import org.slf4j.LoggerFactory;
55
56 public class PropertyValueConstraintValidationUtil {
57
58     private static final String UNDERSCORE = "_";
59     private static final String VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY = "%nValue provided in invalid format for %s property";
60     private static final Logger logger = LoggerFactory.getLogger(PropertyValueConstraintValidationUtil.class);
61     private static final String IGNORE_PROPERTY_VALUE_START_WITH_INPUT = "{\"get_input\":";
62     private static final String IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY = "{\"get_property\":";
63     private static final String IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE = "{\"get_attribute\":";
64     private static final String IGNORE_PROPERTY_VALUE_INPUT = "{get_input=";
65     private static final String IGNORE_PROPERTY_VALUE_PROPERTY = "{get_property=";
66     private static final String IGNORE_PROPERTY_VALUE_ATTRIBUTE = "{get_attribute=";
67     private Map<String, DataTypeDefinition> dataTypeDefinitionCache;
68     private final ObjectMapper objectMapper = new ObjectMapper();
69     private final List<String> errorMessages = new ArrayList<>();
70     private StringBuilder completePropertyName;
71     private String completeInputName;
72
73     public Either<Boolean, ResponseFormat> validatePropertyConstraints(final Collection<? extends PropertyDefinition> propertyDefinitionList,
74                                                                        final ApplicationDataTypeCache applicationDataTypeCache,
75                                                                        final String model) {
76
77         dataTypeDefinitionCache = applicationDataTypeCache.getAll(model).left().value();
78         CollectionUtils.emptyIfNull(propertyDefinitionList).stream()
79             .filter(this::isNonToscaFunctionValuePresent)
80             .forEach(this::evaluatePropertyTypeForConstraintValidation);
81         if (CollectionUtils.isNotEmpty(errorMessages)) {
82             final String errorMsgAsString = String.join(",", errorMessages);
83             logger.debug("Properties with Invalid Data: {}", errorMsgAsString);
84             return Either.right(getResponseFormatManager().getResponseFormat(ActionStatus.INVALID_PROPERTY_VALUES, errorMsgAsString));
85         }
86         return Either.left(Boolean.TRUE);
87     }
88
89     private boolean isNonToscaFunctionValuePresent(PropertyDefinition propertyDefinition) {
90         if (isValueAToscaFunction(propertyDefinition)) {
91             return false;
92         }
93         if (propertyDefinition instanceof ComponentInstanceInput) {
94             return StringUtils.isNotEmpty(propertyDefinition.getValue());
95         }
96         if (propertyDefinition instanceof InputDefinition) {
97             return StringUtils.isNotEmpty(propertyDefinition.getDefaultValue());
98         }
99         return StringUtils.isNotEmpty(propertyDefinition.getValue() != null ? propertyDefinition.getValue() : propertyDefinition.getDefaultValue());
100     }
101
102     private void evaluatePropertyTypeForConstraintValidation(PropertyDefinition propertyDefinition) {
103         if (propertyDefinition == null || propertyDefinition.getType() == null || !dataTypeDefinitionCache.containsKey(
104             propertyDefinition.getType())) {
105             errorMessages.add("\nUnsupported datatype found for property " + getCompletePropertyName(propertyDefinition));
106             return;
107         }
108         completeInputName = "";
109         completePropertyName = new StringBuilder();
110         if (propertyDefinition instanceof ComponentInstanceInput) {
111             setCompletePropertyName(propertyDefinition);
112             evaluateComplexTypeProperties(propertyDefinition);
113             return;
114         }
115         if (propertyDefinition instanceof InputDefinition) {
116             completeInputName = propertyDefinition.getName();
117             propertyDefinition = getPropertyDefinitionObjectFromInputs(propertyDefinition);
118         }
119         if (propertyDefinition != null) {
120             List<PropertyConstraint> propertyConstraints =
121                 dataTypeDefinitionCache.get(propertyDefinition.getType()).safeGetConstraints();
122             if (ToscaType.isPrimitiveType(propertyDefinition.getType())) {
123                 propertyDefinition.setConstraints(org.openecomp.sdc.be.dao.utils.CollectionUtils.merge(propertyDefinition.safeGetConstraints(),
124                     propertyConstraints.isEmpty() ? new ArrayList<>() : propertyConstraints));
125                 evaluateConstraintsOnProperty(propertyDefinition);
126             } else if (ToscaType.isCollectionType(propertyDefinition.getType())) {
127                 propertyDefinition.setConstraints(org.openecomp.sdc.be.dao.utils.CollectionUtils.merge(propertyDefinition.safeGetConstraints(),
128                     propertyConstraints.isEmpty() ? new ArrayList<>() : propertyConstraints));
129                 evaluateConstraintsOnProperty(propertyDefinition);
130                 evaluateCollectionTypeProperties(propertyDefinition);
131             } else {
132                 setCompletePropertyName(propertyDefinition);
133                 evaluateComplexTypeProperties(propertyDefinition);
134             }
135         }
136     }
137
138     private void setCompletePropertyName(PropertyDefinition propertyDefinition) {
139         if (StringUtils.isNotBlank(propertyDefinition.getUniqueId())) {
140             completePropertyName.append(propertyDefinition.getUniqueId().substring(propertyDefinition.getUniqueId().lastIndexOf('.') + 1));
141         }
142     }
143
144     private void evaluateConstraintsOnProperty(PropertyDefinition propertyDefinition) {
145         ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType());
146         if (!isValueAToscaFunction(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) {
147             for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) {
148                 try {
149                     propertyConstraint.initialize(toscaType, propertyDefinition.getSchema());
150                     propertyConstraint.validate(propertyDefinition);
151                 } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
152                     errorMessages.add(propertyConstraint.getErrorMessage(toscaType, exception, getCompletePropertyName(propertyDefinition)));
153                 } catch (IllegalArgumentException ie) {
154                     errorMessages.add(ie.getMessage());
155                 }
156             }
157         } else if (!isValueAToscaFunction(propertyDefinition) && ToscaType.isPrimitiveType(propertyDefinition.getType())
158                 && !propertyDefinition.isToscaFunction() && !toscaType.isValidValue(
159                     propertyDefinition.getValue() != null ? propertyDefinition.getValue() : propertyDefinition.getDefaultValue())) {
160             errorMessages.add(String.format("Unsupported value provided for %s property supported value type is %s.",
161                 getCompletePropertyName(propertyDefinition), toscaType.getType()));
162         }
163     }
164
165     private boolean isValueAToscaFunction(PropertyDefinition propertyDefinition) {
166         return (propertyDefinition.getToscaFunction() != null)  || (propertyDefinition.getValue() != null
167             && ((propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY)
168             || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_ATTRIBUTE)
169             || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_PROPERTY) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_INPUT))));
170     }
171
172     private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) {
173         if (ToscaType.isPrimitiveType(dataTypeDefinition.getName()) && CollectionUtils.isNotEmpty(dataTypeDefinition.getConstraints())) {
174             PropertyDefinition definition = new PropertyDefinition();
175             definition.setValue(propertyDefinition.getValue());
176             definition.setType(dataTypeDefinition.getName());
177             definition.setConstraints(dataTypeDefinition.getConstraints());
178             evaluateConstraintsOnProperty(propertyDefinition);
179         }
180     }
181
182     private void evaluateComplexTypeProperties(PropertyDefinition propertyDefinition) {
183         List<PropertyDefinition> propertyDefinitions = dataTypeDefinitionCache.get(propertyDefinition.getType()).getProperties();
184         try {
185             Map<String, Object> valueMap = MapUtils
186                 .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
187                 }));
188             if (CollectionUtils.isEmpty(propertyDefinitions)) {
189                 checkAndEvaluatePrimitiveProperty(propertyDefinition, dataTypeDefinitionCache.get(propertyDefinition.getType()));
190             } else {
191                 ListUtils.emptyIfNull(propertyDefinitions).forEach(prop -> evaluateRegularComplexType(propertyDefinition, prop, valueMap));
192             }
193         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
194             logger.debug(e.getMessage(), e);
195             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
196         }
197     }
198
199     private void evaluateRegularComplexType(PropertyDefinition propertyDefinition, PropertyDefinition prop, Map<String, Object> valueMap) {
200         try {
201             PropertyDefinition newPropertyWithValue;
202             if (valueMap.containsKey(prop.getName())) {
203                 if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
204                     for (SubPropertyToscaFunction subPropertyToscaFunction : propertyDefinition.getSubPropertyToscaFunctions()) {
205                         final List<String> path = subPropertyToscaFunction.getSubPropertyPath();
206                         if (path.size() == 1 && path.get(0).equals(prop.getName())) {
207                             return;
208                         }
209                         if (path.size() > 1) {
210                             if (path.get(0).equals(propertyDefinition.getToscaSubPath()) && path.get(1).equals(prop.getName())) {
211                                 return;
212                             }
213                         }
214                     }
215                 }
216                 if (ToscaType.isPrimitiveType(prop.getType())) {
217                     newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())), prop.getName());
218                     if (isPropertyToEvaluate(newPropertyWithValue)) {
219                         evaluateConstraintsOnProperty(newPropertyWithValue);
220                     }
221                 } else if (ToscaType.isCollectionType(prop.getType())) {
222                     newPropertyWithValue =
223                         copyPropertyWithNewValue(prop,
224                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
225                     if (isPropertyToEvaluate(newPropertyWithValue)) {
226                         evaluateCollectionTypeProperties(newPropertyWithValue);
227                     }
228                 } else {
229                     newPropertyWithValue =
230                         copyPropertyWithNewValue(prop,
231                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
232                     if (isPropertyToEvaluate(newPropertyWithValue)) {
233                         evaluateComplexTypeProperties(newPropertyWithValue);
234                     }
235                 }
236             }
237         } catch (IOException | ConstraintValueDoNotMatchPropertyTypeException e) {
238             logger.error(e.getMessage(), e);
239             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
240         }
241     }
242
243     private boolean isPropertyToEvaluate(PropertyDefinition propertyDefinition) throws ConstraintValueDoNotMatchPropertyTypeException {
244         if (Boolean.FALSE.equals(propertyDefinition.isRequired())) {
245             if (!ToscaType.isCollectionType(propertyDefinition.getType())) {
246                 return StringUtils.isNotEmpty(propertyDefinition.getValue()) &&
247                     !"null".equals(propertyDefinition.getValue());
248             } else if (ToscaType.LIST == ToscaType.isValidType(propertyDefinition.getType())) {
249                 Collection<?> list = ConstraintUtil.parseToCollection(null != propertyDefinition.getValue() ?
250                     propertyDefinition.getValue() : propertyDefinition.getDefaultValue(), new TypeReference<List<?>>() {
251                 });
252                 return CollectionUtils.isNotEmpty(list);
253             } else {
254                 Map<String, Object> valueMap = MapUtils
255                     .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
256                     }));
257                 return MapUtils.isNotEmpty(valueMap);
258             }
259         } else {
260             return true;
261         }
262     }
263
264     private void evaluateCollectionTypeProperties(PropertyDefinition propertyDefinition) {
265         ToscaType toscaPropertyType = ToscaType.isValidType(propertyDefinition.getType());
266         try {
267             if (isPropertyToEvaluate(propertyDefinition)) {
268                 evaluateCollectionConstraints(propertyDefinition, toscaPropertyType);
269             }
270         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
271             logger.error(e.getMessage(), e);
272             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
273         }
274         if (ToscaType.LIST == toscaPropertyType) {
275             evaluateListType(propertyDefinition);
276         } else if (ToscaType.MAP == toscaPropertyType) {
277             evaluateMapType(propertyDefinition);
278         }
279     }
280
281     private void evaluateCollectionConstraints(PropertyDefinition propertyDefinition, ToscaType toscaPropertyType) {
282         List<PropertyConstraint> constraintsList = propertyDefinition.getConstraints();
283
284         if (CollectionUtils.isEmpty(constraintsList)) {
285             return;
286         }
287         ToscaType toscaPropertyType1;
288         if (null == toscaPropertyType) {
289             toscaPropertyType1 = ToscaType.isValidType(propertyDefinition.getType());
290         } else {
291             toscaPropertyType1 = toscaPropertyType;
292         }
293         constraintsList.stream()
294             .filter(this::isACollectionConstraint)
295             .forEach(propertyConstraint -> {
296                 try {
297                     if (ToscaType.LIST == toscaPropertyType1) {
298                         Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
299                         });
300                         propertyConstraint.validate(list);
301                     } else if (ToscaType.MAP == toscaPropertyType1) {
302                         final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
303                         });
304                         propertyConstraint.validate(map);
305                     }
306                 } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
307                     errorMessages.add("\n" + propertyConstraint.getErrorMessage(toscaPropertyType1, exception,
308                         getCompletePropertyName(propertyDefinition)));
309                 }
310             });
311     }
312
313     private boolean isACollectionConstraint(PropertyConstraint constraint) {
314         if (constraint instanceof MaxLengthConstraint) {
315             return true;
316         }
317         if (constraint instanceof MinLengthConstraint) {
318             return true;
319         }
320         return constraint instanceof LengthConstraint;
321     }
322
323     private void evaluateListType(PropertyDefinition propertyDefinition) {
324         try {
325             if (propertyDefinition.getSchemaType() == null) {
326                 propertyDefinition.setSchema(createStringSchema());
327             }
328             Collection<?> list = ConstraintUtil.parseToCollection(null != propertyDefinition.getValue() ?
329                 propertyDefinition.getValue() : propertyDefinition.getDefaultValue(), new TypeReference<List<?>>() {});
330             final Map<String, Object> map = new HashMap<>();
331             int index = 0;
332             for (Object obj : list) {
333                 map.put(String.valueOf(index),obj);
334                 index++;
335             }
336             evaluateCollectionType(propertyDefinition, map);
337         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
338             logger.debug(e.getMessage(), e);
339             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
340         }
341     }
342
343     private SchemaDefinition createStringSchema() {
344         final SchemaDefinition schemaDefinition = new SchemaDefinition();
345         final PropertyDefinition schemaStringProperty = new PropertyDefinition();
346         schemaStringProperty.setType(ToscaType.STRING.getType());
347         schemaDefinition.setProperty(schemaStringProperty);
348         return schemaDefinition;
349     }
350
351     private void evaluateMapType(final PropertyDefinition propertyDefinition) {
352         try {
353             if (propertyDefinition.getSchemaType() == null) {
354                 propertyDefinition.setSchema(createStringSchema());
355             }
356             final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
357             });
358             evaluateCollectionType(propertyDefinition, map);
359         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
360             logger.debug(e.getMessage(), e);
361             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
362         }
363     }
364
365     private void evaluateCollectionPrimitiveSchemaType(final PropertyDefinition propertyDefinition,
366                                                        final String schemaType) throws JsonProcessingException {
367         if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() instanceof PropertyDefinition) {
368             propertyDefinition.setConstraints(((PropertyDefinition) propertyDefinition.getSchema().getProperty()).getConstraints());
369             propertyDefinition.setValue(objectMapper.readValue(propertyDefinition.getValue(), String.class));
370             propertyDefinition.setType(schemaType);
371             evaluateConstraintsOnProperty(propertyDefinition);
372         }
373     }
374
375     private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Map<String, Object> valueMap) {
376         final String schemaType = propertyDefinition.getSchemaType();
377         for (String mapKey : valueMap.keySet()) {
378             final Object value = valueMap.get(mapKey);
379             try {
380                 final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
381                     objectMapper.writeValueAsString(value),mapKey);
382                 propertyCopyWithNewValue.setToscaSubPath(mapKey);
383                 if (!isValueAToscaFunction(propertyCopyWithNewValue)) {
384                     if (ToscaType.isPrimitiveType(schemaType)) {
385                         evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
386                     } else if (ToscaType.isCollectionType(schemaType)) {
387                         propertyCopyWithNewValue.setType(schemaType);
388                         propertyCopyWithNewValue.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
389                         evaluateCollectionTypeProperties(propertyCopyWithNewValue);
390                     } else {
391                         propertyCopyWithNewValue.setType(schemaType);
392                         completePropertyName.append(UNDERSCORE);
393                         completePropertyName.append(propertyCopyWithNewValue.getName());
394                         evaluateComplexTypeProperties(propertyCopyWithNewValue);
395                     }
396                 }
397             } catch (final Exception e) {
398                 logger.debug(e.getMessage(), e);
399                 errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
400             }
401         }
402     }
403
404     private String getCompletePropertyName(final PropertyDefinition propertyDefinition) {
405         if (StringUtils.isNotBlank(completeInputName)) {
406             return completeInputName;
407         }
408
409         final String propertyName = propertyDefinition == null ? "" : propertyDefinition.getName();
410         if (StringUtils.isNotBlank(completePropertyName)) {
411             return completePropertyName + UNDERSCORE + propertyName;
412         }
413
414         return propertyName;
415     }
416
417     private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) {
418         final var propertyDefinition = new PropertyDefinition(propertyToCopy);
419         if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) {
420             propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> {
421                 final List<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath();
422                 if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) {
423                     propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction());
424                 }
425             });
426         }
427         propertyDefinition.setValue(value);
428         return propertyDefinition;
429     }
430
431     private PropertyDefinition getPropertyDefinitionObjectFromInputs(PropertyDefinition property) {
432         InputDefinition inputDefinition = (InputDefinition) property;
433         PropertyDefinition propertyDefinition = null;
434         if (CollectionUtils.isEmpty(inputDefinition.getProperties()) || ToscaType.isPrimitiveType(inputDefinition.getProperties().get(0).getType())) {
435             propertyDefinition = new PropertyDefinition();
436             propertyDefinition.setType(inputDefinition.getType());
437             propertyDefinition.setValue(inputDefinition.getDefaultValue());
438             propertyDefinition.setName(inputDefinition.getName());
439             propertyDefinition.setConstraints(inputDefinition.getConstraints());
440         } else if (Objects.nonNull(inputDefinition.getInputPath())) {
441             propertyDefinition = evaluateComplexTypeInputs(inputDefinition);
442             propertyDefinition.setConstraints(inputDefinition.getConstraints());
443         }
444         return propertyDefinition;
445     }
446
447     private PropertyDefinition evaluateComplexTypeInputs(InputDefinition inputDefinition) {
448         Map<String, Object> inputMap = new HashMap<>();
449         PropertyDefinition propertyDefinition = new PropertyDefinition();
450         String[] inputPathArr = inputDefinition.getInputPath().split("#");
451         if (inputPathArr.length > 1) {
452             inputPathArr = ArrayUtils.remove(inputPathArr, 0);
453         }
454         try {
455             Map<String, Object> presentMap = inputMap;
456             for (int i = 0; i < inputPathArr.length; i++) {
457                 if (i == inputPathArr.length - 1) {
458                     presentMap.computeIfAbsent(inputPathArr[i], k -> inputDefinition.getDefaultValue());
459                 } else {
460                     presentMap.computeIfAbsent(inputPathArr[i], k -> new HashMap<String, Object>());
461                     presentMap = (Map<String, Object>) presentMap.get(inputPathArr[i]);
462                 }
463             }
464             if (CollectionUtils.isNotEmpty(inputDefinition.getProperties())) {
465                 propertyDefinition.setType(inputDefinition.getProperties().get(0).getType());
466             }
467             propertyDefinition.setName(inputDefinition.getName());
468             propertyDefinition.setValue(objectMapper.writeValueAsString(inputMap));
469         } catch (IOException e) {
470             logger.error(e.getMessage(), e);
471             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, inputDefinition.getName()));
472         }
473         return propertyDefinition;
474     }
475
476     protected ResponseFormatManager getResponseFormatManager() {
477         return ResponseFormatManager.getInstance();
478     }
479 }