diff options
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java')
-rw-r--r-- | openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java | 228 |
1 files changed, 118 insertions, 110 deletions
diff --git a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java index db0851cd5f..16147553fe 100644 --- a/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java +++ b/openecomp-be/backend/openecomp-sdc-vendor-software-product-manager/src/main/java/org/openecomp/sdc/vendorsoftwareproduct/impl/orchestration/OrchestrationTemplateCSARHandler.java @@ -30,131 +30,139 @@ import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CS import static org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.CSARConstants.MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME; public class OrchestrationTemplateCSARHandler extends BaseOrchestrationTemplateHandler - implements OrchestrationTemplateFileHandler { - - - @Override - public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData) { - FileContentHandler contentMap = null; - List<String> folderList = new ArrayList<>(); - try { - Pair<FileContentHandler, List<String>> fileContentMapFromOrchestrationCandidateZip = CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData); - contentMap = fileContentMapFromOrchestrationCandidateZip.getKey(); - folderList = fileContentMapFromOrchestrationCandidateZip.getRight(); - } catch (IOException exception) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); - } catch (CoreException coreException) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); - } - validateContent(uploadFileResponse, contentMap, folderList); - return Optional.ofNullable(contentMap); + implements OrchestrationTemplateFileHandler { + + + @Override + public Optional<FileContentHandler> getFileContentMap(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData) { + FileContentHandler contentMap = null; + List<String> folderList = new ArrayList<>(); + try { + Pair<FileContentHandler, List<String>> fileContentMapFromOrchestrationCandidateZip = + CommonUtil.getFileContentMapFromOrchestrationCandidateZip(uploadedFileData); + contentMap = fileContentMapFromOrchestrationCandidateZip.getKey(); + folderList = fileContentMapFromOrchestrationCandidateZip.getRight(); + } catch (IOException exception) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, Messages.INVALID_CSAR_FILE.getErrorMessage())); + } catch (CoreException coreException) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, coreException.getMessage())); } - - private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, List<String> folderList) { - validateManifest(uploadFileResponse, contentMap); - validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); - validateNoExtraFiles(uploadFileResponse, contentMap); - validateFolders(uploadFileResponse, folderList); + validateContent(uploadFileResponse, contentMap, folderList); + return Optional.ofNullable(contentMap); + } + + private void validateContent(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, + List<String> folderList) { + validateManifest(uploadFileResponse, contentMap); + validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_YAML_FILE_NAME); + validateNoExtraFiles(uploadFileResponse, contentMap); + validateFolders(uploadFileResponse, folderList); + } + + private void validateManifest(UploadFileResponse uploadFileResponse, + FileContentHandler contentMap) { + + if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { + return; } - private void validateManifest(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { - - if (!validateFileExist(uploadFileResponse, contentMap, MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)){ - return; - } - - try (InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { + try (InputStream fileContent = contentMap.getFileContent(MAIN_SERVICE_TEMPLATE_MF_FILE_NAME)) { - OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); - if (!onboardingManifest.isValid()) { - onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); - } + OnboardingManifest onboardingManifest = new OnboardingManifest(fileContent); + if (!onboardingManifest.isValid()) { + onboardingManifest.getErrors().forEach(error -> uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, error))); + } - } catch (IOException e) { - // convert to runtime to keep the throws unchanged - throw new RuntimeException("Failed to validate manifest", e); - } + } catch (IOException e) { + // convert to runtime to keep the throws unchanged + throw new RuntimeException("Failed to validate manifest", e); } - - private void validateNoExtraFiles(UploadFileResponse uploadFileResponse, FileContentHandler contentMap) { - List<String> unwantedFiles = contentMap.getFileList().stream() - .filter(this::filterFiles).collect(Collectors.toList()); - if (!unwantedFiles.isEmpty()) { - unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), - unwantedFile)))); - } + } + + private void validateNoExtraFiles(UploadFileResponse uploadFileResponse, + FileContentHandler contentMap) { + List<String> unwantedFiles = contentMap.getFileList().stream() + .filter(this::filterFiles).collect(Collectors.toList()); + if (!unwantedFiles.isEmpty()) { + unwantedFiles.stream().filter(this::filterFiles).forEach(unwantedFile -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILES_NOT_ALLOWED.getErrorMessage(), + unwantedFile)))); } + } + + private void validateFolders(UploadFileResponse uploadFileResponse, List<String> folderList) { + List<String> filterResult = + folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); + if (!filterResult.isEmpty()) { + folderList.stream().filter(this::filterFolders).forEach(unwantedFolder -> + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), + unwantedFolder)))); - private void validateFolders(UploadFileResponse uploadFileResponse, List<String> folderList) { - List<String> filterResult = folderList.stream().filter(this::filterFolders).collect(Collectors.toList()); - if (!filterResult.isEmpty()) { - folderList.stream().filter(this::filterFolders).forEach( unwantedFolder -> - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_DIRECTORIES_NOT_ALLOWED.getErrorMessage(), - unwantedFolder)))); - - } - } - private boolean filterFiles(String inFileName) { - boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName)); - return !valid && filterFolders(inFileName); } + } - private boolean filterFolders(String fileName) { - return ELIGBLE_FOLDERS.stream().noneMatch(fileName::startsWith); - } + private boolean filterFiles(String inFileName) { + boolean valid = ELIGIBLE_FILES.stream().anyMatch(fileName -> fileName.equals(inFileName)); + return !valid && filterFolders(inFileName); + } - private boolean validateFileExist(UploadFileResponse uploadFileResponse, FileContentHandler contentMap, String fileName) { + private boolean filterFolders(String fileName) { + return ELIGBLE_FOLDERS.stream().noneMatch(fileName::startsWith); + } - boolean containsFile = contentMap.containsFile(fileName); - if (!containsFile) { - uploadFileResponse.addStructureError( - SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); - } - return containsFile; - } + private boolean validateFileExist(UploadFileResponse uploadFileResponse, + FileContentHandler contentMap, String fileName) { - @Override - protected boolean updateCandidateData(String vspId, String user, CandidateService candidateService, - VspDetails vspDetails, UploadFileResponse uploadFileResponse, - byte[] uploadedFileData, Optional<FileContentHandler> optionalContentMap) { - try { - candidateService.updateCandidateUploadData(new OrchestrationTemplateCandidateData( - ByteBuffer.wrap(uploadedFileData), ""), vspDetails.getId()); - } catch (Exception exception) { - logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), - getHandlerType().toString()), exception); - uploadFileResponse - .addStructureError( - SdcCommon.UPLOAD_FILE, - new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); - - mdcDataDebugMessage.debugExitMessage("VSP id", vspId); - return true; - } - return false; + boolean containsFile = contentMap.containsFile(fileName); + if (!containsFile) { + uploadFileResponse.addStructureError( + SdcCommon.UPLOAD_FILE, new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.CSAR_FILE_NOT_FOUND.getErrorMessage(), fileName))); } - - - @Override - protected OnboardingTypesEnum getHandlerType() { - return OnboardingTypesEnum.CSAR; + return containsFile; + } + + @Override + protected boolean updateCandidateData(VspDetails vspDetails, byte[] uploadedFileData, + FileContentHandler contentMap, + String fileSuffix, String networkPackageName, + CandidateService candidateService, + UploadFileResponse uploadFileResponse) { + try { + candidateService.updateCandidateUploadData(vspDetails.getId(), vspDetails.getVersion(), + new OrchestrationTemplateCandidateData(ByteBuffer.wrap(uploadedFileData), "", fileSuffix, + networkPackageName)); + } catch (Exception exception) { + logger.error(getErrorWithParameters(Messages.FILE_CONTENT_MAP.getErrorMessage(), + getHandlerType().toString()), exception); + uploadFileResponse.addStructureError(SdcCommon.UPLOAD_FILE, + new ErrorMessage(ErrorLevel.ERROR, exception.getMessage())); + + mdcDataDebugMessage.debugExitMessage("VSP id", vspDetails.getId()); + return true; } + return false; + } - @Override - protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, - byte[] uploadedFileData, CandidateService candidateService) { - return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); - } + @Override + protected OnboardingTypesEnum getHandlerType() { + return OnboardingTypesEnum.CSAR; + } + + @Override + protected boolean isInvalidRawZipData(UploadFileResponse uploadFileResponse, + byte[] uploadedFileData, + CandidateService candidateService) { + return super.isInvalidRawZipData(uploadFileResponse, uploadedFileData, candidateService); + } } |