summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2023-09-28 10:57:58 +0100
committerVasyl Razinkov <vasyl.razinkov@est.tech>2023-09-28 10:27:02 +0000
commit4c610d5fbba2927b6f7cd985504882d8b02b95e4 (patch)
tree814b53aa58eca384d6d4ca5c7c1df2f00e35a69b /catalog-be/src
parentdec130c86743219fc3741fe6c9d897477bd082bf (diff)
Fix 'CSAR contains duplicate syntax'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: I4c46d583ef30439b1a5ce5dc9f84f5a6ce50fde1 Issue-ID: SDC-4638
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/CommonCsarGenerator.java45
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java2
2 files changed, 37 insertions, 10 deletions
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 3fa8745f01..aee8b65ca3 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
@@ -46,6 +46,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -108,6 +109,7 @@ import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.Yaml;
/**
@@ -652,8 +654,7 @@ public class CommonCsarGenerator {
contentToMerge.put(entryPath, toscaImportByModel.getContent().getBytes(StandardCharsets.UTF_8));
} else {
if (writtenEntryPathList.contains(defsPath.resolve(importPath))) {
- importPath =
- ToscaDefaultImportHelper.addModelAsFilePrefix(importPath, toscaImportByModel.getModelId());
+ importPath = ToscaDefaultImportHelper.addModelAsFilePrefix(importPath, toscaImportByModel.getModelId());
}
final Path entryPath = defsPath.resolve(importPath);
writtenEntryPathList.add(entryPath);
@@ -661,12 +662,10 @@ public class CommonCsarGenerator {
}
} else {
if (writtenEntryPathList.contains(defsPath.resolve(importPath))) {
- importPath =
- ToscaDefaultImportHelper.addModelAsFilePrefix(importPath, toscaImportByModel.getModelId());
+ importPath = ToscaDefaultImportHelper.addModelAsFilePrefix(importPath, toscaImportByModel.getModelId());
}
final Path entryPath = defsPath.resolve(importPath);
- final var zipEntry = new ZipEntry(entryPath.toString());
- zipOutputStream.putNextEntry(zipEntry);
+ zipOutputStream.putNextEntry(new ZipEntry(entryPath.toString()));
writtenEntryPathList.add(entryPath);
final byte[] content = toscaImportByModel.getContent().getBytes(StandardCharsets.UTF_8);
zipOutputStream.write(content, 0, content.length);
@@ -677,13 +676,13 @@ public class CommonCsarGenerator {
byte[] mergingContent = new byte[0];
for (Map.Entry<Path, byte[]> entry : contentToMerge.entrySet()) {
if (ADDITIONAL_TYPE_DEFINITIONS.equals(Paths.get(String.valueOf(entry.getKey())).normalize().toString())) {
- mergingContent = Bytes.concat(mergingContent, entry.getValue());
+ mergingContent = mergeContent(mergingContent, entry.getValue());
} else {
final var zipEntry = new ZipEntry(entry.getKey().toString());
zipOutputStream.putNextEntry(zipEntry);
writtenEntryPathList.add(entry.getKey());
- final var concat = Bytes.concat(mergingContent, entry.getValue());
- zipOutputStream.write(concat, 0, concat.length);
+ mergingContent = mergeContent(mergingContent, entry.getValue());
+ zipOutputStream.write(mergingContent, 0, mergingContent.length);
zipOutputStream.closeEntry();
}
}
@@ -695,6 +694,34 @@ public class CommonCsarGenerator {
}
}
+ private byte[] mergeContent(final byte[] first, final byte[] second) {
+ byte[] merged = new byte[0];
+ final Map<String, Object> firstMap = new Yaml().load(new String(first));
+ final Map<String, Object> secondMap = new Yaml().load(new String(second));
+ if (MapUtils.isNotEmpty(secondMap)) {
+ final DumperOptions options = new DumperOptions();
+ options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
+ final Yaml yaml = new Yaml(options);
+ for (final Entry<String, Object> secondMapEntry : secondMap.entrySet()) {
+ final Map<String, Object> newMap = new HashMap<>();
+ if (secondMapEntry.getKey().endsWith("_types")) {
+ if (MapUtils.isNotEmpty(firstMap) && firstMap.containsKey(secondMapEntry.getKey())) {
+ final Map<String, Object> secondMapEntryValue = (Map<String, Object>) secondMapEntry.getValue();
+ final Map<String, Object> firstMapValue = (Map<String, Object>) firstMap.get(secondMapEntry.getKey());
+ secondMapEntryValue.putAll(firstMapValue);
+ newMap.put(secondMapEntry.getKey(), secondMapEntryValue);
+ } else {
+ newMap.put(secondMapEntry.getKey(), secondMapEntry.getValue());
+ }
+ } else {
+ newMap.put(secondMapEntry.getKey(), secondMapEntry.getValue());
+ }
+ merged = Bytes.concat(merged, yaml.dumpAsMap(newMap).getBytes());
+ }
+ }
+ return merged;
+ }
+
private Either<CsarDefinition, ResponseFormat> collectComponentCsarDefinition(Component component) {
ComponentArtifacts componentArtifacts = new ComponentArtifacts();
Component updatedComponent = component;
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index 0b57cfe412..8c802bc43e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -674,7 +674,7 @@ public class ToscaExportHandler {
toscaMetadata.put(JsonPresentationFields.INSTANTIATION_TYPE.getPresentation(),
service.getEnvironmentContext() == null ? StringUtils.EMPTY : service.getInstantiationType());
if (!isInstance) {
- toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(), service.isEcompGeneratedNaming());
+ toscaMetadata.put(JsonPresentationFields.ECOMP_GENERATED_NAMING.getPresentation(), service.isEcompGeneratedNaming().toString());
toscaMetadata.put(JsonPresentationFields.NAMING_POLICY.getPresentation(), service.getNamingPolicy());
}
break;