summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2019-09-19 16:14:01 +0100
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-11-03 15:41:37 +0000
commit433947b5ab5e28fc29aee447de934de89a707419 (patch)
treea485b95b2ae7716ced4825fb7b9eb2b6eeb3433b /openecomp-be/lib
parentee64a64fb0705422c18608304e63a505d10d8ba1 (diff)
Centralize onboarding package validation
Change-Id: I3cc58cf15f62008e83cfc7ddb095d07ab216b82a Issue-ID: SDC-2583 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java8
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/exception/ZipException.java33
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java32
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java102
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java33
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java22
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java107
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java2
-rw-r--r--openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/error/ErrorMessage.java10
-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.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java6
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java18
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java3
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java4
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java17
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java2
-rw-r--r--openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java2
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java4
-rw-r--r--openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java4
24 files changed, 254 insertions, 171 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
index 7163dbecfd..99de164fb3 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -22,6 +22,12 @@ public enum Messages {
VERSION_UPGRADE("Item %s is of old version. A check out was made in order to get new " +
"functionalities"),
+ PACKAGE_PROCESS_ERROR("Could not process package '%s'"),
+ PACKAGE_INVALID_EXTENSION("Invalid package '%s' extension. Expecting %s."),
+ PACKAGE_EMPTY_ERROR("The given package is empty '%s'"),
+ PACKAGE_PROCESS_INTERNAL_PACKAGE_ERROR("Could not process internal package '%s'"),
+ PACKAGE_INVALID_ERROR("Invalid package content '%s'"),
+ PACKAGE_MISSING_INTERNAL_PACKAGE("Missing expected internal package"),
INVALID_ZIP_FILE("Invalid zip file"),
INVALID_CSAR_FILE("Invalid csar file"),
CSAR_FILE_NOT_FOUND("Each CSAR file must contain %s file."),
@@ -207,7 +213,7 @@ public enum Messages {
/* Notifications */
FAILED_TO_MARK_NOTIFICATION_AS_READ("Failed to mark notifications as read"),
FAILED_TO_UPDATE_LAST_SEEN_NOTIFICATION("Failed to update last seen notification for user %s"),
- FAILED_TO_VERIFY_SIGNATURE("Cannot verify signature of signed archive!");
+ FAILED_TO_VERIFY_SIGNATURE("Could not verify signature of signed package.");
private String errorMessage;
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/exception/ZipException.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/exception/ZipException.java
new file mode 100644
index 0000000000..d26fae62e4
--- /dev/null
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/exception/ZipException.java
@@ -0,0 +1,33 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.sdc.common.exception;
+
+import java.io.IOException;
+
+public class ZipException extends IOException {
+
+ public ZipException(String s) {
+ super(s);
+ }
+
+ public ZipException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+}
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
index 8610ecb74b..f286dc1e76 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java
@@ -20,6 +20,7 @@
package org.openecomp.sdc.common.utils;
import com.google.common.collect.Multimap;
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@@ -29,11 +30,14 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.openecomp.core.utilities.file.FileContentHandler;
+import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.core.utilities.orchestration.OnboardingTypesEnum;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
@@ -71,6 +75,14 @@ public class CommonUtil {
return pair.getLeft();
}
+ /**
+ * Extracts the zip in memory and build a pair of {@link FileContentHandler} and the zip folder list. The {@link
+ * FileContentHandler} will only contain the files, not the folders.
+ *
+ * @param uploadFileData the zip file to extract
+ * @return a pair of {@link FileContentHandler} only with the zip files and a list of the zip folders.
+ * @throws ZipException when there was a problem during the zip reading
+ */
public static Pair<FileContentHandler, List<String>> getFileContentMapFromOrchestrationCandidateZip(
byte[] uploadFileData) throws ZipException {
final Map<String, byte[]> zipFileMap = ZipUtils.readZip(uploadFileData, true);
@@ -88,6 +100,26 @@ public class CommonUtil {
return new ImmutablePair<>(mapFileContent, folderList);
}
+ /**
+ * Extracts the zip in memory and build the {@link FileContentHandler}.
+ *
+ * @param zipFile the zip file to extract
+ * @return The {@link FileContentHandler} based on the zip content
+ * @throws ZipException when there was a problem during the zip reading
+ */
+ public static FileContentHandler getZipContent(final byte[] zipFile) throws ZipException {
+ final Map<String, byte[]> zipFileMap = ZipUtils.readZip(zipFile, true);
+ final FileContentHandler fileContentHandler = new FileContentHandler();
+ zipFileMap.forEach((key, value) -> {
+ if (value == null) {
+ fileContentHandler.addFolder(key);
+ } else {
+ fileContentHandler.addFile(key, value);
+ }
+ });
+ return fileContentHandler;
+ }
+
private static void validateNoFolders(List<String> folderList) {
if (CollectionUtils.isNotEmpty(folderList)) {
throw new CoreException((new ErrorCode.ErrorCodeBuilder())
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
index c96ceeb46a..cc13879b96 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
@@ -21,14 +21,12 @@
package org.openecomp.core.utilities.file;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
-import java.util.function.Function;
-
+import java.util.stream.Collectors;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
public class FileContentHandler {
@@ -36,13 +34,12 @@ public class FileContentHandler {
private Map<String, byte[]> files = new HashMap<>();
/**
- * Gets file content.
+ * Gets file content as stream.
*
* @param fileName the file name
- * @return the file content
+ * @return if the file was found, its content as stream, otherwise {@code null}.
*/
- public InputStream getFileContent(String fileName) {
-
+ public InputStream getFileContentAsStream(final String fileName) {
byte[] content = files.get(fileName);
if (content == null || content.length == 0) {
return null;
@@ -51,89 +48,70 @@ public class FileContentHandler {
return new ByteArrayInputStream(content);
}
- /**
- * Applies a business logic to a file's content while taking care of all retrieval logic.
- *
- * @param fileName name of a file inside this content handler.
- * @param processor the business logic to work on the file's input stream, which may not be set
- * (check the {@link Optional} if no such file can be found
- * @param <T> return type, may be {@link java.lang.Void}
- * @return result produced by the processor
- */
- public <T> T processFileContent(String fileName, Function<Optional<InputStream>, T> processor) {
+ public byte[] getFileContent(final String fileName) {
+ return files.get(fileName);
+ }
- // do not throw IOException to mimic the existing uses of getFileContent()
- try (InputStream contentInputStream = getFileContent(fileName)) {
- return processor.apply(Optional.ofNullable(contentInputStream));
- } catch (IOException e) {
- throw new ProcessingException("Failed to process file: " + fileName, e);
- }
+ public boolean isFolder(final String fileName) {
+ return files.get(fileName) == null;
}
- public void addFile(String fileName, byte[] content) {
- files.put(fileName, content);
+ public boolean isFile(final String fileName) {
+ return files.get(fileName) != null;
}
- public void addFile(String fileName, InputStream is) {
+ public void addFolder(final String folder) {
+ files.put(folder, null);
+ }
+
+ public void addFile(final String fileName, final byte[] content) {
+ files.put(fileName, content == null ? new byte[0] : content);
+ }
+ public void addFile(final String fileName, final InputStream is) {
files.put(fileName, FileUtils.toByteArray(is));
}
public Map<String, byte[]> getFiles() {
- return files;
+ return files.entrySet().stream().filter(entry -> entry.getValue() != null)
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
}
- public void setFiles(Map<String, byte[]> files) {
- this.files = files;
+ public void setFiles(final Map<String, byte[]> files) {
+ addAll(files);
}
- public void setFiles(FileContentHandler extFiles) {
- extFiles.getFileList().forEach(fileName -> this.addFile(fileName, extFiles.getFileContent(fileName)));
+ public Set<String> getFileList() {
+ return files.keySet().stream().filter(this::isFile).collect(Collectors.toSet());
}
- public Set<String> getFileList() {
- return files.keySet();
+ public Set<String> getFolderList() {
+ return files.keySet().stream().filter(this::isFolder).collect(Collectors.toSet());
}
- public void putAll(Map<String, byte[]> files) {
- this.files = files;
+ public void addAll(final FileContentHandler fileContentHandlerOther) {
+ if (CollectionUtils.isNotEmpty(fileContentHandlerOther.getFolderList())) {
+ fileContentHandlerOther.getFolderList().forEach(this::addFolder);
+ }
+ addAll(fileContentHandlerOther.getFiles());
}
- public void addAll(FileContentHandler other) {
- this.files.putAll(other.files);
+ private void addAll(final Map<String, byte[]> files) {
+ if (!MapUtils.isEmpty(files)) {
+ files.forEach(this::addFile);
+ }
}
public boolean isEmpty() {
return MapUtils.isEmpty(this.files);
}
- public void remove(String fileName) {
- files.remove(fileName);
+ public byte[] remove(final String fileName) {
+ return files.remove(fileName);
}
- public boolean containsFile(String fileName) {
+ public boolean containsFile(final String fileName) {
return files.containsKey(fileName);
}
- /**
- * An application-specific runtime exception
- */
- private static class ProcessingException extends RuntimeException {
-
- public ProcessingException() {
- super();
- }
-
- public ProcessingException(String message) {
- super(message);
- }
-
- public ProcessingException(Throwable cause) {
- super(cause);
- }
-
- public ProcessingException(String msg, Throwable cause) {
- super(msg, cause);
- }
- }
}
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 31338dcda4..f69a2a060a 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
@@ -229,9 +229,15 @@ public class FileUtils {
public static FileContentHandler getFileContentMapFromZip(byte[] zipData)
throws ZipException {
final Map<String, byte[]> zipFileAndByteMap = ZipUtils.readZip(zipData, true);
- final FileContentHandler mapFileContent = new FileContentHandler();
- mapFileContent.setFiles(zipFileAndByteMap);
- return mapFileContent;
+ final FileContentHandler fileContentHandler = new FileContentHandler();
+ zipFileAndByteMap.forEach((path, bytes) -> {
+ if (bytes == null) {
+ fileContentHandler.addFolder(path);
+ } else {
+ fileContentHandler.addFile(path, bytes);
+ }
+ });
+ return fileContentHandler;
}
@@ -280,24 +286,23 @@ public class FileUtils {
*/
public static Map<String, String> writeFilesFromFileContentHandler(final FileContentHandler fileContentHandler,
final Path dir) throws IOException {
- File file;
final File dirFile = dir.toFile();
final Map<String, String> filePaths = new HashMap<>();
+ File file;
+ for (final String folderPath : fileContentHandler.getFolderList()) {
+ file = new File(dirFile, folderPath);
+ filePaths.put(folderPath, file.getAbsolutePath());
+ if (!file.exists() && !file.mkdirs()) {
+ throw new IOException("Could not create directory " + file.getAbsolutePath());
+ }
+ }
for (final Map.Entry<String, byte[]> fileEntry : fileContentHandler.getFiles().entrySet()) {
file = new File(dirFile, fileEntry.getKey());
filePaths.put(fileEntry.getKey(), file.getAbsolutePath());
final byte[] fileBytes = fileEntry.getValue();
- if (fileBytes == null) {
- if (!file.exists() && !file.mkdirs()) {
- throw new IOException("Could not create directory " + file.getAbsolutePath());
- }
- continue;
- } else {
- if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
- throw new IOException("Could not create parent directory for " + file.getAbsolutePath());
- }
+ if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
+ throw new IOException("Could not create parent directory for " + file.getAbsolutePath());
}
-
try (final FileOutputStream fop = new FileOutputStream(file.getAbsolutePath());) {
fop.write(fileBytes);
fop.flush();
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
index 91cbc2c505..1fa96103ab 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/orchestration/OnboardingTypesEnum.java
@@ -16,14 +16,13 @@
package org.openecomp.core.utilities.orchestration;
-import java.util.Optional;
-
-import static java.util.Arrays.asList;
+import java.util.Arrays;
+import org.apache.commons.lang3.StringUtils;
public enum OnboardingTypesEnum {
- CSAR("csar"), ZIP("zip"), MANUAL("manual"), NONE("none");
- private String type;
+ CSAR("csar"), ZIP("zip"), MANUAL("manual"), NONE("none"), SIGNED_CSAR("signed-csar");
+ private final String type;
- OnboardingTypesEnum(String type) {
+ OnboardingTypesEnum(final String type) {
this.type = type;
}
@@ -32,15 +31,14 @@ public enum OnboardingTypesEnum {
return type;
}
- public static final OnboardingTypesEnum getOnboardingTypesEnum(final String inStr) {
- if (inStr == null) {
+ public static OnboardingTypesEnum getOnboardingTypesEnum(final String type) {
+ if (StringUtils.isEmpty(type)) {
return null;
}
- Optional<OnboardingTypesEnum> onboardingTypesOptional = asList(OnboardingTypesEnum.values()).stream()
- .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equals(inStr.toLowerCase()))
- .findAny();
- return onboardingTypesOptional.orElse(null);
+ return Arrays.stream(OnboardingTypesEnum.values())
+ .filter(onboardingTypesEnum -> onboardingTypesEnum.toString().equalsIgnoreCase(type))
+ .findAny().orElse(null);
}
}
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java
index 0c767a7919..77ada193b3 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java
@@ -16,16 +16,23 @@
package org.openecomp.core.utilities.file;
+import static org.hamcrest.Matchers.aMapWithSize;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
+import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Assert;
@@ -48,7 +55,7 @@ public class FileContentHandlerTest {
Arrays.fill(content, (byte) 44);
contentHandler.addFile(FILE_NAME, content);
- byte[] actualContent = contentHandler.processFileContent(FILE_NAME, optional -> {
+ byte[] actualContent = processFileContent(FILE_NAME, optional -> {
try {
byte[] buffer = new byte[size];
@@ -59,7 +66,7 @@ public class FileContentHandlerTest {
throw new RuntimeException("Unexpected error", e);
}
- });
+ }, contentHandler);
Assert.assertTrue(Arrays.equals(actualContent, content));
}
@@ -67,13 +74,13 @@ public class FileContentHandlerTest {
public void testProcessEmptyFileContent() {
FileContentHandler contentHandler = new FileContentHandler();
contentHandler.addFile(FILE_NAME, new byte[0]);
- assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent));
+ assertFalse(processFileContent(FILE_NAME, Optional::isPresent, contentHandler));
}
@Test
public void testProcessNoFileContent() {
FileContentHandler contentHandler = new FileContentHandler();
- assertFalse(contentHandler.processFileContent("filename", Optional::isPresent));
+ assertFalse(processFileContent("filename", Optional::isPresent, contentHandler));
}
@Test
@@ -88,47 +95,69 @@ public class FileContentHandlerTest {
@Test
public void testSetFiles() {
- FileContentHandler contentHandler = new FileContentHandler();
- Map<String, byte[]> fileMap = Stream.of(new AbstractMap.SimpleEntry<>("file1", new byte[0]),
- new AbstractMap.SimpleEntry<>("file2", new byte[0]))
- .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
-
- contentHandler.setFiles(fileMap);
-
- Assert.assertEquals(contentHandler.getFiles().size(), 2);
- Assert.assertEquals(contentHandler.getFileList().size(), 2);
- assertFalse(contentHandler.isEmpty());
- contentHandler.remove("file1");
- assertFalse(contentHandler.containsFile("file1"));
- }
-
- @Test
- public void testAddAll() {
- FileContentHandler contentHandler = new FileContentHandler();
- FileContentHandler contentHandler1 = createFileHandlerContent();
-
- contentHandler.addAll(contentHandler1);
-
- Assert.assertTrue(contentHandler1.containsFile("file1"));
- Assert.assertEquals(contentHandler.getFiles().size(), 2);
+ //given
+ final FileContentHandler expectedFileContentHandler = createFileContentHandler();
+ //when
+ final FileContentHandler actualContentHandler = new FileContentHandler();
+ actualContentHandler.setFiles(expectedFileContentHandler.getFiles());
+
+ //then
+ final Map<String, byte[]> actualFileMap = actualContentHandler.getFiles();
+ assertThat("Should contain the expected number of folders", actualContentHandler.getFolderList(), hasSize(0));
+ assertThat("Should contain the expected number of files", actualFileMap, aMapWithSize(2));
+ expectedFileContentHandler.getFiles().keySet().forEach(filePath -> {
+ assertThat("Should contain the expected file", actualFileMap.keySet(), hasItem(filePath));
+ });
}
@Test
- public void testSetFilesUsingFIleContentHandlerObject() {
- FileContentHandler contentHandler1 = createFileHandlerContent();
-
- FileContentHandler contentHandler = new FileContentHandler();
- contentHandler.setFiles(contentHandler1);
-
- Assert.assertEquals(contentHandler.getFiles().size(), 2);
+ public void testAddAllFromFileContentHandler() {
+ //given
+ final FileContentHandler expectedFileContentHandler = createFileContentHandler();
+ //when
+ final FileContentHandler actualContentHandler = new FileContentHandler();
+ actualContentHandler.addAll(expectedFileContentHandler);
+ //then
+ final Map<String, byte[]> actualFileMap = actualContentHandler.getFiles();
+ assertThat("Should contain the expected number of files", actualFileMap, aMapWithSize(2));
+ final Set<String> actualFolderList = actualContentHandler.getFolderList();
+ assertThat("Should contain the expected number of folders", actualFolderList, hasSize(3));
+ expectedFileContentHandler.getFiles().keySet().forEach(filePath -> {
+ assertThat("Should contain the expected file", actualFileMap.keySet(), hasItem(filePath));
+ });
+ expectedFileContentHandler.getFolderList().forEach(folderPath -> {
+ assertThat("Should contain the expected file", actualFolderList, hasItem(folderPath));
+ });
}
- private FileContentHandler createFileHandlerContent() {
- FileContentHandler contentHandler1 = new FileContentHandler();
- Map<String, byte[]> fileMap = Stream.of(new AbstractMap.SimpleEntry<>("file1", new byte[0]),
+ private FileContentHandler createFileContentHandler() {
+ final FileContentHandler contentHandler = new FileContentHandler();
+ final Map<String, byte[]> fileMap = Stream.of(new AbstractMap.SimpleEntry<>("file1", new byte[0]),
new AbstractMap.SimpleEntry<>("file2", new byte[0]))
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
- contentHandler1.putAll(fileMap);
- return contentHandler1;
+ contentHandler.setFiles(fileMap);
+ contentHandler.addFolder("folder1");
+ contentHandler.addFolder("folder1/folder2");
+ contentHandler.addFolder("folder3");
+ return contentHandler;
+ }
+
+ /**
+ * Applies a business logic to a file's content while taking care of all retrieval logic.
+ *
+ * @param fileName name of a file inside this content handler.
+ * @param processor the business logic to work on the file's input stream, which may not be set
+ * (check the {@link Optional} if no such file can be found
+ * @param <T> return type, may be {@link java.lang.Void}
+ * @return result produced by the processor
+ */
+ public <T> T processFileContent(String fileName, Function<Optional<InputStream>, T> processor, FileContentHandler contentHandler) {
+
+ // do not throw IOException to mimic the existing uses of getFileContent()
+ try (InputStream contentInputStream = contentHandler.getFileContentAsStream(fileName)) {
+ return processor.apply(Optional.ofNullable(contentInputStream));
+ } catch (IOException e) {
+ throw new RuntimeException("Failed to process file: " + fileName, e);
+ }
}
}
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
index 936f02be67..b10d4862b1 100644
--- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManager.java
@@ -118,7 +118,7 @@ public class HeatTreeManager {
GlobalValidationContext globalContext) {
String fileName = fileHeatStructureTree.getFileName();
- try (InputStream fileContent = this.heatContentMap.getFileContent(fileName)) {
+ try (InputStream fileContent = this.heatContentMap.getFileContentAsStream(fileName)) {
HeatOrchestrationTemplate hot =
new YamlUtil().yamlToObject(fileContent, HeatOrchestrationTemplate.class);
diff --git a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
index 8c6d1354c4..792d9a4854 100644
--- a/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
+++ b/openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/services/tree/HeatTreeManagerUtil.java
@@ -54,7 +54,7 @@ public class HeatTreeManagerUtil {
HeatTreeManager heatTreeManager = new HeatTreeManager();
fileContentMap.getFileList().forEach(
- fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContent(fileName)));
+ fileName -> heatTreeManager.addFile(fileName, fileContentMap.getFileContentAsStream(fileName)));
return heatTreeManager;
}
diff --git a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/error/ErrorMessage.java b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/error/ErrorMessage.java
index 2c88e9d61a..a8aeb17a51 100644
--- a/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/error/ErrorMessage.java
+++ b/openecomp-be/lib/openecomp-sdc-datatypes-lib/src/main/java/org/openecomp/sdc/datatypes/error/ErrorMessage.java
@@ -20,16 +20,17 @@
package org.openecomp.sdc.datatypes.error;
-import org.apache.commons.collections4.CollectionUtils;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import lombok.Getter;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.ToString;
+import org.apache.commons.collections4.CollectionUtils;
@Getter
@EqualsAndHashCode
+@ToString
public class ErrorMessage {
private final ErrorLevel level;
private final String message;
@@ -41,6 +42,9 @@ public class ErrorMessage {
public static class ErrorMessageUtil {
+ private ErrorMessageUtil() {
+ }
+
/**
* Add message list.
*
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 ca1fbe11b7..34954bdbbb 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
@@ -281,7 +281,7 @@ public class MonitoringMibEnricher implements ExternalArtifactEnricherInterface
}
Set<String> fileList = mibs.getFileList();
for (String fileName : fileList) {
- mibServiceArtifact.setContentData(FileUtils.toByteArray(mibs.getFileContent(fileName)));
+ mibServiceArtifact.setContentData(mibs.getFileContent(fileName));
mibServiceArtifact.setName(monitoringArtifactInfo.getName() + File.separator + fileName);
getEnrichedServiceModelDao().storeExternalArtifact(mibServiceArtifact);
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
index f1732fa4f9..76ef37327e 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/TranslationContext.java
@@ -280,11 +280,11 @@ public class TranslationContext {
}
public void setFiles(Map<String, byte[]> files) {
- this.files.putAll(files);
+ this.files.setFiles(files);
}
- public InputStream getFileContent(String fileName) {
- return files.getFileContent(fileName);
+ public InputStream getFileContentAsStream(final String fileName) {
+ return files.getFileContentAsStream(fileName);
}
public void addFile(String name, byte[] content) {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
index 9c21c9cbf6..6b03e29348 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/HeatToToscaUtil.java
@@ -120,7 +120,7 @@ public class HeatToToscaUtil {
public static TranslatorOutput loadAndTranslateTemplateData(FileContentHandler fileNameContentMap) {
HeatToToscaTranslator heatToToscaTranslator = HeatToToscaTranslatorFactory.getInstance().createInterface();
- try (InputStream fileContent = fileNameContentMap.getFileContent(SdcCommon.MANIFEST_NAME)) {
+ try (InputStream fileContent = fileNameContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
heatToToscaTranslator.addManifest(SdcCommon.MANIFEST_NAME, FileUtils.toByteArray(fileContent));
} catch (IOException e) {
throw new SdcRuntimeException("Failed to read manifest", e);
@@ -128,7 +128,7 @@ public class HeatToToscaUtil {
fileNameContentMap.getFileList().stream().filter(fileName -> !(fileName.equals(SdcCommon.MANIFEST_NAME)))
.forEach(fileName -> heatToToscaTranslator.addFile(fileName,
- FileUtils.toByteArray(fileNameContentMap.getFileContent(fileName))));
+ fileNameContentMap.getFileContent(fileName)));
Map<String, List<ErrorMessage>> errors = heatToToscaTranslator.validate();
if (MapUtils.isNotEmpty(MessageContainerUtil.getMessageByLevel(ErrorLevel.ERROR, errors))) {
@@ -233,7 +233,7 @@ public class HeatToToscaUtil {
fileDataCollection.addBaseFiles(fileData);
}
HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil().yamlToObject(
- translationContext.getFileContent(fileName), HeatOrchestrationTemplate.class);
+ translationContext.getFileContentAsStream(fileName), HeatOrchestrationTemplate.class);
if (MapUtils.isNotEmpty(heatOrchestrationTemplate.getResources())) {
referenced.addAll(applyFilterOnFileCollection(heatOrchestrationTemplate, translationContext,
fileDataCollection, filteredFiles));
@@ -565,7 +565,7 @@ public class HeatToToscaUtil {
private static boolean isNestedVlanResource(String nestedHeatFileName, TranslationContext translationContext) {
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
- translationContext.getFileContent(nestedHeatFileName), HeatOrchestrationTemplate.class);
+ translationContext.getFileContentAsStream(nestedHeatFileName), HeatOrchestrationTemplate.class);
return Objects.nonNull(nestedHeatOrchestrationTemplate.getResources()) && nestedHeatOrchestrationTemplate
.getResources().values()
.stream().anyMatch(
@@ -575,7 +575,7 @@ public class HeatToToscaUtil {
public static Optional<String> getSubInterfaceParentPortNodeTemplateId(TranslateTo subInterfaceTo) {
String subInterfaceResourceType = getSubInterfaceResourceType(subInterfaceTo.getResource());
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
- subInterfaceTo.getContext().getFileContent(subInterfaceResourceType), HeatOrchestrationTemplate.class);
+ subInterfaceTo.getContext().getFileContentAsStream(subInterfaceResourceType), HeatOrchestrationTemplate.class);
if (Objects.isNull(nestedHeatOrchestrationTemplate.getResources())) {
return Optional.empty();
}
@@ -664,7 +664,7 @@ public class HeatToToscaUtil {
public static boolean isNestedVfcResource(Resource resource, TranslationContext context) {
Optional<String> nestedHeatFileName = HeatToToscaUtil.getNestedHeatFileName(resource);
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
- context.getFileContent(nestedHeatFileName.get()), HeatOrchestrationTemplate.class);
+ context.getFileContentAsStream(nestedHeatFileName.get()), HeatOrchestrationTemplate.class);
Map<String, Resource> resources = nestedHeatOrchestrationTemplate.getResources();
return Objects.nonNull(resources) && resources.values().stream()
.anyMatch(ConsolidationDataUtil::isComputeResource);
@@ -1366,8 +1366,8 @@ public class HeatToToscaUtil {
private static FileContentHandler getCsarArtifactFiles(TranslationContext translationContext) {
FileContentHandler artifactFiles = new FileContentHandler();
- artifactFiles.setFiles(translationContext.getFiles());
- artifactFiles.setFiles(translationContext.getExternalArtifacts());
+ artifactFiles.addAll(translationContext.getFiles());
+ artifactFiles.addAll(translationContext.getExternalArtifacts());
HeatTreeManager heatTreeManager = HeatTreeManagerUtil.initHeatTreeManager(translationContext.getFiles());
heatTreeManager.createTree();
@@ -1415,7 +1415,7 @@ public class HeatToToscaUtil {
}
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject(
- translationContext.getFileContent(nestedHeatFileName.get()), HeatOrchestrationTemplate.class);
+ translationContext.getFileContentAsStream(nestedHeatFileName.get()), HeatOrchestrationTemplate.class);
if (MapUtils.isNotEmpty(nestedHeatOrchestrationTemplate.getResources())) {
ContrailV2VirtualMachineInterfaceHelper contrailV2VirtualMachineInterfaceHelper =
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
index 32b5e29ac7..866f78c1b5 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/TranslationService.java
@@ -129,7 +129,7 @@ public class TranslationService {
TranslationContext context) {
String heatFileName = heatFileData.getFile();
HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(context.getFileContent(heatFileName), HeatOrchestrationTemplate.class);
+ .yamlToObject(context.getFileContentAsStream(heatFileName), HeatOrchestrationTemplate.class);
translateInputParameters(serviceTemplate, heatOrchestrationTemplate, heatFileData, context,
heatFileName);
@@ -389,7 +389,7 @@ public class TranslationService {
}
for (FileData fileRelatedData : fileRelatedDataList) {
if (fileRelatedData.getType().equals(FileData.Type.HEAT_ENV)) {
- return new YamlUtil().yamlToObject(context.getFileContent(fileRelatedData.getFile()),
+ return new YamlUtil().yamlToObject(context.getFileContentAsStream(fileRelatedData.getFile()),
Environment.class);
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java
index 588c403f7d..6328541927 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/helper/VolumeTranslationHelper.java
@@ -81,7 +81,7 @@ public class VolumeTranslationHelper {
String resourceId, TranslateTo translateTo, List<FileData> fileDatas) {
for (FileData data : fileDatas) {
HeatOrchestrationTemplate heatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(translateTo.getContext().getFiles().getFileContent(data.getFile()),
+ .yamlToObject(translateTo.getContext().getFiles().getFileContentAsStream(data.getFile()),
HeatOrchestrationTemplate.class);
Map<String, Output> outputs = heatOrchestrationTemplate.getOutputs();
if (Objects.isNull(outputs)) {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
index 812fcc90d6..16316f45af 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/functiontranslation/FunctionTranslationGetAttrImpl.java
@@ -28,7 +28,6 @@ import java.util.Optional;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
-import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
import org.onap.sdc.tosca.services.YamlUtil;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.heat.datatypes.model.Resource;
@@ -237,7 +236,7 @@ public class FunctionTranslationGetAttrImpl implements FunctionTranslation {
return Optional.empty();
}
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(context.getFiles().getFileContent(nestedFile.get()), HeatOrchestrationTemplate.class);
+ .yamlToObject(context.getFiles().getFileContentAsStream(nestedFile.get()), HeatOrchestrationTemplate.class);
translatedAttributes.addAll(nestedHeatOrchestrationTemplate.getOutputs().keySet());
return Optional.of(translatedAttributes);
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
index 6b7f1cf5b9..e7449c4105 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/BaseResourceConnection.java
@@ -103,7 +103,7 @@ abstract class BaseResourceConnection<T> {
.get(translateTo.getResource().getType());
List<String> paramNames;
HeatOrchestrationTemplate nestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(translateTo.getContext().getFileContent(nestedFileData.getFile()),
+ .yamlToObject(translateTo.getContext().getFileContentAsStream(nestedFileData.getFile()),
HeatOrchestrationTemplate.class);
List<Map<String, T>> exposedConnectionPoints = getAllConnectionPoints();
for (Map<String, T> connectionPointsMap : exposedConnectionPoints) {
@@ -148,7 +148,7 @@ abstract class BaseResourceConnection<T> {
return Collections.emptyList();
}
HeatOrchestrationTemplate mappedNestedHeatOrchestrationTemplate = new YamlUtil()
- .yamlToObject(translateTo.getContext().getFileContent(mappedNestedHeatFileName),
+ .yamlToObject(translateTo.getContext().getFileContentAsStream(mappedNestedHeatFileName),
HeatOrchestrationTemplate.class);
ServiceTemplate mappedNestedServiceTemplate =
translateTo.getContext().getTranslatedServiceTemplates().get(mappedNestedHeatFileName);
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
index 6702479864..eb4b29d742 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-api/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/utils/CandidateEntityBuilder.java
@@ -56,7 +56,7 @@ public class CandidateEntityBuilder {
Map<String, List<ErrorMessage>> uploadErrors) throws Exception {
//mdcDataDebugMessage.debugEntryMessage("VSP Id", vspDetails.getId());
- try (InputStream zipFileManifest = contentMap.getFileContent(SdcCommon.MANIFEST_NAME)) {
+ try (InputStream zipFileManifest = contentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
HeatFileAnalyzer heatFileAnalyzer = new HeatFileAnalyzerRowDataImpl();
AnalyzedZipHeatFiles analyzedZipHeatFiles =
heatFileAnalyzer.analyzeFilesNotEligibleForModulesFromFileAnalyzer(contentMap.getFiles());
@@ -87,7 +87,7 @@ public class CandidateEntityBuilder {
FileContentHandler fileContentHandler,
AnalyzedZipHeatFiles analyzedZipHeatFiles)
throws IOException {
- try (InputStream manifest = fileContentHandler.getFileContent(SdcCommon.MANIFEST_NAME)) {
+ try (InputStream manifest = fileContentHandler.getFileContentAsStream(SdcCommon.MANIFEST_NAME)) {
if (Objects.isNull(manifest)) {
Optional<ManifestContent> manifestContentOptional =
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
index e727078daa..ca60577b29 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImpl.java
@@ -152,12 +152,11 @@ public class ETSIServiceImpl implements ETSIService {
private Optional<Path> updateNonManoPathInHandler(final FileContentHandler handler, final NonManoType nonManoType,
final Path nonManoOriginalFilePath) {
final Path fixedSourcePath = fixNonManoPath(nonManoOriginalFilePath);
- final Map<String, byte[]> packageFileMap = handler.getFiles();
- if (packageFileMap.containsKey(fixedSourcePath.toString())) {
+ if (handler.containsFile(fixedSourcePath.toString())) {
final Path newNonManoPath = Paths.get(nonManoType.getType(), nonManoType.getLocation()
, fixedSourcePath.getFileName().toString());
- if (!packageFileMap.containsKey(newNonManoPath.toString())) {
- packageFileMap.put(newNonManoPath.toString(), packageFileMap.remove(fixedSourcePath.toString()));
+ if (!handler.containsFile(newNonManoPath.toString())) {
+ handler.addFile(newNonManoPath.toString(), handler.remove(fixedSourcePath.toString()));
return Optional.of(newNonManoPath);
}
}
@@ -254,10 +253,10 @@ public class ETSIServiceImpl implements ETSIService {
ToscaMetadata metadata;
if (handler.containsFile(TOSCA_META_PATH_FILE_NAME)) {
metadata = OnboardingToscaMetadata
- .parseToscaMetadataFile(handler.getFileContent(TOSCA_META_PATH_FILE_NAME));
+ .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
} else if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
metadata = OnboardingToscaMetadata
- .parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME));
+ .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
} else {
throw new IOException("TOSCA.meta file not found!");
}
@@ -267,7 +266,7 @@ public class ETSIServiceImpl implements ETSIService {
private ToscaMetadata getOriginalMetadata(final FileContentHandler handler) throws IOException {
if (handler.containsFile(TOSCA_META_ORIG_PATH_FILE_NAME)) {
return OnboardingToscaMetadata
- .parseToscaMetadataFile(handler.getFileContent(TOSCA_META_ORIG_PATH_FILE_NAME));
+ .parseToscaMetadataFile(handler.getFileContentAsStream(TOSCA_META_ORIG_PATH_FILE_NAME));
} else {
throw new IOException(String.format("%s file not found", TOSCA_META_ORIG_PATH_FILE_NAME));
}
@@ -276,9 +275,9 @@ public class ETSIServiceImpl implements ETSIService {
private InputStream getManifestInputStream(FileContentHandler handler, String manifestLocation) throws IOException {
InputStream io;
if (manifestLocation == null || !handler.containsFile(manifestLocation)) {
- io = handler.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME);
+ io = handler.getFileContentAsStream(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME);
} else {
- io = handler.getFileContent(manifestLocation);
+ io = handler.getFileContentAsStream(manifestLocation);
}
if (io == null) {
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
index 07dc53dfae..5535416838 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/filedatastructuremodule/CandidateServiceImpl.java
@@ -132,7 +132,7 @@ public class CandidateServiceImpl implements CandidateService {
analyzedZipHeatFiles);
handleOtherResources(tree, usedEnvFiles, structure);
FilesDataStructure fileDataStructureFromManifest =
- createFileDataStructureFromManifest(zipContentMap.getFileContent(SdcCommon.MANIFEST_NAME));
+ createFileDataStructureFromManifest(zipContentMap.getFileContentAsStream(SdcCommon.MANIFEST_NAME));
List<String> structureArtifacts = structure.getArtifacts();
structureArtifacts.addAll(fileDataStructureFromManifest.getArtifacts().stream().filter
(artifact -> isNotStrctureArtifact(structureArtifacts, artifact))
diff --git a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
index 3e37125442..1118260a16 100644
--- a/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
+++ b/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/dao/ServiceModelDaoFactoryTest.java
@@ -174,7 +174,7 @@ public class ServiceModelDaoFactoryTest {
artifacts.put("art4", ("this is art4 desc:" + CommonMethods.nextUuId()).getBytes());
FileContentHandler fileContentHandler = new FileContentHandler();
- fileContentHandler.putAll(artifacts);
+ fileContentHandler.setFiles(artifacts);
return fileContentHandler;
}
diff --git a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
index f0d8bb2b3c..ce7024015b 100644
--- a/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
+++ b/openecomp-be/lib/openecomp-tosca-converter-lib/openecomp-tosca-converter-core/src/main/java/org/openecomp/core/impl/AbstractToscaSolConverter.java
@@ -96,7 +96,7 @@ public abstract class AbstractToscaSolConverter extends AbstractToscaConverter {
private String getMainServiceDefinitionFileName(FileContentHandler contentHandler) throws IOException {
try {
ToscaMetadata toscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(
- contentHandler.getFileContent(TOSCA_META_PATH_FILE_NAME));
+ contentHandler.getFileContentAsStream(TOSCA_META_PATH_FILE_NAME));
return toscaMetadata.getMetaEntries().get(TOSCA_META_ENTRY_DEFINITIONS);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
index f4e0ae409e..29b083853a 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java
@@ -123,7 +123,7 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
for (String filenameIncludingPath : externalArtifacts.getFileList()) {
try {
zos.putNextEntry(new ZipEntry(filenameIncludingPath));
- writeBytesToZip(zos, externalArtifacts.getFileContent(filenameIncludingPath));
+ writeBytesToZip(zos, externalArtifacts.getFileContentAsStream(filenameIncludingPath));
} catch (IOException ex) {
throw new RuntimeException(ex);
@@ -143,7 +143,7 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
for (String fileName : artifacts.getFileList()) {
try {
zos.putNextEntry(new ZipEntry(ARTIFACTS_FOLDER_NAME + FILE_SEPARATOR + fileName));
- writeBytesToZip(zos, artifacts.getFileContent(fileName));
+ writeBytesToZip(zos, artifacts.getFileContentAsStream(fileName));
} catch (IOException ex) {
throw new RuntimeException(ex);
diff --git a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
index 92374f57fe..5054c09fab 100644
--- a/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
+++ b/openecomp-be/lib/openecomp-tosca-lib/src/test/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImplTest.java
@@ -104,7 +104,7 @@ public class ToscaFileOutputServiceCsarImplTest {
FileContentHandler heatFiles = new FileContentHandler();
- heatFiles.putAll(dummyHeatArtifacts);
+ heatFiles.setFiles(dummyHeatArtifacts);
Map<String, byte[]> licenseArtifacts = new HashMap<>();
FileContentHandler licenseArtifactsFiles = new FileContentHandler();
@@ -116,7 +116,7 @@ public class ToscaFileOutputServiceCsarImplTest {
ToscaFileOutputServiceCsarImpl.EXTERNAL_ARTIFACTS_FOLDER_NAME + File.separator +
"license-file-2.xml", file1Content.getBytes());
- licenseArtifactsFiles.putAll(licenseArtifacts);
+ licenseArtifactsFiles.setFiles(licenseArtifacts);
byte[] csarFile = toscaFileOutputServiceCSARImpl.createOutputFile(
new ToscaServiceModel(heatFiles, definitionsInput,