6c820a1af2217762fe86b07fdc884dc59ee19eae
[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 Map<String, DataTypeDefinition> dataTypeDefinitionCache;
65     private final ObjectMapper objectMapper = new ObjectMapper();
66     private final List<String> errorMessages = new ArrayList<>();
67     private StringBuilder completePropertyName;
68     private String completeInputName;
69
70     public Either<Boolean, ResponseFormat> validatePropertyConstraints(final Collection<? extends PropertyDefinition> propertyDefinitionList,
71                                                                        final ApplicationDataTypeCache applicationDataTypeCache,
72                                                                        final String model) {
73
74         dataTypeDefinitionCache = applicationDataTypeCache.getAll(model).left().value();
75         CollectionUtils.emptyIfNull(propertyDefinitionList).stream()
76             .filter(this::isValuePresent)
77             .forEach(this::evaluatePropertyTypeForConstraintValidation);
78         if (CollectionUtils.isNotEmpty(errorMessages)) {
79             final String errorMsgAsString = String.join(",", errorMessages);
80             logger.debug("Properties with Invalid Data: {}", errorMsgAsString);
81             return Either.right(getResponseFormatManager().getResponseFormat(ActionStatus.INVALID_PROPERTY_VALUES, errorMsgAsString));
82         }
83         return Either.left(Boolean.TRUE);
84     }
85
86     private boolean isValuePresent(PropertyDefinition propertyDefinition) {
87         if (propertyDefinition instanceof ComponentInstanceInput) {
88             return StringUtils.isNotEmpty(propertyDefinition.getValue());
89         }
90         if (propertyDefinition instanceof InputDefinition) {
91             return StringUtils.isNotEmpty(propertyDefinition.getDefaultValue());
92         }
93         return StringUtils.isNotEmpty(propertyDefinition.getValue());
94     }
95
96     private void evaluatePropertyTypeForConstraintValidation(PropertyDefinition propertyDefinition) {
97         if (propertyDefinition == null || propertyDefinition.getType() == null || !dataTypeDefinitionCache.containsKey(
98             propertyDefinition.getType())) {
99             errorMessages.add("\nUnsupported datatype found for property " + getCompletePropertyName(propertyDefinition));
100             return;
101         }
102         completeInputName = "";
103         completePropertyName = new StringBuilder();
104         if (propertyDefinition instanceof ComponentInstanceInput) {
105             setCompletePropertyName(propertyDefinition);
106             evaluateComplexTypeProperties(propertyDefinition);
107             return;
108         }
109         if (propertyDefinition instanceof InputDefinition) {
110             completeInputName = propertyDefinition.getName();
111             propertyDefinition = getPropertyDefinitionObjectFromInputs(propertyDefinition);
112         }
113         if (propertyDefinition != null) {
114             List<PropertyConstraint> propertyConstraints =
115                 dataTypeDefinitionCache.get(propertyDefinition.getType()).safeGetConstraints();
116             if (ToscaType.isPrimitiveType(propertyDefinition.getType())) {
117                 propertyDefinition.setConstraints(org.openecomp.sdc.be.dao.utils.CollectionUtils.merge(propertyDefinition.safeGetConstraints(),
118                     propertyConstraints.isEmpty() ? new ArrayList<>() : propertyConstraints));
119                 evaluateConstraintsOnProperty(propertyDefinition);
120             } else if (ToscaType.isCollectionType(propertyDefinition.getType())) {
121                 propertyDefinition.setConstraints(org.openecomp.sdc.be.dao.utils.CollectionUtils.merge(propertyDefinition.safeGetConstraints(),
122                     propertyConstraints.isEmpty() ? new ArrayList<>() : propertyConstraints));
123                 evaluateConstraintsOnProperty(propertyDefinition);
124                 evaluateCollectionTypeProperties(propertyDefinition);
125             } else {
126                 setCompletePropertyName(propertyDefinition);
127                 evaluateComplexTypeProperties(propertyDefinition);
128             }
129         }
130     }
131
132     private void setCompletePropertyName(PropertyDefinition propertyDefinition) {
133         if (StringUtils.isNotBlank(propertyDefinition.getUniqueId())) {
134             completePropertyName.append(propertyDefinition.getUniqueId().substring(propertyDefinition.getUniqueId().lastIndexOf('.') + 1));
135         }
136     }
137
138     private void evaluateConstraintsOnProperty(PropertyDefinition propertyDefinition) {
139         ToscaType toscaType = ToscaType.isValidType(propertyDefinition.getType());
140         if (isPropertyNotMappedAsInput(propertyDefinition) && CollectionUtils.isNotEmpty(propertyDefinition.getConstraints())) {
141             for (PropertyConstraint propertyConstraint : propertyDefinition.getConstraints()) {
142                 try {
143                     propertyConstraint.initialize(toscaType);
144                     propertyConstraint.validate(toscaType, propertyDefinition.getValue());
145                 } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
146                     errorMessages.add(propertyConstraint.getErrorMessage(toscaType, exception, getCompletePropertyName(propertyDefinition)));
147                 } catch (IllegalArgumentException ie) {
148                     errorMessages.add(ie.getMessage());
149                 }
150             }
151         } else if (isPropertyNotMappedAsInput(propertyDefinition) && ToscaType.isPrimitiveType(propertyDefinition.getType())
152                 && !propertyDefinition.isToscaFunction() && !toscaType.isValidValue(propertyDefinition.getValue())) {
153             errorMessages.add(String.format("Unsupported value provided for %s property supported value type is %s.",
154                 getCompletePropertyName(propertyDefinition), toscaType.getType()));
155         }
156     }
157
158     private boolean isPropertyNotMappedAsInput(PropertyDefinition propertyDefinition) {
159         return !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_INPUT) && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_PROPERTY)
160                 && !propertyDefinition.getValue().startsWith(IGNORE_PROPERTY_VALUE_START_WITH_ATTRIBUTE);
161     }
162
163     private void checkAndEvaluatePrimitiveProperty(PropertyDefinition propertyDefinition, DataTypeDefinition dataTypeDefinition) {
164         if (ToscaType.isPrimitiveType(dataTypeDefinition.getName()) && CollectionUtils.isNotEmpty(dataTypeDefinition.getConstraints())) {
165             PropertyDefinition definition = new PropertyDefinition();
166             definition.setValue(propertyDefinition.getValue());
167             definition.setType(dataTypeDefinition.getName());
168             definition.setConstraints(dataTypeDefinition.getConstraints());
169             evaluateConstraintsOnProperty(propertyDefinition);
170         }
171     }
172
173     private void evaluateComplexTypeProperties(PropertyDefinition propertyDefinition) {
174         List<PropertyDefinition> propertyDefinitions = dataTypeDefinitionCache.get(propertyDefinition.getType()).getProperties();
175         try {
176             Map<String, Object> valueMap = MapUtils
177                 .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
178                 }));
179             if (CollectionUtils.isEmpty(propertyDefinitions)) {
180                 checkAndEvaluatePrimitiveProperty(propertyDefinition, dataTypeDefinitionCache.get(propertyDefinition.getType()));
181             } else {
182                 ListUtils.emptyIfNull(propertyDefinitions).forEach(prop -> evaluateRegularComplexType(propertyDefinition, prop, valueMap));
183             }
184         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
185             logger.debug(e.getMessage(), e);
186             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
187         }
188     }
189
190     private void evaluateRegularComplexType(PropertyDefinition propertyDefinition, PropertyDefinition prop, Map<String, Object> valueMap) {
191         try {
192             PropertyDefinition newPropertyWithValue;
193             if (valueMap.containsKey(prop.getName())) {
194                 if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
195                     for (SubPropertyToscaFunction subPropertyToscaFunction : propertyDefinition.getSubPropertyToscaFunctions()) {
196                         final List<String> path = subPropertyToscaFunction.getSubPropertyPath();
197                         if (path.size() == 1) {
198                             if (path.get(0).equals(prop.getName())) {
199                                 return;
200                             }
201                         }
202                         if (path.size() > 1) {
203                             if (path.get(0).equals(propertyDefinition.getToscaSubPath()) && path.get(1).equals(prop.getName())) {
204                                 return;
205                             }
206                         }
207                     }
208                 }
209                 if (ToscaType.isPrimitiveType(prop.getType())) {
210                     newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())), prop.getName());
211                     if (isPropertyToEvaluate(newPropertyWithValue)) {
212                         evaluateConstraintsOnProperty(newPropertyWithValue);
213                     }
214                 } else if (ToscaType.isCollectionType(prop.getType())) {
215                     newPropertyWithValue =
216                         copyPropertyWithNewValue(prop,
217                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
218                     if (isPropertyToEvaluate(newPropertyWithValue)) {
219                         evaluateCollectionTypeProperties(newPropertyWithValue);
220                     }
221                 } else {
222                     newPropertyWithValue =
223                         copyPropertyWithNewValue(prop,
224                             objectMapper.writeValueAsString(valueMap.get(prop.getName())), prop.getName());
225                     if (isPropertyToEvaluate(newPropertyWithValue)) {
226                         evaluateComplexTypeProperties(newPropertyWithValue);
227                     }
228                 }
229             }
230         } catch (IOException | ConstraintValueDoNotMatchPropertyTypeException e) {
231             logger.error(e.getMessage(), e);
232             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
233         }
234     }
235
236     private boolean isPropertyToEvaluate(PropertyDefinition propertyDefinition) throws ConstraintValueDoNotMatchPropertyTypeException {
237         if (Boolean.FALSE.equals(propertyDefinition.isRequired())) {
238             if (!ToscaType.isCollectionType(propertyDefinition.getType())) {
239                 return StringUtils.isNotEmpty(propertyDefinition.getValue()) &&
240                     !"null".equals(propertyDefinition.getValue());
241             } else if (ToscaType.LIST == ToscaType.isValidType(propertyDefinition.getType())) {
242                 Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
243                 });
244                 return CollectionUtils.isNotEmpty(list);
245             } else {
246                 Map<String, Object> valueMap = MapUtils
247                     .emptyIfNull(ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
248                     }));
249                 return MapUtils.isNotEmpty(valueMap);
250             }
251         } else {
252             return true;
253         }
254     }
255
256     private void evaluateCollectionTypeProperties(PropertyDefinition propertyDefinition) {
257         ToscaType toscaPropertyType = ToscaType.isValidType(propertyDefinition.getType());
258         try {
259             if (isPropertyToEvaluate(propertyDefinition)) {
260                 evaluateCollectionConstraints(propertyDefinition, toscaPropertyType);
261             }
262         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
263             logger.error(e.getMessage(), e);
264             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
265         }
266         if (ToscaType.LIST == toscaPropertyType) {
267             evaluateListType(propertyDefinition);
268         } else if (ToscaType.MAP == toscaPropertyType) {
269             evaluateMapType(propertyDefinition);
270         }
271     }
272
273     private void evaluateCollectionConstraints(PropertyDefinition propertyDefinition, ToscaType toscaPropertyType) {
274         List<PropertyConstraint> constraintsList = propertyDefinition.getConstraints();
275
276         if (CollectionUtils.isEmpty(constraintsList)) {
277             return;
278         }
279         ToscaType toscaPropertyType1;
280         if (null == toscaPropertyType) {
281             toscaPropertyType1 = ToscaType.isValidType(propertyDefinition.getType());
282         } else {
283             toscaPropertyType1 = toscaPropertyType;
284         }
285         constraintsList.stream()
286             .filter(this::isACollectionConstraint)
287             .forEach(propertyConstraint -> {
288                 try {
289                     if (ToscaType.LIST == toscaPropertyType1) {
290                         Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
291                         });
292                         propertyConstraint.validate(list);
293                     } else if (ToscaType.MAP == toscaPropertyType1) {
294                         final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
295                         });
296                         propertyConstraint.validate(map);
297                     }
298                 } catch (ConstraintValueDoNotMatchPropertyTypeException | ConstraintViolationException exception) {
299                     errorMessages.add("\n" + propertyConstraint.getErrorMessage(toscaPropertyType1, exception,
300                         getCompletePropertyName(propertyDefinition)));
301                 }
302             });
303     }
304
305     private boolean isACollectionConstraint(PropertyConstraint constraint) {
306         if (constraint instanceof MaxLengthConstraint) {
307             return true;
308         }
309         if (constraint instanceof MinLengthConstraint) {
310             return true;
311         }
312         return constraint instanceof LengthConstraint;
313     }
314
315     private void evaluateListType(PropertyDefinition propertyDefinition) {
316         try {
317             if (propertyDefinition.getSchemaType() == null) {
318                 propertyDefinition.setSchema(createStringSchema());
319             }
320             Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
321             final Map<String, Object> map = new HashMap<>();
322             int index = 0;
323             for (Object obj : list) {
324                 map.put(String.valueOf(index),obj);
325                 index++;
326             }
327             evaluateCollectionType(propertyDefinition, map);
328         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
329             logger.debug(e.getMessage(), e);
330             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
331         }
332     }
333
334     private SchemaDefinition createStringSchema() {
335         final SchemaDefinition schemaDefinition = new SchemaDefinition();
336         final PropertyDefinition schemaStringProperty = new PropertyDefinition();
337         schemaStringProperty.setType(ToscaType.STRING.getType());
338         schemaDefinition.setProperty(schemaStringProperty);
339         return schemaDefinition;
340     }
341
342     private void evaluateMapType(final PropertyDefinition propertyDefinition) {
343         try {
344             if (propertyDefinition.getSchemaType() == null) {
345                 propertyDefinition.setSchema(createStringSchema());
346             }
347             final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
348             });
349             evaluateCollectionType(propertyDefinition, map);
350         } catch (ConstraintValueDoNotMatchPropertyTypeException e) {
351             logger.debug(e.getMessage(), e);
352             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
353         }
354     }
355
356     private void evaluateCollectionPrimitiveSchemaType(final PropertyDefinition propertyDefinition,
357                                                        final String schemaType) throws JsonProcessingException {
358         if (propertyDefinition.getSchema() != null && propertyDefinition.getSchema().getProperty() instanceof PropertyDefinition) {
359             propertyDefinition.setConstraints(((PropertyDefinition) propertyDefinition.getSchema().getProperty()).getConstraints());
360             propertyDefinition.setValue(objectMapper.readValue(propertyDefinition.getValue(), String.class));
361             propertyDefinition.setType(schemaType);
362             evaluateConstraintsOnProperty(propertyDefinition);
363         }
364     }
365
366     private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Map<String, Object> valueMap) {
367         final String schemaType = propertyDefinition.getSchemaType();
368         for (String mapKey : valueMap.keySet()) {
369             final Object value = valueMap.get(mapKey);
370             try {
371                 final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
372                     objectMapper.writeValueAsString(value),mapKey);
373                 propertyCopyWithNewValue.setToscaSubPath(mapKey);
374                 if (isPropertyNotMappedAsInput(propertyCopyWithNewValue)) {
375                     if (ToscaType.isPrimitiveType(schemaType)) {
376                         evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
377                     } else if (ToscaType.isCollectionType(schemaType)) {
378                         propertyCopyWithNewValue.setType(schemaType);
379                         propertyCopyWithNewValue.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
380                         evaluateCollectionTypeProperties(propertyCopyWithNewValue);
381                     } else {
382                         propertyCopyWithNewValue.setType(schemaType);
383                         completePropertyName.append(UNDERSCORE);
384                         completePropertyName.append(propertyCopyWithNewValue.getName());
385                         evaluateComplexTypeProperties(propertyCopyWithNewValue);
386                     }
387                 }
388             } catch (final Exception e) {
389                 logger.debug(e.getMessage(), e);
390                 errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
391             }
392         }
393     }
394
395     private String getCompletePropertyName(final PropertyDefinition propertyDefinition) {
396         if (StringUtils.isNotBlank(completeInputName)) {
397             return completeInputName;
398         }
399
400         final String propertyName = propertyDefinition == null ? "" : propertyDefinition.getName();
401         if (StringUtils.isNotBlank(completePropertyName)) {
402             return completePropertyName + UNDERSCORE + propertyName;
403         }
404
405         return propertyName;
406     }
407
408     private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) {
409         final var propertyDefinition = new PropertyDefinition(propertyToCopy);
410         if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) {
411             propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> {
412                 final List<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath();
413                 if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) {
414                     propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction());
415                 }
416             });
417         }
418         propertyDefinition.setValue(value);
419         return propertyDefinition;
420     }
421
422     private PropertyDefinition getPropertyDefinitionObjectFromInputs(PropertyDefinition property) {
423         InputDefinition inputDefinition = (InputDefinition) property;
424         PropertyDefinition propertyDefinition = null;
425         if (CollectionUtils.isEmpty(inputDefinition.getProperties()) || ToscaType.isPrimitiveType(inputDefinition.getProperties().get(0).getType())) {
426             propertyDefinition = new PropertyDefinition();
427             propertyDefinition.setType(inputDefinition.getType());
428             propertyDefinition.setValue(inputDefinition.getDefaultValue());
429             propertyDefinition.setName(inputDefinition.getName());
430             propertyDefinition.setConstraints(inputDefinition.getConstraints());
431         } else if (Objects.nonNull(inputDefinition.getInputPath())) {
432             propertyDefinition = evaluateComplexTypeInputs(inputDefinition);
433             propertyDefinition.setConstraints(inputDefinition.getConstraints());
434         }
435         return propertyDefinition;
436     }
437
438     private PropertyDefinition evaluateComplexTypeInputs(InputDefinition inputDefinition) {
439         Map<String, Object> inputMap = new HashMap<>();
440         PropertyDefinition propertyDefinition = new PropertyDefinition();
441         String[] inputPathArr = inputDefinition.getInputPath().split("#");
442         if (inputPathArr.length > 1) {
443             inputPathArr = ArrayUtils.remove(inputPathArr, 0);
444         }
445         try {
446             Map<String, Object> presentMap = inputMap;
447             for (int i = 0; i < inputPathArr.length; i++) {
448                 if (i == inputPathArr.length - 1) {
449                     presentMap.computeIfAbsent(inputPathArr[i], k -> inputDefinition.getDefaultValue());
450                 } else {
451                     presentMap.computeIfAbsent(inputPathArr[i], k -> new HashMap<String, Object>());
452                     presentMap = (Map<String, Object>) presentMap.get(inputPathArr[i]);
453                 }
454             }
455             if (CollectionUtils.isNotEmpty(inputDefinition.getProperties())) {
456                 propertyDefinition.setType(inputDefinition.getProperties().get(0).getType());
457             }
458             propertyDefinition.setName(inputDefinition.getName());
459             propertyDefinition.setValue(objectMapper.writeValueAsString(inputMap));
460         } catch (IOException e) {
461             logger.error(e.getMessage(), e);
462             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, inputDefinition.getName()));
463         }
464         return propertyDefinition;
465     }
466
467     protected ResponseFormatManager getResponseFormatManager() {
468         return ResponseFormatManager.getInstance();
469     }
470 }