summaryrefslogtreecommitdiffstats
path: root/openecomp-be
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java12
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java28
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java23
-rw-r--r--openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java6
4 files changed, 38 insertions, 31 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
index 6fe7f9dd0a..e8ee6b3c4b 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/OrchestrationTemplateCandidateImpl.java
@@ -32,6 +32,7 @@ import static org.openecomp.sdc.common.errors.Messages.NO_FILE_WAS_UPLOADED_OR_F
import static org.openecomp.sdc.common.errors.Messages.PACKAGE_PROCESS_ERROR;
import static org.openecomp.sdc.common.errors.Messages.UNEXPECTED_PROBLEM_HAPPENED_WHILE_GETTING;
+import java.io.ByteArrayInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -183,8 +184,12 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
final var vspDetails = vendorSoftwareProductManager.getVsp(vspId, version);
final Response response = processOnboardPackage(onboardPackageInfo, vspDetails, errorMessages);
final UploadFileResponseDto entity = (UploadFileResponseDto) response.getEntity();
- if (artifactStorageManager.isEnabled() && !entity.getErrors().isEmpty()) {
- artifactStorageManager.delete(artifactInfo);
+ if (artifactStorageManager.isEnabled()) {
+ if (!entity.getErrors().isEmpty()) {
+ artifactStorageManager.delete(artifactInfo);
+ } else {
+ artifactStorageManager.put(vspId, versionId + ".reduced", new ByteArrayInputStream(fileToUploadBytes));
+ }
}
return response;
}
@@ -255,7 +260,8 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate
FilesDataStructure fileDataStructure = copyFilesDataStructureDtoToFilesDataStructure(fileDataStructureDto);
ValidationResponse response = candidateManager.updateFilesDataStructure(vspId, new Version(versionId), fileDataStructure);
if (!response.isValid()) {
- return Response.status(EXPECTATION_FAILED).entity(new MapValidationResponseToDto().applyMapping(response, ValidationResponseDto.class))
+ return Response.status(EXPECTATION_FAILED)
+ .entity(new MapValidationResponseToDto().applyMapping(response, ValidationResponseDto.class))
.build();
}
return Response.ok(fileDataStructureDto).build();
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);
diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
index 06a5b3a2c2..02d0328d3b 100644
--- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
+++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricher.java
@@ -19,6 +19,7 @@ import static org.openecomp.sdc.tosca.services.ToscaConstants.SERVICE_TEMPLATE_F
import static org.openecomp.sdc.tosca.services.ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -41,7 +42,6 @@ import org.openecomp.core.model.types.ServiceArtifact;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.common.errors.Messages;
-import org.openecomp.sdc.common.zip.exception.ZipException;
import org.openecomp.sdc.datatypes.error.ErrorLevel;
import org.openecomp.sdc.datatypes.error.ErrorMessage;
import org.openecomp.sdc.enrichment.EnrichmentInfo;
@@ -208,8 +208,8 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface
}
FileContentHandler mibs;
try {
- mibs = FileUtils.getFileContentMapFromZip(FileUtils.toByteArray(monitoringArtifactInfo.getContent()));
- } catch (ZipException ex) {
+ mibs = FileUtils.getFileContentMapFromZip(monitoringArtifactInfo.getContent());
+ } catch (final IOException ex) {
log.error("Failed to get file content map from zip ", ex);
ErrorMessage.ErrorMessageUtil.addMessage(mibServiceArtifact.getName() + "." + type.name(), errors)
.add(new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_ZIP_FILE.getErrorMessage()));