aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be
diff options
context:
space:
mode:
authorimamSidero <imam.hussain@est.tech>2022-12-21 17:51:43 +0000
committerimamSidero <imam.hussain@est.tech>2023-01-03 15:03:15 +0000
commitdb3e2ef238fa29e06cec3cb3f5b11fb407b161ce (patch)
tree1dbca1372aa87c881a4ed93a8788e3eff0d38e9d /catalog-be
parent5b1a92cea1fb437c236a77468f3e8e351e25a990 (diff)
Provide tosca function to custom datatypes of list and map
Providing the capability to add tosca function as the custom datatypes of list and map Issue-ID: SDC-4311 Signed-off-by: Imam hussain <imam.hussain@est.tech> Change-Id: I7ec8943d8008440b091fc4eaa2aba49cdadcda8d
Diffstat (limited to 'catalog-be')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java24
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java35
3 files changed, 45 insertions, 26 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
index 150007408a..5a6a7c91e4 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
@@ -1378,25 +1378,23 @@ public class YamlTemplateParsingHandler {
for (Object objValue : propValueList) {
if (objValue instanceof Map) {
Map<String, Object> objMap = (Map<String, Object>) objValue;
+ Map<String, Object> propValueMap = new HashMap<String, Object>();
+ propValueMap.put(String.valueOf(index),objValue);
+ final Collection<SubPropertyToscaFunction> subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>());
+ if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) {
+ Collection<SubPropertyToscaFunction> existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions();
+ if (existingSubPropertyToscaFunctions == null) {
+ propertyDef.setSubPropertyToscaFunctions(subPropertyToscaFunctions);
+ } else {
+ propertyDef.getSubPropertyToscaFunctions().addAll(subPropertyToscaFunctions);
+ }
+ }
if (objMap.containsKey(GET_INPUT.getElementName())) {
fillInputRecursively(propertyDef.getName(), objMap, propertyDef);
} else {
Set<String> keys = objMap.keySet();
findAndFillInputsListRecursively(propertyDef, objMap, keys);
}
- if (toscaFunctionYamlParsingHandler.isPropertyValueToscaFunction(objValue)) {
- Map<String, Object> propValueMap = new HashMap<String, Object>();
- propValueMap.put(String.valueOf(index),objValue);
- final Collection<SubPropertyToscaFunction> subPropertyToscaFunctions = buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>());
- if (CollectionUtils.isNotEmpty(subPropertyToscaFunctions)) {
- Collection<SubPropertyToscaFunction> existingSubPropertyToscaFunctions = propertyDef.getSubPropertyToscaFunctions();
- if (existingSubPropertyToscaFunctions == null) {
- propertyDef.setSubPropertyToscaFunctions(subPropertyToscaFunctions);
- } else {
- propertyDef.getSubPropertyToscaFunctions().addAll(subPropertyToscaFunctions);
- }
- }
- }
} else if (objValue instanceof List) {
List<Object> propSubValueList = (List<Object>) objValue;
fillInputsListRecursively(propertyDef, propSubValueList);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
index 3797fb9fae..fe6ea03562 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ComponentInstanceBusinessLogic.java
@@ -2071,14 +2071,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic {
if (jsonObject.has(path.get(0))) {
objectForPath = jsonObject.get(path.get(0));
} else {
- if (path.size() > 1) {
- if (StringUtils.isNumeric(path.get(1))) {
- objectForPath = new JSONArray();
- } else {
- objectForPath = new JSONObject();
- }
- jsonObject.put(path.get(0), objectForPath);
+ if (StringUtils.isNumeric(path.get(0))) {
+ objectForPath = new JSONArray();
+ } else {
+ objectForPath = new JSONObject();
}
+ jsonObject.put(path.get(0), objectForPath);
}
if (path.size() == 1) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
index 6aa59e4844..19fe69e421 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/PropertyValueConstraintValidationUtil.java
@@ -34,6 +34,7 @@ import org.apache.commons.lang3.StringUtils;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
+import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
import org.openecomp.sdc.be.model.ComponentInstanceInput;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.InputDefinition;
@@ -186,6 +187,21 @@ public class PropertyValueConstraintValidationUtil {
try {
PropertyDefinition newPropertyWithValue;
if (valueMap.containsKey(prop.getName())) {
+ if (propertyDefinition.getSubPropertyToscaFunctions() != null) {
+ for (SubPropertyToscaFunction subPropertyToscaFunction : propertyDefinition.getSubPropertyToscaFunctions()) {
+ final List<String> path = subPropertyToscaFunction.getSubPropertyPath();
+ if (path.size() == 1) {
+ if (path.get(0).equals(prop.getName())) {
+ return;
+ }
+ }
+ if (path.size() > 1) {
+ if (path.get(0).equals(propertyDefinition.getToscaSubPath()) && path.get(1).equals(prop.getName())) {
+ return;
+ }
+ }
+ }
+ }
if (ToscaType.isPrimitiveType(prop.getType())) {
newPropertyWithValue = copyPropertyWithNewValue(prop, String.valueOf(valueMap.get(prop.getName())));
if (isPropertyToEvaluate(newPropertyWithValue)) {
@@ -297,9 +313,14 @@ public class PropertyValueConstraintValidationUtil {
if (propertyDefinition.getSchemaType() == null) {
propertyDefinition.setSchema(createStringSchema());
}
- Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
- });
- evaluateCollectionType(propertyDefinition, list);
+ Collection<Object> list = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {});
+ final Map<String, Object> map = new HashMap<>();
+ int index = 0;
+ for (Object obj : list) {
+ map.put(String.valueOf(index),obj);
+ index++;
+ }
+ evaluateCollectionType(propertyDefinition, map);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
@@ -321,7 +342,7 @@ public class PropertyValueConstraintValidationUtil {
}
final Map<String, Object> map = ConstraintUtil.parseToCollection(propertyDefinition.getValue(), new TypeReference<>() {
});
- evaluateCollectionType(propertyDefinition, map.values());
+ evaluateCollectionType(propertyDefinition, map);
} catch (ConstraintValueDoNotMatchPropertyTypeException e) {
logger.debug(e.getMessage(), e);
errorMessages.add(String.format(VALUE_PROVIDED_IN_INVALID_FORMAT_FOR_PROPERTY, getCompletePropertyName(propertyDefinition)));
@@ -338,12 +359,14 @@ public class PropertyValueConstraintValidationUtil {
}
}
- private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Collection<Object> valueList) {
+ private void evaluateCollectionType(final PropertyDefinition propertyDefinition, final Map<String, Object> valueMap) {
final String schemaType = propertyDefinition.getSchemaType();
- for (final Object value : valueList) {
+ for (String mapKey : valueMap.keySet()) {
+ final Object value = valueMap.get(mapKey);
try {
final PropertyDefinition propertyCopyWithNewValue = copyPropertyWithNewValue(propertyDefinition,
objectMapper.writeValueAsString(value));
+ propertyCopyWithNewValue.setToscaSubPath(mapKey);
if (ToscaType.isPrimitiveType(schemaType)) {
evaluateCollectionPrimitiveSchemaType(propertyCopyWithNewValue, schemaType);
} else if (ToscaType.isCollectionType(schemaType)) {