a25a332b9e8e33986ae4fa0df7c1eb81f9bff839
[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::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 (ToscaType.isPrimitiveType(schemaType)) {
375                     evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
376                 } else if (ToscaType.isCollectionType(schemaType)) {
377                     propertyCopyWithNewValue.setType(schemaType);
378                     propertyCopyWithNewValue.setSchemaType(propertyDefinition.getSchemaProperty().getSchemaType());
379                     evaluateCollectionTypeProperties(propertyCopyWithNewValue);
380                 } else {
381                     propertyCopyWithNewValue.setType(schemaType);
382                     completePropertyName.append(UNDERSCORE);
383                     completePropertyName.append(propertyCopyWithNewValue.getName());
384                     evaluateComplexTypeProperties(propertyCopyWithNewValue);
385                 }
386             } catch (final Exception e) {
387                 logger.debug(e.getMessage(), e);
388                 errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
389             }
390         }
391     }
392
393     private String getCompletePropertyName(final PropertyDefinition propertyDefinition) {
394         if (StringUtils.isNotBlank(completeInputName)) {
395             return completeInputName;
396         }
397
398         final String propertyName = propertyDefinition == null ? "" : propertyDefinition.getName();
399         if (StringUtils.isNotBlank(completePropertyName)) {
400             return completePropertyName + UNDERSCORE + propertyName;
401         }
402
403         return propertyName;
404     }
405
406     private PropertyDefinition copyPropertyWithNewValue(final PropertyDefinition propertyToCopy, final String value, final String key) {
407         final var propertyDefinition = new PropertyDefinition(propertyToCopy);
408         if (key != null && propertyToCopy.getSubPropertyToscaFunctions() != null) {
409             propertyToCopy.getSubPropertyToscaFunctions().forEach(subPropertyToscaFunction -> {
410                 final List<String> subPropertyPath = subPropertyToscaFunction.getSubPropertyPath();
411                 if (subPropertyPath.get((subPropertyPath.size() - 1)).equals(key)) {
412                     propertyDefinition.setToscaFunction(subPropertyToscaFunction.getToscaFunction());
413                 }
414             });
415         }
416         propertyDefinition.setValue(value);
417         return propertyDefinition;
418     }
419
420     private PropertyDefinition getPropertyDefinitionObjectFromInputs(PropertyDefinition property) {
421         InputDefinition inputDefinition = (InputDefinition) property;
422         PropertyDefinition propertyDefinition = null;
423         if (CollectionUtils.isEmpty(inputDefinition.getProperties()) || ToscaType.isPrimitiveType(inputDefinition.getProperties().get(0).getType())) {
424             propertyDefinition = new PropertyDefinition();
425             propertyDefinition.setType(inputDefinition.getType());
426             propertyDefinition.setValue(inputDefinition.getDefaultValue());
427             propertyDefinition.setName(inputDefinition.getName());
428             propertyDefinition.setConstraints(inputDefinition.getConstraints());
429         } else if (Objects.nonNull(inputDefinition.getInputPath())) {
430             propertyDefinition = evaluateComplexTypeInputs(inputDefinition);
431             propertyDefinition.setConstraints(inputDefinition.getConstraints());
432         }
433         return propertyDefinition;
434     }
435
436     private PropertyDefinition evaluateComplexTypeInputs(InputDefinition inputDefinition) {
437         Map<String, Object> inputMap = new HashMap<>();
438         PropertyDefinition propertyDefinition = new PropertyDefinition();
439         String[] inputPathArr = inputDefinition.getInputPath().split("#");
440         if (inputPathArr.length > 1) {
441             inputPathArr = ArrayUtils.remove(inputPathArr, 0);
442         }
443         try {
444             Map<String, Object> presentMap = inputMap;
445             for (int i = 0; i < inputPathArr.length; i++) {
446                 if (i == inputPathArr.length - 1) {
447                     presentMap.computeIfAbsent(inputPathArr[i], k -> inputDefinition.getDefaultValue());
448                 } else {
449                     presentMap.computeIfAbsent(inputPathArr[i], k -> new HashMap<String, Object>());
450                     presentMap = (Map<String, Object>) presentMap.get(inputPathArr[i]);
451                 }
452             }
453             if (CollectionUtils.isNotEmpty(inputDefinition.getProperties())) {
454                 propertyDefinition.setType(inputDefinition.getProperties().get(0).getType());
455             }
456             propertyDefinition.setName(inputDefinition.getName());
457             propertyDefinition.setValue(objectMapper.writeValueAsString(inputMap));
458         } catch (IOException e) {
459             logger.error(e.getMessage(), e);
460             errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, inputDefinition.getName()));
461         }
462         return propertyDefinition;
463     }
464
465     protected ResponseFormatManager getResponseFormatManager() {
466         return ResponseFormatManager.getInstance();
467     }
468 }