aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java4
3 files changed, 47 insertions, 45 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));
diff --git a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
index 3294523de1..7409588970 100644
--- a/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
+++ b/integration-tests/src/test/java/org/onap/sdc/frontend/ci/tests/execute/sanity/ServiceTemplateDesignUiTests.java
@@ -822,8 +822,8 @@ public class ServiceTemplateDesignUiTests extends SetupCDTest {
final Map<String, Object> substitutionMappingProperties = getMapEntry(substitutionMapping, "properties");
assertThat(String.format("'%s' should contain a properties entry", toscaYaml), substitutionMappingProperties,
notNullValue());
- assertEquals(2, substitutionMappingProperties.keySet().stream()
- .filter(s -> (s.contains("resourceSubtype") || s.contains("property1"))).count());
+ assertEquals(1, substitutionMappingProperties.keySet().stream()
+ .filter(s -> (s.contains("property1"))).count());
}
private void verifyToscaTemplateAddInput(Map<?, ?> yaml) {