From 9c696c0d1787d50a8481f7ccc66f30a3e0b6e197 Mon Sep 17 00:00:00 2001 From: KrupaNagabhushan Date: Thu, 16 Mar 2023 11:45:20 +0000 Subject: Allign properties import during service import Issue-ID: SDC-4438 Signed-off-by: KrupaNagabhushan Change-Id: Iefb3fd84d5087f7e114cd61f762bedfcafe864ec --- .../csar/YamlTemplateParsingHandler.java | 3 ++ .../be/components/impl/InputsBusinessLogic.java | 43 +++++++++++----------- .../impl/ServiceImportBusinessLogic.java | 21 +++++++---- .../property/DefaultPropertyDeclarator.java | 6 ++- .../openecomp/sdc/be/tosca/ToscaExportHandler.java | 13 +++---- 5 files changed, 48 insertions(+), 38 deletions(-) (limited to 'catalog-be/src/main/java/org') 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 5a6a7c91e4..e9d5c025cf 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 @@ -196,6 +196,9 @@ public class YamlTemplateParsingHandler { parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml))); parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate)); } + if (substitutionMappings.get("properties") != null) { + parsedToscaYamlInfo.setSubstitutionMappingProperties((Map>) substitutionMappings.get("properties")); + } parsedToscaYamlInfo.setSubstitutionMappingNodeType((String) substitutionMappings.get(NODE_TYPE.getElementName())); } log.debug("#parseResourceInfoFromYAML - The yaml {} has been parsed ", fileName); diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java index b632abfcca..a24bce9837 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InputsBusinessLogic.java @@ -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 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 = new AtomicReference<>(StorageOperationStatus.OK); - Map> inputDeclaredProperties = new HashMap<>(); + private ImmutablePair validateInputName(final Component component, + final ComponentInstInputsMap componentInstInputsMap) { + final Map> 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 componentInstancePropInputs : inputDeclaredProperties.values()) { + for (final ComponentInstancePropInput componentInstancePropInput : componentInstancePropInputs) { + final Optional 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); } /** diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java index b3f1d57a60..ca8a13dba3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java @@ -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> substitutionMappingProperties) { final List inputs = component.getInputs(); if (CollectionUtils.isNotEmpty(inputs)) { final List 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> substitutionMappingProperties) { final List properties = component.getProperties(); - if (CollectionUtils.isNotEmpty(properties)) { - final String propertyNameFromInput = input.getName(); - final Optional propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput)) + if (CollectionUtils.isNotEmpty(properties) && MapUtils.isNotEmpty(substitutionMappingProperties)) { + AtomicReference propertyNameFromInput = new AtomicReference<>(" "); + substitutionMappingProperties.entrySet().forEach(stringEntry -> { + if (stringEntry.getValue().get(0).equals(input.getName())) { + propertyNameFromInput.set(stringEntry.getKey()); + } + }); + + final Optional propDefOptional = properties.stream().filter(prop -> prop.getName().equals(propertyNameFromInput.get())) .findFirst(); if (propDefOptional.isPresent()) { // From SELF diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java index 31a27b0457..339238f3fc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/DefaultPropertyDeclarator.java @@ -274,7 +274,11 @@ public abstract class DefaultPropertyDeclarator nodeTypes, boolean isAssociatedComponent) { log.debug("start convert node type for {}", component.getUniqueId()); - ToscaNodeType toscaNodeType = createNodeType(component); + ToscaNodeType toscaNodeType = createNodeType(component); Either, 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 dataTypes = dataTypesEither.left().value(); - List 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 convertedProperties = new HashMap(); if (CollectionUtils.isNotEmpty(component.getProperties())) { List properties = component.getProperties(); - Map 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 privateDataTypes = component.getDataTypes(); -- cgit 1.2.3-korg