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