diff options
author | vasraz <vasyl.razinkov@est.tech> | 2021-11-26 14:40:29 +0000 |
---|---|---|
committer | Michael Morris <michael.morris@est.tech> | 2021-11-29 14:36:12 +0000 |
commit | 6c32cbc7343bd56f62007451071c4b26c875382f (patch) | |
tree | fa3250eb24d518e5f15cb629bdb462b96be769c5 /openecomp-be/lib/openecomp-core-lib | |
parent | e9171113772c0c7dc3f7514ffd0660d1e0f8ef02 (diff) |
Add VNFD to NSD when using S3 storage
Change-Id: I8eb810fadfe54b335647e71e21115514963b4be7
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3792
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib')
2 files changed, 26 insertions, 25 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java index 60ff1c172a..d6df24e4c2 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java @@ -30,12 +30,12 @@ import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.onap.sdc.tosca.services.YamlUtil; import org.openecomp.core.utilities.json.JsonUtil; -import org.openecomp.sdc.common.zip.ZipUtils; -import org.openecomp.sdc.common.zip.exception.ZipException; /** * The type File utils. @@ -206,20 +206,24 @@ public class FileUtils { /** * Gets file content map from zip. * - * @param zipData the zip data + * @param inputStream the zip data * @return the file content map from zip - * @throws ZipException when an error occurs while extracting zip files + * @throws IOException when an error occurs while extracting zip files */ - public static FileContentHandler getFileContentMapFromZip(byte[] zipData) throws ZipException { - final Map<String, byte[]> zipFileAndByteMap = ZipUtils.readZip(zipData, true); - final FileContentHandler fileContentHandler = new FileContentHandler(); - zipFileAndByteMap.forEach((path, bytes) -> { - if (bytes == null) { - fileContentHandler.addFolder(path); + public static FileContentHandler getFileContentMapFromZip(final InputStream inputStream) throws IOException { + + final var zipInputStream = new ZipInputStream(inputStream); + ZipEntry zipEntry; + final var fileContentHandler = new FileContentHandler(); + while ((zipEntry = zipInputStream.getNextEntry()) != null) { + final var entryName = zipEntry.getName(); + if (zipEntry.isDirectory()) { + fileContentHandler.addFolder(entryName); } else { - fileContentHandler.addFile(path, bytes); + fileContentHandler.addFile(entryName, zipInputStream.readAllBytes()); } - }); + + } return fileContentHandler; } diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java index facfe57622..05ec5a478d 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java @@ -35,7 +35,6 @@ import java.util.Map; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; import org.openecomp.sdc.common.zip.exception.ZipException; @@ -47,7 +46,7 @@ import org.openecomp.sdc.common.zip.exception.ZipException; public class FileUtilsTest { private static final String TEST_RESOURCE = FileUtilsTest.class.getPackage().getName() - .replace('.', '/') + "/test-resource.txt"; + .replace('.', '/') + "/test-resource.txt"; private static final Function<InputStream, Integer> TEST_FUNCTION = (s) -> { @@ -82,13 +81,11 @@ public class FileUtilsTest { public void testWriteFilesFromFileContentHandler() throws IOException, ZipException { final Path tempDirectory = Files.createTempDirectory("CSAR_" + System.currentTimeMillis()); try { - byte[] uploadedFileData = - IOUtils.toByteArray(FileUtilsTest.class.getResource("resource-Spgw-csar-ZTE.csar")); - final FileContentHandler contentMap = FileUtils.getFileContentMapFromZip(uploadedFileData); + final var contentMap = FileUtils.getFileContentMapFromZip(FileUtilsTest.class.getResourceAsStream("resource-Spgw-csar-ZTE.csar")); final Map<String, String> filePaths = FileUtils.writeFilesFromFileContentHandler(contentMap, tempDirectory); assertThat("The file map should not be empty", filePaths, is(not(anEmptyMap()))); - assertThat("The file map should have size 20", filePaths, is(aMapWithSize(20))); + assertThat("The file map should have size 20", filePaths, is(aMapWithSize(18))); for (final Map.Entry<String, String> fileEntry : filePaths.entrySet()) { final File f = new File(fileEntry.getValue()); assertThat(String.format("The file '%s' is expected to", f.getAbsolutePath()), f.exists(), is(true)); @@ -151,7 +148,7 @@ public class FileUtilsTest { @Test public void testConvertToBytes() { byte[] bytesArray = FileUtils.convertToBytes(Stream.of("Json", "Util", "Test").collect(Collectors.toList()), - FileUtils.FileExtension.YAML); + FileUtils.FileExtension.YAML); Assert.assertNotNull(bytesArray); } @@ -159,7 +156,7 @@ public class FileUtilsTest { @Test public void testConvertToBytesNotYaml() { byte[] bytesArray = FileUtils.convertToBytes(Stream.of("Json", "Util", "Test").collect(Collectors.toList()), - FileUtils.FileExtension.JSON); + FileUtils.FileExtension.JSON); Assert.assertNotNull(bytesArray); } @@ -172,7 +169,7 @@ public class FileUtilsTest { @Test public void testConvertToInputStream() { InputStream inputStream = FileUtils.convertToInputStream(Stream.of("Json", "Util", "Test") - .collect(Collectors.toList()), FileUtils.FileExtension.YAML); + .collect(Collectors.toList()), FileUtils.FileExtension.YAML); Assert.assertNotNull(inputStream); } @@ -183,13 +180,13 @@ public class FileUtilsTest { } @Test - public void testLoadFileToInputStream() throws IOException{ + public void testLoadFileToInputStream() throws IOException { int i; StringBuilder builder = new StringBuilder(20); InputStream inputStream = FileUtils.loadFileToInputStream( - "org/openecomp/core/utilities/file/testFileUtils.txt"); - while((i = inputStream.read())!=-1) { - builder.append((char)i); + "org/openecomp/core/utilities/file/testFileUtils.txt"); + while ((i = inputStream.read()) != -1) { + builder.append((char) i); } Assert.assertNotNull(inputStream); |