aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorKrupaNagabhushan <krupa.nagabhushan@est.tech>2023-02-21 14:22:14 +0000
committerMichael Morris <michael.morris@est.tech>2023-03-09 16:52:05 +0000
commit52b078ee0276fbda860d7acf9d29c5fb35542030 (patch)
treef7065f79e45cc5e366d4968f9394d71c480520dd /catalog-be/src/main/java/org/openecomp
parented163d02d66b80496829f611ce03ef6fdf875be3 (diff)
Fix instance declared inputs mapped to substitution mapping
Issue-ID: SDC-4410 Signed-off-by: KrupaNagabhushan <krupa.nagabhushan@est.tech> Change-Id: I7514f197628ace6aff22b51724b9acea0e21944f
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ServiceImportBusinessLogic.java78
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java10
2 files changed, 45 insertions, 43 deletions
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 828439e44b..b3f1d57a60 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
@@ -43,6 +43,7 @@ import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.TreeSet;
+import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -74,7 +75,6 @@ import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datamodel.utils.ArtifactUtils;
-import org.openecomp.sdc.be.datatypes.elements.ComponentInstanceDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.CustomYamlFunction;
import org.openecomp.sdc.be.datatypes.elements.GetInputValueDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ListCapabilityDataDefinition;
@@ -763,10 +763,9 @@ public class ServiceImportBusinessLogic {
if (CollectionUtils.isNotEmpty(inputs)) {
final List<ComponentInstance> componentInstances = component.getComponentInstances();
final String componentUniqueId = component.getUniqueId();
- final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties = component.getComponentInstancesProperties();
for (final InputDefinition input : inputs) {
- if (isInputFromComponentInstanceProperty(input.getName(), componentInstances, componentInstancesProperties)) {
- associateInputToComponentInstanceProperty(userId, input, componentInstances, componentInstancesProperties, componentUniqueId);
+ if (isInputFromComponentInstanceProperty(input.getName(), componentInstances)) {
+ associateInputToComponentInstanceProperty(userId, input, componentInstances, componentUniqueId);
} else {
associateInputToServiceProperty(userId, input, component);
}
@@ -781,50 +780,49 @@ public class ServiceImportBusinessLogic {
return component;
}
- private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances,
- final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties) {
+ private boolean isInputFromComponentInstanceProperty(final String inputName, final List<ComponentInstance> componentInstances) {
+
+ AtomicBoolean isInputFromCIProp = new AtomicBoolean(false);
if (CollectionUtils.isNotEmpty(componentInstances)) {
- // get instance's names
- final List<String> componentInstancesNames = componentInstances.stream().map(ComponentInstanceDataDefinition::getNormalizedName)
- .collect(toList());
- final Optional<String> componentInstancesNameOptional = componentInstancesNames.stream()
- .filter(cin -> inputName.startsWith(cin + "_")).findFirst();
- if (componentInstancesNameOptional.isPresent() && MapUtils.isNotEmpty(componentInstancesProperties)) {
- final Optional<String> componentInstanceIdOptional = componentInstancesProperties.keySet().stream()
- .filter(key -> key.endsWith("." + componentInstancesNameOptional.get())).findFirst();
- if (componentInstanceIdOptional.isPresent()) {
- // get property's name
- final String propertyNameFromInput = extractPropertyNameFromInputName(inputName, componentInstancesNames);
- return componentInstancesProperties.get(componentInstanceIdOptional.get()).stream()
- .anyMatch(prop -> prop.getName().equals(propertyNameFromInput) && prop.getValue() != null
- && prop.getValue().contains(ToscaGetFunctionType.GET_INPUT.getFunctionName()));
+ outer: for (ComponentInstance instance : componentInstances) {
+ for (PropertyDefinition instanceProperty : instance.getProperties()) {
+ if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
+ for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
+ if (inputName.equals(getInputValueDataDefinition.getInputName())) {
+ isInputFromCIProp.set(true);
+ break outer;
+ }
+ }
+ }
}
}
}
- return false;
+ return isInputFromCIProp.get();
}
private void associateInputToComponentInstanceProperty(final String userId, final InputDefinition input,
final List<ComponentInstance> componentInstances,
- final Map<String, List<ComponentInstanceProperty>> componentInstancesProperties,
String componentUniqueId) {
- // From Instance
- final List<String> componentInstancesNames = componentInstances.stream().map(ComponentInstanceDataDefinition::getNormalizedName)
- .collect(toList());
- final String propertyNameFromInput = extractPropertyNameFromInputName(input.getName(), componentInstancesNames);
-
- final Optional<String> componentInstancesNameOptional = componentInstancesNames.stream()
- .filter(cin -> input.getName().startsWith(cin + "_")).findFirst();
-
- final Optional<String> componentInstanceIdOptional = componentInstancesProperties.keySet().stream()
- .filter(key -> key.endsWith("." + componentInstancesNameOptional.get())).findFirst();
- final String componentInstanceId = componentInstanceIdOptional.get();
- final List<ComponentInstanceProperty> componentInstanceProperties = componentInstancesProperties.get(componentInstanceId);
+ String componentInstanceId = null;
+ ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
+
+ outer: for (ComponentInstance instance : componentInstances) {
+ for (PropertyDefinition instanceProperty : instance.getProperties()) {
+ if (CollectionUtils.isNotEmpty(instanceProperty.getGetInputValues())) {
+ for (GetInputValueDataDefinition getInputValueDataDefinition : instanceProperty.getGetInputValues()) {
+ if (input.getName().equals(getInputValueDataDefinition.getInputName())) {
+ componentInstanceId = instance.getUniqueId();
+ componentInstanceProperty = new ComponentInstanceProperty(instanceProperty);
+ break outer;
+ }
+ }
+ }
+ }
+ }
- final ComponentInstanceProperty componentInstanceProperty = componentInstanceProperties.stream()
- .filter(prop -> prop.getName().equals(propertyNameFromInput) && prop.getValue() != null
- && prop.getValue().contains(ToscaGetFunctionType.GET_INPUT.getFunctionName())).findFirst().get();
+ //unmapping instance property declared inputs from substitution mapping
+ input.setMappedToComponentProperty(false);
// From Instance
updateInput(input, componentInstanceProperty, userId, componentInstanceId);
@@ -881,12 +879,6 @@ public class ServiceImportBusinessLogic {
input.setParentPropertyType(propertyDefinition.getType());
}
- private String extractPropertyNameFromInputName(final String inputName, final List<String> componentInstancesNames) {
- final AtomicReference<String> result = new AtomicReference<>(inputName);
- componentInstancesNames.forEach(cin -> result.set(result.get().replace(cin + "_", "")));
- return result.get();
- }
-
protected Either<Resource, ResponseFormat> createOrUpdateArtifacts(ArtifactsBusinessLogic.ArtifactOperationEnum operation,
List<ArtifactDefinition> createdArtifacts, String yamlFileName,
CsarInfo csarInfo, Resource preparedResource,
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
index e5367c4e3d..2d00913e39 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/property/PropertyDeclarationOrchestrator.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentInstancePropertyToPolicyDeclarator;
import org.openecomp.sdc.be.components.property.propertytopolicydeclarators.ComponentPropertyToPolicyDeclarator;
@@ -77,10 +78,19 @@ public class PropertyDeclarationOrchestrator {
ComponentInstInputsMap componentInstInputsMap) {
updatePropertiesConstraints(component, componentInstInputsMap);
PropertyDeclarator propertyDeclarator = getPropertyDeclarator(componentInstInputsMap);
+ undoCISubstitutionMapping(componentInstInputsMap);
Pair<String, List<ComponentInstancePropInput>> propsToDeclare = componentInstInputsMap.resolvePropertiesToDeclare();
return propertyDeclarator.declarePropertiesAsInputs(component, propsToDeclare.getLeft(), propsToDeclare.getRight());
}
+ private void undoCISubstitutionMapping(ComponentInstInputsMap componentInstInputsMap) {
+ if (MapUtils.isNotEmpty(componentInstInputsMap.getComponentInstanceProperties())) {
+ componentInstInputsMap.getComponentInstanceProperties().values()
+ .forEach(componentInstancePropInputsList -> componentInstancePropInputsList.stream()
+ .forEach(componentInstancePropInput -> componentInstancePropInput.setMappedToComponentProperty(false)));
+ }
+ }
+
private void updatePropertiesConstraints(Component component, ComponentInstInputsMap componentInstInputsMap) {
componentInstInputsMap.getComponentInstanceProperties()
.forEach((k, v) -> updatePropsConstraints(component.safeGetComponentInstancesProperties(), k, v));