ef7363a1a39466cca6d1472dcfa29280d0ab0ecc
[sdc.git] /
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());
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(propertyDefinition.getValue())) {
159             errorMessages.add(String.format("Unsupported value provided for %s property supported value type is %s.",
160                 getCompletePropertyName(propertyDefinition), toscaType.getType()));
161         }
162     }
163
164     private boolean isValueAToscaFunction(PropertyDefinition propertyDefinition) {
165         return (propertyDefinition.getToscaFunction() != null)  || (propertyDefinition.getValue() != null
166             && ((propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY)
167             || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_ATTRIBUTE)
168             || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_PROPERTY) || propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_INPUT))));
169     }
170
171     private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) {
172         if (ToscaType.isPrimitiveType(dataTypeDefinition.getName()) && CollectionUtils.isNotEmpty(dataTypeDefinition.getConstraints())) {
173             PropertyDefinition definition = new PropertyDefinition();
174             definition.setValue(propertyDefinition.getValue());
175             definition.setType(dataTypeDefinition.getName());
176             definition.setConstraints(dataTypeDefinition.getConstraints());
177             evaluateConstraintsOnProperty(propertyDefinition);
178         }
179     }
180
181     private void evaluateComplexTypeProperties(PropertyDefinition propertyDefinition) {
182         List<PropertyDefinition> propertyDefinitions = dataTypeDefinitionCache.get(propertyDefinition.getType()).getProperties();
183         try {
184             Map<String, Object> valueMap = MapUtils
185                 .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
186                 }));
187             if (CollectionUtils.isEmpty(propertyDefinitions)) {
188                 checkAndEvaluatePrimitiveProperty(propertyDefinition, dataTypeDefinitionCache.get(propertyDefinition.getType()));
189             } else {
190                 ListUtils.emptyIfNull(propertyDefinitions).forEach(prop -> evaluateRegularComplexType(propertyDefinition, prop, valueMap));
191             }
192         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
193             logger.debug(e.getMessage(), e);
194             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
195         }
196     }
197
198     private void evaluateRegularComplexType(PropertyDefinition propertyDefinition, PropertyDefinition prop, Map<String, Object> valueMap) {
199         try {
200             PropertyDefinition newPropertyWithValue;
201             if (valueMap.containsKey(prop.getName())) {
202                 if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
203                     for (SubPropertyToscaFunction subPropertyToscaFunction : propertyDefinition.getSubPropertyToscaFunctions()) {
204                         final List<String> path = subPropertyToscaFunction.getSubPropertyPath();
205                         if (path.size() == 1 && path.get(0).equals(prop.getName())) {
206                             return;
207                         }
208                         if (path.size() > 1) {
209                             if (path.get(0).equals(propertyDefinition.getToscaSubPath()) && path.get(1).equals(prop.getName())) {
210                                 return;
211                             }
212                         }
213                     }
214                 }
215                 if (ToscaType.isPrimitiveType(prop.getType())) {
216                     newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())), prop.getName());
217                     if (isPropertyToEvaluate(newPropertyWithValue)) {
218                         evaluateConstraintsOnProperty(newPropertyWithValue);
219                     }
220                 } else if (ToscaType.isCollectionType(prop.getType())) {
221                     newPropertyWithValue =
222                         copyPropertyWithNewValue(prop,
223                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
224                     if (isPropertyToEvaluate(newPropertyWithValue)) {
225                         evaluateCollectionTypeProperties(newPropertyWithValue);
226                     }
227                 } else {
228                     newPropertyWithValue =
229                         copyPropertyWithNewValue(prop,
230                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
231                     if (isPropertyToEvaluate(newPropertyWithValue)) {
232                         evaluateComplexTypeProperties(newPropertyWithValue);
233                     }
234                 }
235             }
236         } catch (IOException | ConstraintValueDoNotMatchPropertyTypeException e) {
237             logger.error(e.getMessage(), e);
238             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
239         }
240     }
241
242     private boolean isPropertyToEvaluate(PropertyDefinition propertyDefinition) throws ConstraintValueDoNotMatchPropertyTypeException {
243         if (Boolean.FALSE.equals(propertyDefinition.isRequired())) {
244             if (!ToscaType.isCollectionType(propertyDefinition.getType())) {
245                 return StringUtils.isNotEmpty(propertyDefinition.getValue()) &&
246                     !"null".equals(propertyDefinition.getValue());
247             } else if (ToscaType.LIST == ToscaType.isValidType(propertyDefinition.getType())) {
248                 Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
249                 });
250                 return CollectionUtils.isNotEmpty(list);
251             } else {
252                 Map<String, Object> valueMap = MapUtils
253                     .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
254                     }));
255                 return MapUtils.isNotEmpty(valueMap);
256             }
257         } else {
258             return true;
259         }
260     }
261
262     private void evaluateCollectionTypeProperties(PropertyDefinition propertyDefinition) {
263         ToscaType toscaPropertyType = ToscaType.isValidType(propertyDefinition.getType());
264         try {
265             if (isPropertyToEvaluate(propertyDefinition)) {
266                 evaluateCollectionConstraints(propertyDefinition, toscaPropertyType);
267             }
268         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
269             logger.error(e.getMessage(), e);
270             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
271         }
272         if (ToscaType.LIST == toscaPropertyType) {
273             evaluateListType(propertyDefinition);
274         } else if (ToscaType.MAP == toscaPropertyType) {
275             evaluateMapType(propertyDefinition);
276         }
277     }
278
279     private void evaluateCollectionConstraints(PropertyDefinition propertyDefinition, ToscaType toscaPropertyType) {
280         List<PropertyConstraint> constraintsList = propertyDefinition.getConstraints();
281
282         if (CollectionUtils.isEmpty(constraintsList)) {
283             return;
284         }
285         ToscaType toscaPropertyType1;
286         if (null == toscaPropertyType) {
287             toscaPropertyType1 = ToscaType.isValidType(propertyDefinition.getType());
288         } else {
289             toscaPropertyType1 = toscaPropertyType;
290         }
291         constraintsList.stream()
292             .filter(this::isACollectionConstraint)
293             .forEach(propertyConstraint -> {
294                 try {
295                     if (ToscaType.LIST == toscaPropertyType1) {
296                         Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
297                         });
298                         propertyConstraint.validate(list);
299                     } else if (ToscaType.MAP == toscaPropertyType1) {
300                         final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
301                         });
302                         propertyConstraint.validate(map);
303                     }
304                 } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
305                     errorMessages.add("\n" + propertyConstraint.getErrorMessage(toscaPropertyType1, exception,
306                         getCompletePropertyName(propertyDefinition)));
307                 }
308             });
309     }
310
311     private boolean isACollectionConstraint(PropertyConstraint constraint) {
312         if (constraint instanceof MaxLengthConstraint) {
313             return true;
314         }
315         if (constraint instanceof MinLengthConstraint) {
316             return true;
317         }
318         return constraint instanceof LengthConstraint;
319     }
320
321     private void evaluateListType(PropertyDefinition propertyDefinition) {
322         try {
323             if (propertyDefinition.getSchemaType() == null) {
324                 propertyDefinition.setSchema(createStringSchema());
325             }
326             Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
327             final Map<String, Object> map = new HashMap<>();
328             int index = 0;
329             for (Object obj : list) {
330                 map.put(String.valueOf(index),obj);
331                 index++;
332             }
333             evaluateCollectionType(propertyDefinition, map);
334         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
335             logger.debug(e.getMessage(), e);
336             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
337         }
338     }
339
340     private SchemaDefinition createStringSchema() {
341         final SchemaDefinition schemaDefinition = new SchemaDefinition();
342         final PropertyDefinition schemaStringProperty = new PropertyDefinition();
343         schemaStringProperty.setType(ToscaType.STRING.getType());
344         schemaDefinition.setProperty(schemaStringProperty);
345         return schemaDefinition;
346     }
347
348     private void evaluateMapType(final PropertyDefinition propertyDefinition) {
349         try {
350             if (propertyDefinition.getSchemaType() == null) {
351                 propertyDefinition.setSchema(createStringSchema());
352             }
353             final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
354             });
355             evaluateCollectionType(propertyDefinition, map);
356         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
357             logger.debug(e.getMessage(), e);
358             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
359         }
360     }
361
362     private void evaluateCollectionPrimitiveSchemaType(final PropertyDefinition propertyDefinition,
363                                                        final String schemaType) throws JsonProcessingException {
364         if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() instanceof PropertyDefinition) {
365             propertyDefinition.setConstraints(((PropertyDefinition) propertyDefinition.getSchema().getProperty()).getConstraints());
366             propertyDefinition.setValue(objectMapper.readValue(propertyDefinition.getValue(), String.class));
367             propertyDefinition.setType(schemaType);
368             evaluateConstraintsOnProperty(propertyDefinition);
369         }
370     }
371
372     private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Map<String, Object> valueMap) {
373         final String schemaType = propertyDefinition.getSchemaType();
374         for (String mapKey : valueMap.keySet()) {
375             final Object value = valueMap.get(mapKey);
376             try {
377                 final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
378                     objectMapper.writeValueAsString(value),mapKey);
379                 propertyCopyWithNewValue.setToscaSubPath(mapKey);
380                 if (!isValueAToscaFunction(propertyCopyWithNewValue)) {
381                     if (ToscaType.isPrimitiveType(schemaType)) {
382                         evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
383                     } else if (ToscaType.isCollectionType(schemaType)) {
384                         propertyCopyWithNewValue.setType(schemaType);
385                         propertyCopyWithNewValue.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
386                         evaluateCollectionTypeProperties(propertyCopyWithNewValue);
387                     } else {
388                         propertyCopyWithNewValue.setType(schemaType);
389                         completePropertyName.append(UNDERSCORE);
390                         completePropertyName.append(propertyCopyWithNewValue.getName());
391                         evaluateComplexTypeProperties(propertyCopyWithNewValue);
392                     }
393                 }
394             } catch (final Exception e) {
395                 logger.debug(e.getMessage(), e);
396                 errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
397             }
398         }
399     }
400
401     private String getCompletePropertyName(final PropertyDefinition propertyDefinition) {
402         if (StringUtils.isNotBlank(completeInputName)) {
403             return completeInputName;
404         }
405
406         final String propertyName = propertyDefinition == null ? "" : propertyDefinition.getName();
407         if (StringUtils.isNotBlank(completePropertyName)) {
408             return completePropertyName + UNDERSCORE + propertyName;
409         }
410
411         return propertyName;
412     }
413
414     private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) {
415         final var propertyDefinition = new PropertyDefinition(propertyToCopy);
416         if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) {
417             propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> {
418                 final List<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath();
419                 if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) {
420                     propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction());
421                 }
422             });
423         }
424         propertyDefinition.setValue(value);
425         return propertyDefinition;
426     }
427
428     private PropertyDefinition getPropertyDefinitionObjectFromInputs(PropertyDefinition property) {
429         InputDefinition inputDefinition = (InputDefinition) property;
430         PropertyDefinition propertyDefinition = null;
431         if (CollectionUtils.isEmpty(inputDefinition.getProperties()) || ToscaType.isPrimitiveType(inputDefinition.getProperties().get(0).getType())) {
432             propertyDefinition = new PropertyDefinition();
433             propertyDefinition.setType(inputDefinition.getType());
434             propertyDefinition.setValue(inputDefinition.getDefaultValue());
435             propertyDefinition.setName(inputDefinition.getName());
436             propertyDefinition.setConstraints(inputDefinition.getConstraints());
437         } else if (Objects.nonNull(inputDefinition.getInputPath())) {
438             propertyDefinition = evaluateComplexTypeInputs(inputDefinition);
439             propertyDefinition.setConstraints(inputDefinition.getConstraints());
440         }
441         return propertyDefinition;
442     }
443
444     private PropertyDefinition evaluateComplexTypeInputs(InputDefinition inputDefinition) {
445         Map<String, Object> inputMap = new HashMap<>();
446         PropertyDefinition propertyDefinition = new PropertyDefinition();
447         String[] inputPathArr = inputDefinition.getInputPath().split("#");
448         if (inputPathArr.length > 1) {
449             inputPathArr = ArrayUtils.remove(inputPathArr, 0);
450         }
451         try {
452             Map<String, Object> presentMap = inputMap;
453             for (int i = 0; i < inputPathArr.length; i++) {
454                 if (i == inputPathArr.length - 1) {
455                     presentMap.computeIfAbsent(inputPathArr[i], k -> inputDefinition.getDefaultValue());
456                 } else {
457                     presentMap.computeIfAbsent(inputPathArr[i], k -> new HashMap<String, Object>());
458                     presentMap = (Map<String, Object>) presentMap.get(inputPathArr[i]);
459                 }
460             }
461             if (CollectionUtils.isNotEmpty(inputDefinition.getProperties())) {
462                 propertyDefinition.setType(inputDefinition.getProperties().get(0).getType());
463             }
464             propertyDefinition.setName(inputDefinition.getName());
465             propertyDefinition.setValue(objectMapper.writeValueAsString(inputMap));
466         } catch (IOException e) {
467             logger.error(e.getMessage(), e);
468             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, inputDefinition.getName()));
469         }
470         return propertyDefinition;
471     }
472
473     protected ResponseFormatManager getResponseFormatManager() {
474         return ResponseFormatManager.getInstance();
475     }
476 }