diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-common-lib')
4 files changed, 107 insertions, 16 deletions
diff --git a/openecomp-be/lib/openecomp-common-lib/pom.xml b/openecomp-be/lib/openecomp-common-lib/pom.xml index c742056774..0ebbf0632d 100644 --- a/openecomp-be/lib/openecomp-common-lib/pom.xml +++ b/openecomp-be/lib/openecomp-common-lib/pom.xml @@ -34,6 +34,21 @@ <artifactId>logback-classic</artifactId> <version>${logback.version}</version> </dependency> + <dependency> + <groupId>org.openecomp.sdc.core</groupId> + <artifactId>openecomp-utilities-lib</artifactId> + <version>1.1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.5</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.5</version> + </dependency> </dependencies> </project> diff --git a/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup new file mode 100644 index 0000000000..e2333b5ae3 --- /dev/null +++ b/openecomp-be/lib/openecomp-common-lib/pom.xml.versionsBackup @@ -0,0 +1,44 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.openecomp.core</groupId> + <name>openecomp-common-lib</name> + <dependencies> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-utilities-lib</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.openecomp.sdc</groupId> + <artifactId>openecomp-sdc-datatypes-lib</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> + <version>2.0-m10</version> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>${logback.version}</version> + </dependency> + <dependency> + <groupId>org.openecomp.core</groupId> + <artifactId>openecomp-utilities-lib</artifactId> + <version>1.0-SNAPSHOT</version> + </dependency> + </dependencies> + + <artifactId>openecomp-common-lib</artifactId> + + <parent> + <artifactId>openecomp-sdc-lib</artifactId> + <groupId>org.openecomp.sdc</groupId> + <version>1.0-SNAPSHOT</version> + </parent> + + +</project>
\ No newline at end of file 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); + } } |