X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=catalog-be%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenecomp%2Fsdc%2Fbe%2Fcomponents%2Fimpl%2FComponentInstanceBusinessLogic.java;h=01e87a134bfc7b0c8a238d945d845bf5726b7f98;hb=98826572a529d01250cf4925dc3f26ac8c35478a;hp=142969aa4a9dd834f0a0513e520c489af904b8f7;hpb=589afc753f2cadd9688715b4e5fe54075600060b;p=sdc.git 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 142969aa4a..01e87a134b 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 @@ -44,6 +44,7 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.text.StringEscapeUtils; import org.json.JSONArray; import org.json.JSONObject; import org.onap.sdc.tosca.datatypes.model.PropertyType; @@ -75,6 +76,7 @@ import org.openecomp.sdc.be.datatypes.elements.GetPolicyValueDataDefinition; import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; +import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType; import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum; @@ -1983,11 +1985,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { String propertyParentUniqueId = property.getParentUniqueId(); if (property.isToscaFunction()) { toscaFunctionValidator.validate(property, containerComponent); - property.setValue(property.getToscaFunction().getValue()); + property.setValue(StringEscapeUtils.unescapeJava(property.getToscaFunction().getValue())); + if (ToscaFunctionType.GET_INPUT == property.getToscaFunction().getType()) { + property.setGetInputValues(Collections.singletonList(buildGetInputValue(property))); + } } if (CollectionUtils.isNotEmpty(property.getSubPropertyToscaFunctions())) { ToscaPropertyType type = ToscaPropertyType.isValidType(property.getType()); - if (type.equals(ToscaPropertyType.LIST)) { + if (ToscaPropertyType.LIST.equals(type)) { final JSONArray jsonArray = property.getValue() == null ? new JSONArray() : new JSONArray(property.getValue()); property.getSubPropertyToscaFunctions().stream().forEach(subToscaFunction -> { addE(jsonArray, subToscaFunction.getSubPropertyPath(), subToscaFunction.getToscaFunction().getValue()); @@ -2046,6 +2051,14 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { } } + private GetInputValueDataDefinition buildGetInputValue(final ComponentInstanceProperty property) { + final GetInputValueDataDefinition getInputValueDataDefinition = new GetInputValueDataDefinition(); + getInputValueDataDefinition.setPropName(property.getName()); + getInputValueDataDefinition.setInputName(((ToscaGetFunctionDataDefinition) property.getToscaFunction()).getPropertyName()); + getInputValueDataDefinition.setInputId(((ToscaGetFunctionDataDefinition) property.getToscaFunction()).getPropertyUniqueId()); + return getInputValueDataDefinition; + } + private void addE(JSONArray jsonArray, List path, String value) { Object objectForPath = jsonArray.opt(Integer.parseInt(path.get(0))); if (objectForPath == null) { @@ -2077,7 +2090,7 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { if (jsonObject.has(path.get(0))) { objectForPath = jsonObject.get(path.get(0)); } else { - if (StringUtils.isNumeric(path.get(0))) { + if (path.size() > 1 && StringUtils.isNumeric(path.get(1))) { objectForPath = new JSONArray(); } else { objectForPath = new JSONObject(); @@ -2543,11 +2556,12 @@ public class ComponentInstanceBusinessLogic extends BaseBusinessLogic { referredProperty = findSubProperty(referredProperty, toscaGetFunction, model); } - if (!property.getType().equals(referredProperty.getType())) { + if (!property.getType().equals(referredProperty.getType()) && !"list".equalsIgnoreCase(referredProperty.getType())) { throw ToscaGetFunctionExceptionSupplier .propertyTypeDiverge(toscaGetFunction.getType(), referredProperty.getType(), property.getType()).get(); } - if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { + if (PropertyType.typeHasSchema(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getType()) + && !"list".equalsIgnoreCase(referredProperty.getType()) && !referredProperty.getSchemaType().equals(property.getSchemaType())) { throw ToscaGetFunctionExceptionSupplier .propertySchemaDiverge(toscaGetFunction.getType(), referredProperty.getSchemaType(), property.getSchemaType()).get(); }