Allign properties import during service import 78/133678/5
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>
Thu, 16 Mar 2023 11:45:20 +0000 (11:45 +0000)
committerVasyl Razinkov <vasyl.razinkov@est.tech>
Tue, 21 Mar 2023 14:06:57 +0000 (14:06 +0000)
Issue-ID: SDC-4438
Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech>
Change-Id: Iefb3fd84d5087f7e114cd61f762bedfcafe864ec

catalog-be/src/main/docker/backend/chef-repo/cookbooks/sdc-catalog-be/files/default/error-configuration.yaml
catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java
catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java
catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
catalog-model/src/main/java/org/openecomp/sdc/be/model/ParsedToscaYamlInfo.java

index fe32ad0..ba2e58d 100644 (file)
@@ -2871,9 +2871,10 @@ errors:
         messageId: "SVC4015"
     }
 
+    # %1 - The input name
     #---------SVC4016-----------------------------
     INPUT_NAME_ALREADY_EXIST: {
         code: 400,
-        message: "Input name already exist.",
+        message: "Input name '%1' already exist.",
         messageId: "SVC4016"
     }
\ No newline at end of file
index 5a6a7c9..e9d5c02 100644 (file)
@@ -196,6 +196,9 @@ public class YamlTemplateParsingHandler {
                 parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml)));
                 parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
             }
+            if (substitutionMappings.get("properties") != null) {
+                parsedToscaYamlInfo.setSubstitutionMappingProperties((Map<String, List<String>>) substitutionMappings.get("properties"));
+            }
             parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) substitutionMappings.get(NODE_TYPE.getElementName()));
         }
         log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName);
index b632abf..a24bce9 100644 (file)
@@ -38,6 +38,7 @@ import org.apache.commons.collections4.MapUtils;
 import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
+import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
@@ -399,10 +400,10 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
         try {
             validateUserExists(userId);
             component = getAndValidateComponentForCreate(userId, componentId, componentType, shouldLockComp);
-            StorageOperationStatus status = validateInputName(component, componentInstInputsMapUi);
-            if (status != StorageOperationStatus.OK) {
+            ImmutablePair<StorageOperationStatus, String> status = validateInputName(component, componentInstInputsMapUi);
+            if (status.getLeft() != StorageOperationStatus.OK) {
                 log.debug("Input name already exist");
-                throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INPUT_NAME_ALREADY_EXIST));
+                throw new ByResponseFormatComponentException(componentsUtils.getResponseFormat(ActionStatus.INPUT_NAME_ALREADY_EXIST, status.getRight()));
             }
             result = propertyDeclarationOrchestrator.declarePropertiesToInputs(component, componentInstInputsMapUi).left()
                 .bind(inputsToCreate -> prepareInputsForCreation(userId, componentId, inputsToCreate)).right()
@@ -429,29 +430,27 @@ public class InputsBusinessLogic extends BaseBusinessLogic {
         }
     }
 
