From d378c37fbd1ecec7b43394926f1ca32a695e07de Mon Sep 17 00:00:00 2001 From: vasraz Date: Mon, 22 Mar 2021 15:33:06 +0000 Subject: Reformat openecomp-be Signed-off-by: Vasyl Razinkov Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1 --- .../OrchestrationTemplateCandidateImpl.java | 255 +++++++++------------ 1 file changed, 113 insertions(+), 142 deletions(-) (limited to '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') 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 b393153ece..48ad75d09c 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 @@ -18,7 +18,6 @@ * Modifications copyright (c) 2019 Nokia * ================================================================================ */ - package org.openecomp.sdcrests.vsp.rest.services; import static org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder.getErrorWithParameters; @@ -74,56 +73,47 @@ import org.springframework.stereotype.Service; @Service("orchestrationTemplateCandidate") @Scope(value = "prototype") public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplateCandidate { - private static final Logger LOGGER = - LoggerFactory.getLogger(OrchestrationTemplateCandidateImpl.class); - private final OrchestrationTemplateCandidateManager candidateManager; - - private final VendorSoftwareProductManager vendorSoftwareProductManager; - private final ActivityLogManager activityLogManager; - - - public OrchestrationTemplateCandidateImpl() { - this.candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(); - this.vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface(); - this.activityLogManager = ActivityLogManagerFactory.getInstance().createInterface(); - } - - // Constructor used in test to avoid mock static - public OrchestrationTemplateCandidateImpl( - OrchestrationTemplateCandidateManager candidateManager, - VendorSoftwareProductManager vendorSoftwareProductManager, - ActivityLogManager activityLogManager) { - this.candidateManager = candidateManager; - this.vendorSoftwareProductManager = vendorSoftwareProductManager; - this.activityLogManager = activityLogManager; - } - - @Override - public Response upload(final String vspId, final String versionId, - final Attachment fileToUpload, final String user) { - final byte[] fileToUploadBytes = fileToUpload.getObject(byte[].class); - final DataHandler dataHandler = fileToUpload.getDataHandler(); - final String filename = ValidationUtils.sanitizeInputString(dataHandler.getName()); - - final OnboardingPackageProcessor onboardingPackageProcessor = new OnboardingPackageProcessor(filename, fileToUploadBytes); - if (onboardingPackageProcessor.hasErrors()) { - final UploadFileResponseDto uploadFileResponseDto = - buildUploadResponseWithError(onboardingPackageProcessor.getErrorMessages().toArray(new ErrorMessage[0])); - return Response.status(Status.NOT_ACCEPTABLE).entity(uploadFileResponseDto).build(); - } - final OnboardPackageInfo onboardPackageInfo = onboardingPackageProcessor.getOnboardPackageInfo().orElse(null); + private static final Logger LOGGER = LoggerFactory.getLogger(OrchestrationTemplateCandidateImpl.class); + private final OrchestrationTemplateCandidateManager candidateManager; + private final VendorSoftwareProductManager vendorSoftwareProductManager; + private final ActivityLogManager activityLogManager; - if (onboardPackageInfo == null) { - final UploadFileResponseDto uploadFileResponseDto = buildUploadResponseWithError( - new ErrorMessage(ErrorLevel.ERROR, Messages.PACKAGE_PROCESS_ERROR.formatMessage(filename))); - return Response.ok(uploadFileResponseDto).build(); + public OrchestrationTemplateCandidateImpl() { + this.candidateManager = OrchestrationTemplateCandidateManagerFactory.getInstance().createInterface(); + this.vendorSoftwareProductManager = VspManagerFactory.getInstance().createInterface(); + this.activityLogManager = ActivityLogManagerFactory.getInstance().createInterface(); } - final VspDetails vspDetails = new VspDetails(ValidationUtils.sanitizeInputString(vspId), - new Version(ValidationUtils.sanitizeInputString(versionId))); - return processOnboardPackage(onboardPackageInfo, vspDetails); - } + // Constructor used in test to avoid mock static + public OrchestrationTemplateCandidateImpl(OrchestrationTemplateCandidateManager candidateManager, + VendorSoftwareProductManager vendorSoftwareProductManager, ActivityLogManager activityLogManager) { + this.candidateManager = candidateManager; + this.vendorSoftwareProductManager = vendorSoftwareProductManager; + this.activityLogManager = activityLogManager; + } + + @Override + public Response upload(final String vspId, final String versionId, final Attachment fileToUpload, final String user) { + final byte[] fileToUploadBytes = fileToUpload.getObject(byte[].class); + final DataHandler dataHandler = fileToUpload.getDataHandler(); + final String filename = ValidationUtils.sanitizeInputString(dataHandler.getName()); + final OnboardingPackageProcessor onboardingPackageProcessor = new OnboardingPackageProcessor(filename, fileToUploadBytes); + if (onboardingPackageProcessor.hasErrors()) { + final UploadFileResponseDto uploadFileResponseDto = buildUploadResponseWithError( + onboardingPackageProcessor.getErrorMessages().toArray(new ErrorMessage[0])); + return Response.status(Status.NOT_ACCEPTABLE).entity(uploadFileResponseDto).build(); + } + final OnboardPackageInfo onboardPackageInfo = onboardingPackageProcessor.getOnboardPackageInfo().orElse(null); + if (onboardPackageInfo == null) { + final UploadFileResponseDto uploadFileResponseDto = buildUploadResponseWithError( + new ErrorMessage(ErrorLevel.ERROR, Messages.PACKAGE_PROCESS_ERROR.formatMessage(filename))); + return Response.ok(uploadFileResponseDto).build(); + } + final VspDetails vspDetails = new VspDetails(ValidationUtils.sanitizeInputString(vspId), + new Version(ValidationUtils.sanitizeInputString(versionId))); + return processOnboardPackage(onboardPackageInfo, vspDetails); + } private Response processOnboardPackage(final OnboardPackageInfo onboardPackageInfo, final VspDetails vspDetails) { final UploadFileResponse uploadFileResponse = candidateManager.upload(vspDetails, onboardPackageInfo); @@ -132,108 +122,89 @@ public class OrchestrationTemplateCandidateImpl implements OrchestrationTemplate return Response.ok(uploadFileResponseDto).build(); } - private UploadFileResponseDto buildUploadResponseWithError(final ErrorMessage... errorMessages) { - final UploadFileResponseDto uploadFileResponseDto = new UploadFileResponseDto(); - final Map> errorMap = new HashMap<>(); - final List errorMessageList = new ArrayList<>(); - Collections.addAll(errorMessageList, errorMessages); - errorMap.put(SdcCommon.UPLOAD_FILE, errorMessageList); - uploadFileResponseDto.setErrors(errorMap); - return uploadFileResponseDto; - } - - @Override - public Response get(String vspId, String versionId, String user) throws IOException { - Optional> zipFile = candidateManager.get(vspId, new Version(versionId)); - String fileName; - if (zipFile.isPresent()) { - fileName = "Candidate." + zipFile.get().getLeft(); - } else { - zipFile = vendorSoftwareProductManager.get(vspId, new Version((versionId))); - - if (!zipFile.isPresent()) { - ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, - getErrorWithParameters( - Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), - "")); - LOGGER.error(errorMessage.getMessage()); - return Response.status(Response.Status.NOT_FOUND).build(); - } - fileName = "Processed." + zipFile.get().getLeft(); + private UploadFileResponseDto buildUploadResponseWithError(final ErrorMessage... errorMessages) { + final UploadFileResponseDto uploadFileResponseDto = new UploadFileResponseDto(); + final Map> errorMap = new HashMap<>(); + final List errorMessageList = new ArrayList<>(); + Collections.addAll(errorMessageList, errorMessages); + errorMap.put(SdcCommon.UPLOAD_FILE, errorMessageList); + uploadFileResponseDto.setErrors(errorMap); + return uploadFileResponseDto; } - Response.ResponseBuilder response = Response.ok(zipFile.get().getRight()); - response.header("Content-Disposition", "attachment; filename=" + fileName); - return response.build(); - } - - @Override - public Response abort(String vspId, String versionId) { - candidateManager.abort(vspId, new Version(versionId)); - return Response.ok().build(); - } - - @Override - public Response process(String vspId, String versionId, String user) { - - Version version = new Version(versionId); - OrchestrationTemplateActionResponse response = candidateManager.process(vspId, version); - - activityLogManager.logActivity(new ActivityLogEntity(vspId, version, - ActivityType.Upload_Network_Package, user, true, "", "")); - - OrchestrationTemplateActionResponseDto responseDto = copyOrchestrationTemplateActionResponseToDto(response); - return Response.ok(responseDto).build(); - } - - @Override - public Response updateFilesDataStructure( - String vspId, String versionId, FileDataStructureDto fileDataStructureDto, String user) { - - FilesDataStructure fileDataStructure = copyFilesDataStructureDtoToFilesDataStructure(fileDataStructureDto); + @Override + public Response get(String vspId, String versionId, String user) throws IOException { + Optional> zipFile = candidateManager.get(vspId, new Version(versionId)); + String fileName; + if (zipFile.isPresent()) { + fileName = "Candidate." + zipFile.get().getLeft(); + } else { + zipFile = vendorSoftwareProductManager.get(vspId, new Version((versionId))); + if (!zipFile.isPresent()) { + ErrorMessage errorMessage = new ErrorMessage(ErrorLevel.ERROR, + getErrorWithParameters(Messages.NO_FILE_WAS_UPLOADED_OR_FILE_NOT_EXIST.getErrorMessage(), "")); + LOGGER.error(errorMessage.getMessage()); + return Response.status(Response.Status.NOT_FOUND).build(); + } + fileName = "Processed." + zipFile.get().getLeft(); + } + Response.ResponseBuilder response = Response.ok(zipFile.get().getRight()); + response.header("Content-Disposition", "attachment; filename=" + fileName); + return response.build(); + } - ValidationResponse response = candidateManager - .updateFilesDataStructure(vspId, new Version(versionId), fileDataStructure); + @Override + public Response abort(String vspId, String versionId) { + candidateManager.abort(vspId, new Version(versionId)); + return Response.ok().build(); + } - if (!response.isValid()) { - return Response.status(Response.Status.EXPECTATION_FAILED).entity( - new MapValidationResponseToDto() - .applyMapping(response, ValidationResponseDto.class)).build(); + @Override + public Response process(String vspId, String versionId, String user) { + Version version = new Version(versionId); + OrchestrationTemplateActionResponse response = candidateManager.process(vspId, version); + activityLogManager.logActivity(new ActivityLogEntity(vspId, version, ActivityType.Upload_Network_Package, user, true, "", "")); + OrchestrationTemplateActionResponseDto responseDto = copyOrchestrationTemplateActionResponseToDto(response); + return Response.ok(responseDto).build(); } - return Response.ok(fileDataStructureDto).build(); - } - - @Override - public Response getFilesDataStructure(String vspId, String versionId, String user) { - Optional filesDataStructure = - candidateManager.getFilesDataStructure(vspId, new Version(versionId)); - if (!filesDataStructure.isPresent()) { - filesDataStructure = vendorSoftwareProductManager.getOrchestrationTemplateStructure(vspId, - new Version(versionId)); + + @Override + public Response updateFilesDataStructure(String vspId, String versionId, FileDataStructureDto fileDataStructureDto, String user) { + FilesDataStructure fileDataStructure = copyFilesDataStructureDtoToFilesDataStructure(fileDataStructureDto); + ValidationResponse response = candidateManager.updateFilesDataStructure(vspId, new Version(versionId), fileDataStructure); + if (!response.isValid()) { + return Response.status(Response.Status.EXPECTATION_FAILED) + .entity(new MapValidationResponseToDto().applyMapping(response, ValidationResponseDto.class)).build(); + } + return Response.ok(fileDataStructureDto).build(); } - FileDataStructureDto fileDataStructureDto = - filesDataStructure.map(dataStructure -> new MapFilesDataStructureToDto() - .applyMapping(dataStructure, FileDataStructureDto.class)) + @Override + public Response getFilesDataStructure(String vspId, String versionId, String user) { + Optional filesDataStructure = candidateManager.getFilesDataStructure(vspId, new Version(versionId)); + if (!filesDataStructure.isPresent()) { + filesDataStructure = vendorSoftwareProductManager.getOrchestrationTemplateStructure(vspId, new Version(versionId)); + } + FileDataStructureDto fileDataStructureDto = filesDataStructure + .map(dataStructure -> new MapFilesDataStructureToDto().applyMapping(dataStructure, FileDataStructureDto.class)) .orElse(new FileDataStructureDto()); - return Response.ok(fileDataStructureDto).build(); - } - - private OrchestrationTemplateActionResponseDto copyOrchestrationTemplateActionResponseToDto(OrchestrationTemplateActionResponse response){ - OrchestrationTemplateActionResponseDto result = new OrchestrationTemplateActionResponseDto(); - result.setErrors(response.getErrors()); - result.setFileNames(response.getFileNames()); - result.setStatus(response.getStatus()); - return result; - } - - private FilesDataStructure copyFilesDataStructureDtoToFilesDataStructure(FileDataStructureDto fileDataStructureDto){ - FilesDataStructure filesDataStructure = new FilesDataStructure(); - filesDataStructure.setArtifacts(fileDataStructureDto.getArtifacts()); - filesDataStructure.setModules(fileDataStructureDto.getModules()); - filesDataStructure.setNested(fileDataStructureDto.getNested()); - filesDataStructure.setUnassigned(fileDataStructureDto.getUnassigned()); - return filesDataStructure; - } + return Response.ok(fileDataStructureDto).build(); + } + + private OrchestrationTemplateActionResponseDto copyOrchestrationTemplateActionResponseToDto(OrchestrationTemplateActionResponse response) { + OrchestrationTemplateActionResponseDto result = new OrchestrationTemplateActionResponseDto(); + result.setErrors(response.getErrors()); + result.setFileNames(response.getFileNames()); + result.setStatus(response.getStatus()); + return result; + } + private FilesDataStructure copyFilesDataStructureDtoToFilesDataStructure(FileDataStructureDto fileDataStructureDto) { + FilesDataStructure filesDataStructure = new FilesDataStructure(); + filesDataStructure.setArtifacts(fileDataStructureDto.getArtifacts()); + filesDataStructure.setModules(fileDataStructureDto.getModules()); + filesDataStructure.setNested(fileDataStructureDto.getNested()); + filesDataStructure.setUnassigned(fileDataStructureDto.getUnassigned()); + return filesDataStructure; + } } -- cgit 1.2.3-korg