summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-common-lib/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-common-lib/src/main')
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java7
-rw-r--r--openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/utils/CommonUtil.java57
2 files changed, 48 insertions, 16 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 f850afbab8..9fff4bd749 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
@@ -32,6 +32,9 @@ public enum Messages {
ZIP_NOT_EXIST("Zip file doesn't exist"),
ZIP_SHOULD_NOT_CONTAIN_FOLDERS("Zip file should not contain folders"),
+ VES_ZIP_SHOULD_CONTAIN_YML_ONLY(
+ "Wrong VES EVENT Artifact was uploaded - all files contained in Artifact must be YAML files" +
+ " (using .yaml/.yml extensions)"),
MANIFEST_NOT_EXIST("Manifest doesn't exist"),
FILE_TYPE_NOT_LEGAL("File type not legal as data for other file"),
MODULE_IN_MANIFEST_NO_YAML("Module '%s', has no yaml file reference"),
@@ -47,6 +50,10 @@ public enum Messages {
CANDIDATE_PROCESS_FAILED("Candidate zip file process failed"),
FOUND_UNASSIGNED_FILES("cannot process zip since it has unassigned files"),
+ /* Monitor uploads related errors*/
+ ILLEGAL_MONITORING_ARTIFACT_TYPE("Illegal monitoring artifact type for component id %s, vsp id " +
+ "%s"),
+
/* manifest errors*/
MISSING_FILE_IN_ZIP("Missing file in zip"),
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 8ffddc48d7..07322c626b 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
@@ -21,37 +21,44 @@
package org.openecomp.sdc.common.utils;
import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.io.FilenameUtils;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.core.utilities.file.FileUtils;
import org.openecomp.sdc.common.errors.CoreException;
import org.openecomp.sdc.common.errors.ErrorCategory;
import org.openecomp.sdc.common.errors.ErrorCode;
+import org.openecomp.sdc.common.errors.Messages;
import org.openecomp.sdc.logging.types.LoggerConstants;
import org.openecomp.sdc.logging.types.LoggerErrorDescription;
-import org.openecomp.sdc.common.errors.Messages;
import org.slf4j.MDC;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class CommonUtil {
- public static String getMethodName() {
- return Thread.currentThread().getStackTrace()[2].getMethodName();
+ public static FileContentHandler validateAndUploadFileContent(byte[] uploadedFileData)
+ throws IOException {
+ return getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(uploadedFileData);
}
- public static FileContentHandler loadUploadFileContent(byte[] uploadedFileData)
- throws IOException {
- return getFileContentMapFromOrchestrationCandidateZip(uploadedFileData);
- }
-
- public static FileContentHandler getFileContentMapFromOrchestrationCandidateZip(byte[] uploadFileData)
- throws IOException {
+ /**
+ * Gets files out of the zip AND validates zip is flat (no folders)
+ *
+ * @param uploadFileData zip file
+ * @return FileContentHandler if input is valid and has no folders
+ */
+ private static FileContentHandler getFileContentMapFromOrchestrationCandidateZipAndValidateNoFolders(
+ byte[] uploadFileData)
+ throws IOException {
ZipEntry zipEntry;
List<String> folderList = new ArrayList<>();
FileContentHandler mapFileContent = new FileContentHandler();
@@ -73,22 +80,25 @@ public class CommonUtil {
} else {
mapFileContent.addFile(currentEntryName, fileByteContent);
}
-
}
} catch (RuntimeException exception) {
throw new IOException(exception);
}
+ validateNoFolders(folderList);
+
+ return mapFileContent;
+ }
+
+ private static void validateNoFolders(List<String> folderList) {
if (CollectionUtils.isNotEmpty(folderList)) {
MDC.put(LoggerConstants.ERROR_DESCRIPTION, LoggerErrorDescription.INVALID_ZIP);
throw new CoreException((new ErrorCode.ErrorCodeBuilder())
- .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
- .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
- .withCategory(ErrorCategory.APPLICATION).build());
+ .withMessage(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withId(Messages.ZIP_SHOULD_NOT_CONTAIN_FOLDERS.getErrorMessage())
+ .withCategory(ErrorCategory.APPLICATION).build());
}
-
- return mapFileContent;
}
private static int lastIndexFileSeparatorIndex(String filePath) {
@@ -103,4 +113,19 @@ public class CommonUtil {
// if we've reached to the start of the string and didn't find file separator - return -1
return -1;
}
+
+ public static boolean validateFilesExtensions(Set<String> allowedExtensions, FileContentHandler
+ files) {
+ for (String fileName : files.getFileList()) {
+ if (!allowedExtensions.contains(FilenameUtils.getExtension(fileName))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static boolean validateAllFilesYml(FileContentHandler files) {
+ Set<String> allowedExtensions = new HashSet<>(Arrays.asList("yml", "yaml"));
+ return validateFilesExtensions(allowedExtensions, files);
+ }
}