+ private boolean tryHandlingAsYamlToscaFunction(String validatedPropValue, String value, UploadPropInfo propertyInfo) {
+ return StringUtils.isEmpty(validatedPropValue) && StringUtils.isNotEmpty(value) && propertyInfo.getToscaFunction() == null && CollectionUtils.isEmpty(propertyInfo.getSubPropertyToscaFunctions());
+ }
+
+ private void addSubPropertyYamlToscaFunctions(final String validatedPropValue, final String value, final String propertyType, final UploadPropInfo propertyInfo, final Map<String, DataTypeDefinition> allDataTypes) {
+ if (StringUtils.isNotEmpty(validatedPropValue) || StringUtils.isEmpty(value) || ToscaPropertyType.isValidType(propertyType) != null) {
+ return;
+ }
+ try {
+ final JsonObject jsonObject = JsonParser.parseString(value).getAsJsonObject();
+
+ final DataTypeDefinition dataTypeDefinition = allDataTypes.get(propertyType);
+ final List<String> propertyNames =
+ dataTypeDefinition.getProperties().stream().map(PropertyDataDefinition::getName).collect(Collectors.toList());
+
+ boolean hasSubPropertyValues = jsonObject.entrySet().stream().allMatch(entry -> propertyNames.contains(entry.getKey()));
+
+ if (hasSubPropertyValues) {
+ for (final PropertyDefinition prop : dataTypeDefinition.getProperties()) {
+ if (propertyInfo.getSubPropertyToscaFunctions().stream()
+ .anyMatch(subPropertyToscaFunction -> subPropertyToscaFunction.getSubPropertyPath().get(0).equals(prop.getName()))) {
+ continue;
+ }
+ Optional<SubPropertyToscaFunction> subPropertyToscaFunction = createSubPropertyYamlToscaFunction(jsonObject, prop, allDataTypes);
+ if (subPropertyToscaFunction.isPresent()) {
+ propertyInfo.getSubPropertyToscaFunctions().add(subPropertyToscaFunction.get());
+ }
+ }
+ }
+ } catch (Exception exception) {
+ log.info("Cannot create YAML value for {}", value);
+ }
+ }
+
+ private Optional<SubPropertyToscaFunction> createSubPropertyYamlToscaFunction(final JsonObject jsonObject, final PropertyDefinition prop, final Map<String, DataTypeDefinition> allDataTypes) {
+ JsonElement propJsonElement = jsonObject.get(prop.getName());
+ if (propJsonElement != null) {
+ final String subPropValue = propJsonElement.toString();
+ final ComponentInstanceProperty subProperty = new ComponentInstanceProperty(prop, subPropValue, null);
+ final String validateSubPropValue =
+ serviceBusinessLogic.validatePropValueBeforeCreate(subProperty, subPropValue, true, allDataTypes);
+
+ if (StringUtils.isEmpty(validateSubPropValue) && StringUtils.isNotEmpty(subPropValue)) {
+ try {
+ Object yamlValue = new Yaml().loadAs(subPropValue, Object.class);
+ SubPropertyToscaFunction subPropertyToscaFunction = new SubPropertyToscaFunction();
+ CustomYamlFunction toscaFunction = new CustomYamlFunction();
+ toscaFunction.setYamlValue(yamlValue);
+ subPropertyToscaFunction.setToscaFunction(toscaFunction);
+ subPropertyToscaFunction.setSubPropertyPath(Collections.singletonList(prop.getName()));
+ return Optional.of(subPropertyToscaFunction);
+ } catch (Exception exception) {
+ log.info("Cannot create YAML value for {}", subPropValue);
+ }
+ }
+ }
+ return Optional.empty();