summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-09-22 14:51:31 +0100
committerMichael Morris <michael.morris@est.tech>2023-09-25 11:03:32 +0000
commitf4668df71072c8ecd4b9d05423006265b36a6ef7 (patch)
tree91c147e039b45b91e65eecea174f94a3b96ad27d /catalog-be/src/main
parentceaf83e0f29c10e4521321abcd6dd17080d2db60 (diff)
Fix 'Substitution Node not updated during import'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I3b99e4c60a5971916ed593b8d4161da58ddab6d6 Issue-ID: SDC-4633
Diffstat (limited to 'catalog-be/src/main')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java20
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandler.java9
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java12
3 files changed, 20 insertions, 21 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
index 7837588178..8352a8d628 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/csar/ServiceCsarInfo.java
@@ -22,6 +22,7 @@
package org.openecomp.sdc.be.components.csar;
import static org.openecomp.sdc.be.components.impl.ImportUtils.Constants.DEFAULT_ICON;
+import static org.openecomp.sdc.be.components.impl.ImportUtils.findFirstToscaStringElement;
import static org.openecomp.sdc.be.components.impl.ImportUtils.findToscaElement;
import fj.data.Either;
@@ -282,16 +283,18 @@ public class ServiceCsarInfo extends CsarInfo {
}
@SuppressWarnings("unchecked")
- private Set<String> getNodeTypesUsedInToscaTemplate(Map<String, Object> mappedToscaTemplate) {
- final Either<Object, ResultStatusEnum> nodeTemplatesEither = findToscaElement(mappedToscaTemplate,
- TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP);
- final Set<String> nodeTypesUsedInNodeTemplates = new HashSet<>();
+ private Set<String> getNodeTypesUsedInToscaTemplate(final Map<String, Object> mappedToscaTemplate) {
+ final var nodeTemplatesEither = findToscaElement(mappedToscaTemplate, TypeUtils.ToscaTagNamesEnum.NODE_TEMPLATES, ToscaElementTypeEnum.MAP);
+ final Set<String> nodeTypesUsedInToscaTemplate = new HashSet<>();
if (nodeTemplatesEither.isLeft()) {
- final Map<String, Map<String, Object>> nodeTemplates =
- (Map<String, Map<String, Object>>) nodeTemplatesEither.left().value();
- nodeTypesUsedInNodeTemplates.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates));
+ final var nodeTemplates = (Map<String, Map<String, Object>>) nodeTemplatesEither.left().value();
+ nodeTypesUsedInToscaTemplate.addAll(findNodeTypesUsedInNodeTemplates(nodeTemplates));
}
- return nodeTypesUsedInNodeTemplates;
+ final var substitutionMappingsNodeType = findFirstToscaStringElement(mappedToscaTemplate, ToscaTagNamesEnum.NODE_TYPE);
+ if (substitutionMappingsNodeType.isLeft()){
+ nodeTypesUsedInToscaTemplate.add(substitutionMappingsNodeType.left().value());
+ }
+ return nodeTypesUsedInToscaTemplate;
}
private NodeTypeMetadata getMetaDataFromTemplate(Map<String, Object> mappedResourceTemplate, String nodeTemplateType) {
@@ -320,7 +323,6 @@ public class ServiceCsarInfo extends CsarInfo {
category.setName((String) metadata.get("category"));
category.setNormalizedName(((String) metadata.get("category")).toLowerCase());
category.setIcons(List.of(DEFAULT_ICON));
- category.setNormalizedName(((String) metadata.get("category")).toLowerCase());
category.addSubCategory(subCategory);
List<CategoryDefinition> categories = new ArrayList<>();
categories.add(category);
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 3b0d19f03c..2d29f80017 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
@@ -109,7 +109,6 @@ import org.openecomp.sdc.be.datatypes.elements.SubPropertyToscaFunction;
import org.openecomp.sdc.be.datatypes.elements.SubstitutionFilterPropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunction;
import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
-import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.datatypes.elements.ToscaFunctionType;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
@@ -201,14 +200,12 @@ public class YamlTemplateParsingHandler {
if (substitutionMappings != null) {
if (component.isService()) {
if (interfaceTemplateYaml.isEmpty()) {
- Resource resource = serviceBusinessLogic.fetchDerivedFromGenericType(component, null);
- List<PropertyDefinition> properties = resource.getProperties();
+ List<PropertyDefinition> properties = serviceBusinessLogic.fetchDerivedFromGenericType(component, null).getProperties();
parsedToscaYamlInfo.setProperties(properties.stream().collect(Collectors.toMap(PropertyDefinition::getName, prop -> prop)));
- parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
} else {
parsedToscaYamlInfo.setProperties(getProperties(loadYamlAsStrictMap(interfaceTemplateYaml)));
- parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
}
+ parsedToscaYamlInfo.setSubstitutionFilterProperties(getSubstitutionFilterProperties(mappedToscaTemplate));
}
if (substitutionMappings.get("properties") != null) {
parsedToscaYamlInfo.setSubstitutionMappingProperties((Map<String, List<String>>) substitutionMappings.get("properties"));
@@ -1442,7 +1439,7 @@ public class YamlTemplateParsingHandler {
for (Object objValue : propValueList) {
if (objValue instanceof Map) {
Map<String, Object> objMap = (Map<String, Object>) objValue;
- Map<String, Object> propValueMap = new HashMap<String, Object>();
+ Map<String, Object> propValueMap = new HashMap<>();
propValueMap.put(String.valueOf(index), objValue);
final Collection<SubPropertyToscaFunction> subPropertyToscaFunctions =
buildSubPropertyToscaFunctions(propValueMap, new ArrayList<>());
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java
index 633dd6e483..3fa8745f01 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java
@@ -643,7 +643,7 @@ public class CommonCsarGenerator {
final List<ToscaImportByModel> modelDefaultImportList = modelOperation.findAllModelImports(modelName, true);
final Set<Path> writtenEntryPathList = new HashSet<>();
final var defsPath = Path.of(definitionsPath);
- Map<Path, byte[]> contentToMerge = new HashMap();
+ Map<Path, byte[]> contentToMerge = new HashMap<>();
for (final ToscaImportByModel toscaImportByModel : modelDefaultImportList) {
var importPath = Path.of(toscaImportByModel.getFullPath());
if (!isSingleImportsFile) {
@@ -675,15 +675,15 @@ public class CommonCsarGenerator {
}
if (!isSingleImportsFile) {
byte[] mergingContent = new byte[0];
- for (Map.Entry entry : contentToMerge.entrySet()) {
+ for (Map.Entry<Path, byte[]> entry : contentToMerge.entrySet()) {
if (ADDITIONAL_TYPE_DEFINITIONS.equals(Paths.get(String.valueOf(entry.getKey())).normalize().toString())) {
- mergingContent = (byte[]) entry.getValue();
+ mergingContent = Bytes.concat(mergingContent, entry.getValue());
} else {
final var zipEntry = new ZipEntry(entry.getKey().toString());
zipOutputStream.putNextEntry(zipEntry);
- writtenEntryPathList.add((Path) entry.getKey());
- zipOutputStream.write(Bytes.concat(mergingContent, (byte[]) entry.getValue()), 0,
- ((byte[]) entry.getValue()).length);
+ writtenEntryPathList.add(entry.getKey());
+ final var concat = Bytes.concat(mergingContent, entry.getValue());
+ zipOutputStream.write(concat, 0, concat.length);
zipOutputStream.closeEntry();
}
}