aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authortalio <tali.orenbach@amdocs.com>2017-12-27 10:40:47 +0200
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>2017-12-27 09:45:48 +0000
commit33b5d647d2edc8c8c68790a309ef3c757d4e6b8a (patch)
tree385a1f8bbc89f1e5a0e9130984d114f526cc41e4 /openecomp-be/lib
parent6395962b153816a24eeada88a01449ce0c59dcbb (diff)
fix TOSCA structure tree
when uploading a csar with two different directories that share the same name, the files structure that appears on the validation screen shows all of the files written under the same directory. this issue got fixed Change-Id: I6da7399271fa1cde384f6feb51d60724584aa8f9 Issue-ID: SDC-535 Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java58
1 files changed, 23 insertions, 35 deletions
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java
index 517c690194..c711c72faf 100644
--- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/ToscaTreeManager.java
@@ -3,77 +3,65 @@ package org.openecomp.sdc.heat.services.tree;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.common.utils.SdcCommon;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
-import org.openecomp.sdc.heat.datatypes.structure.Artifact;
import org.openecomp.sdc.heat.datatypes.structure.HeatStructureTree;
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.regex.Pattern;
public class ToscaTreeManager {
-
- private static Logger logger = (Logger) LoggerFactory.getLogger(ToscaTreeManager.class);
-
private FileContentHandler csarContentMap = new FileContentHandler();
- private byte[] manifest;
private HeatStructureTree tree = new HeatStructureTree();
- private Map<String, Artifact> artifactRef = new HashMap<>();
private Map<String, HeatStructureTree> fileTreeRef = new HashMap<>();
public void addFile(String fileName, byte[] content) {
- if (fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) {
- manifest = content;
-
- } else {
+ if (!fileName.equals(SdcCommon.CSAR_MANIFEST_NAME)) {
csarContentMap.addFile(fileName, content);
}
}
- public void createTree(){
- if (manifest == null) {
- logger.error("Missing manifest file in the zip.");
- return;
- }
-
- for(Map.Entry<String, byte[]> fileEntry : csarContentMap.getFiles().entrySet()){
+ public void createTree() {
+ for (Map.Entry<String, byte[]> fileEntry : csarContentMap.getFiles().entrySet()) {
String[] splitFilename = getFullFileNameAsArray(fileEntry.getKey());
- addFileToTree(splitFilename, 0, tree);
+ addFileToTree(splitFilename, 0, splitFilename[0], tree);
}
-
-
}
- private void addFileToTree(String[] splitFilename, int startIndex, HeatStructureTree parent){
- fileTreeRef.putIfAbsent(splitFilename[startIndex], new HeatStructureTree());
- HeatStructureTree heatStructureTree = fileTreeRef.get(splitFilename[startIndex]);
+ private void addFileToTree(String[] splitFilename, int startIndex, String fullFileName,
+ HeatStructureTree parent) {
+ fileTreeRef.putIfAbsent(fullFileName, new HeatStructureTree());
+ HeatStructureTree heatStructureTree = fileTreeRef.get(fullFileName);
heatStructureTree.setFileName(splitFilename[startIndex]);
- if(startIndex < splitFilename.length - 1){
- addFileToTree(splitFilename, startIndex + 1, heatStructureTree);
+ if (startIndex < splitFilename.length - 1) {
+ addFileToTree(splitFilename, startIndex + 1,
+ getFullFileName(fullFileName, splitFilename[startIndex + 1]), heatStructureTree);
}
parent.addHeatStructureTreeToNestedHeatList(heatStructureTree);
}
- public void addErrors(Map<String, List<ErrorMessage>> validationErrors){
- validationErrors.entrySet().stream().filter(entry -> {
- return fileTreeRef.get(entry.getKey()) != null;
- }).forEach(entry -> entry.getValue().stream().forEach(error ->
- fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error)));
+ public void addErrors(Map<String, List<ErrorMessage>> validationErrors) {
+ validationErrors.entrySet().stream().filter(entry ->
+ Objects.nonNull(fileTreeRef.get(entry.getKey()))).forEach(entry -> entry.getValue()
+ .forEach(error -> fileTreeRef.get(entry.getKey()).addErrorToErrorsList(error)));
+ }
+
+ private String getFullFileName(String parentFullName, String fileName) {
+ return parentFullName + File.separator + fileName;
}
- private String[] getFullFileNameAsArray(String filename){
- if(filename.contains("/")){
+ private String[] getFullFileNameAsArray(String filename) {
+ if (filename.contains("/")) {
return filename.split("/");
}
return filename.split(Pattern.quote(File.separator));
}
- public HeatStructureTree getTree(){
+ public HeatStructureTree getTree() {
return tree;
}
}