-    private StorageOperationStatus validateInputName(final Component component, final ComponentInstInputsMap componentInstInputsMap) {
-        AtomicReference<StorageOperationStatus> storageOperationStatus = new AtomicReference<>(StorageOperationStatus.OK);
-        Map<String, List<ComponentInstancePropInput>> inputDeclaredProperties = new HashMap<>();
+    private ImmutablePair<StorageOperationStatus, String> validateInputName(final Component component,
+                                                                            final ComponentInstInputsMap componentInstInputsMap) {
+        final Map<String, List<ComponentInstancePropInput>> inputDeclaredProperties = new HashMap<>();
         if (MapUtils.isNotEmpty(componentInstInputsMap.getComponentInstanceProperties())) {
-            inputDeclaredProperties = componentInstInputsMap.getComponentInstanceProperties();
+            inputDeclaredProperties.putAll(componentInstInputsMap.getComponentInstanceProperties());
         } else if (MapUtils.isNotEmpty(componentInstInputsMap.getServiceProperties())) {
-            inputDeclaredProperties = componentInstInputsMap.getServiceProperties();
+            inputDeclaredProperties.putAll(componentInstInputsMap.getServiceProperties());
         }
-
         if (MapUtils.isNotEmpty(inputDeclaredProperties) && CollectionUtils.isNotEmpty(component.getInputs())) {
-            inputDeclaredProperties.values()
-                .forEach(componentInstancePropInputs ->
-                    componentInstancePropInputs
-                        .forEach(componentInstancePropInput -> component.getInputs()
-                            .forEach(existingInput -> {
-                                if (existingInput.getName().equals(componentInstancePropInput.getInputName())) {
-                                    storageOperationStatus.set(StorageOperationStatus.INVALID_VALUE);
-                                }
-                            })
-                        )
-                );
-        }
-        return storageOperationStatus.get();
+            for (final List<ComponentInstancePropInput> componentInstancePropInputs : inputDeclaredProperties.values()) {
+                for (final ComponentInstancePropInput componentInstancePropInput : componentInstancePropInputs) {
+                    final Optional<InputDefinition> inputDefinition = component.getInputs().stream()
+                        .filter(input -> input.getName().equals(componentInstancePropInput.getInputName())
+                            || input.getName().equals(componentInstancePropInput.getName())).findAny();
+                    if (inputDefinition.isPresent()) {
+                        return new ImmutablePair<>(StorageOperationStatus.INVALID_VALUE, inputDefinition.get().getName());
+                    }
+                }
+            }
+        }
+        return new ImmutablePair<>(StorageOperationStatus.OK, StringUtils.EMPTY);
     }
 
     /**
index b3f1d57..ca8a13d 100644 (file)
@@ -736,7 +736,7 @@ public class ServiceImportBusinessLogic {
                 throw new ComponentException(createArtifactsEither.right().value());
             }
             service = serviceImportParseLogic.getServiceWithGroups(createArtifactsEither.left().value().getUniqueId());
-            service = updateInputs(service, userId);
+            service = updateInputs(service, userId, parsedToscaYamlInfo.getSubstitutionMappingProperties());
 
             ASDCKpiApi.countCreatedResourcesKPI();
             return service;
@@ -758,7 +758,7 @@ public class ServiceImportBusinessLogic {
         }
     }
 
-    private Service updateInputs(final Service component, final String userId) {
+    private Service updateInputs(final Service component, final String userId, final Map<String, List<String>> substitutionMappingProperties) {
         final List<InputDefinition> inputs = component.getInputs();
         if (CollectionUtils.isNotEmpty(inputs)) {
             final List<ComponentInstance> componentInstances = component.getComponentInstances();
@@ -767,7 +767,7 @@ public class ServiceImportBusinessLogic {
                 if (isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
                     associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId);
                 } else {
-                    associateInputToServiceProperty(userId, input, component);
+                    associateInputToServiceProperty(userId, input, component, substitutionMappingProperties);
                 }
             }
 
@@ -836,11 +836,18 @@ public class ServiceImportBusinessLogic {
     }
 
     private void associateInputToServiceProperty(final String userId,
-                                                 final InputDefinition input, final Service component) {
+                                                 final InputDefinition input, final Service component,
+                                                 final Map<String, List<String>> substitutionMappingProperties) {
         final List<PropertyDefinition> properties = component.getProperties();
-        if (CollectionUtils.isNotEmpty(properties)) {
-            final String propertyNameFromInput = input.getName();
-            final Optional<PropertyDefinition> propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput))
+        if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) {
+            AtomicReference<String> propertyNameFromInput = new AtomicReference<>(" ");
+            substitutionMappingProperties.entrySet().forEach(stringEntry -> {
+                if (stringEntry.getValue().get(0).equals(input.getName())) {
+                    propertyNameFromInput.set(stringEntry.getKey());
+                }
+            });
+
+            final Optional<PropertyDefinition> propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get()))
                 .findFirst();
             if (propDefOptional.isPresent()) {
                 // From SELF
index 31a27b0..339238f 100644 (file)
@@ -274,7 +274,11 @@ public abstract class DefaultPropertyDeclarator<PROPERTYOWNER extends Properties
             String[] propName = {propInput.getName()};
             declaredInputName = handleInputName(inputName, propName);
         }
-        return declaredInputName;
+        return validateDeclaredInputName(declaredInputName);
+    }
+
+    private String validateDeclaredInputName(String inputName) {
+        return inputName.replace("::", "_");
     }
 
     private String handleInputName(String inputName, String[] parsedPropNames) {
index 186bcd2..de35bcf 100644 (file)
@@ -817,7 +817,7 @@ public class ToscaExportHandler {
                                                                       ToscaTemplate toscaNode, Map<String, ToscaNodeType> nodeTypes,
                                                                       boolean isAssociatedComponent) {
         log.debug("start convert node type for {}", component.getUniqueId());
-        ToscaNodeType toscaNodeType = createNodeType(component);
+         ToscaNodeType toscaNodeType = createNodeType(component);
         Either<Map<String, InterfaceDefinition>, StorageOperationStatus> lifecycleTypeEither = interfaceLifecycleOperation
             .getAllInterfaceLifecycleTypes(component.getModel());
         if (lifecycleTypeEither.isRight() && !StorageOperationStatus.NOT_FOUND.equals(lifecycleTypeEither.right().value())) {
@@ -835,24 +835,21 @@ public class ToscaExportHandler {
             return Either.right(ToscaError.GENERAL_ERROR);
         }
         Map<String, DataTypeDefinition> dataTypes = dataTypesEither.left().value();
-        List<InputDefinition> inputDef = component.getInputs();
         interfacesOperationsConverter.addInterfaceDefinitionElement(component, toscaNodeType, dataTypes, isAssociatedComponent);
         final var toscaAttributeMap = convertToToscaAttributes(component.getAttributes(), dataTypes);
         if (!toscaAttributeMap.isEmpty()) {
             toscaNodeType.setAttributes(toscaAttributeMap);
         }
-        final var mergedProperties = convertInputsToProperties(dataTypes, inputDef, component.getUniqueId());
+        Map<String, ToscaProperty> convertedProperties = new HashMap();
         if (CollectionUtils.isNotEmpty(component.getProperties())) {
             List<PropertyDefinition> properties = component.getProperties();
-            Map<String, ToscaProperty> convertedProperties = properties.stream()
+            convertedProperties = properties.stream()
                 .map(propertyDefinition -> resolvePropertyValueFromInput(propertyDefinition, component.getInputs())).collect(Collectors
                     .toMap(PropertyDataDefinition::getName,
                         property -> propertyConvertor.convertProperty(dataTypes, property, PropertyConvertor.PropertyType.PROPERTY)));
-            // merge component properties and inputs properties
-            mergedProperties.putAll(convertedProperties);
         }
-        if (MapUtils.isNotEmpty(mergedProperties)) {
-            toscaNodeType.setProperties(mergedProperties);
+        if (MapUtils.isNotEmpty(convertedProperties)) {
+            toscaNodeType.setProperties(convertedProperties);
         }
         /* convert private data_types */
         List<DataTypeDefinition> privateDataTypes = component.getDataTypes();
index 326cfca..03e3de5 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.openecomp.sdc.be.model;
 
+import java.util.List;
 import java.util.Map;
 import lombok.Getter;
 import lombok.Setter;
@@ -39,4 +40,5 @@ public class ParsedToscaYamlInfo {
     Map<String, PropertyDefinition> properties;
     ListDataDefinition<SubstitutionFilterPropertyDataDefinition> substitutionFilterProperties;
     String substitutionMappingNodeType;
+    Map<String, List<String>> substitutionMappingProperties;
 }