From 5f3a0ea3230fc09bb66a5b6fbd65868fe2a46e6c Mon Sep 17 00:00:00 2001 From: vempo Date: Mon, 23 Oct 2017 13:28:46 +0300 Subject: Fixed resources not being released, code cleanup Properly close input streams; code cleanup; fixed static analysis violations and coding convetions. Change-Id: I53dabcc9f8898a0ab25636735cb0b5f84b57c427 Issue-ID: SDC-291 Signed-off-by: vempo --- .../impl/UploadValidationManagerImpl.java | 21 ++++++++------------- .../sdc/validation/util/ValidationManagerUtil.java | 12 +++++++----- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'openecomp-be/backend/openecomp-sdc-validation-manager/src') diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java index ddb56ddbfc..1d1ce4f03c 100644 --- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java +++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java @@ -62,20 +62,19 @@ import java.util.zip.ZipInputStream; */ public class UploadValidationManagerImpl implements UploadValidationManager { - private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage(); + private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage(); private static FileContentHandler getFileContentMapFromZip(byte[] uploadFileData) throws IOException, CoreException { + ZipEntry zipEntry; List folderList = new ArrayList<>(); FileContentHandler mapFileContent = new FileContentHandler(); - try { - ZipInputStream inputZipStream; + try (ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData))) { byte[] fileByteContent; String currentEntryName; - inputZipStream = new ZipInputStream(new ByteArrayInputStream(uploadFileData)); while ((zipEntry = inputZipStream.getNextEntry()) != null) { currentEntryName = zipEntry.getName(); @@ -130,7 +129,7 @@ public class UploadValidationManagerImpl implements UploadValidationManager { throws IOException { - mdcDataDebugMessage.debugEntryMessage(null, null); + MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, (String[]) null); ValidationFileResponse validationFileResponse = new ValidationFileResponse(); @@ -150,15 +149,12 @@ public class UploadValidationManagerImpl implements UploadValidationManager { Map> errors = validateHeatUploadData(content); tree = HeatTreeManagerUtil.initHeatTreeManager(content); tree.createTree(); - if (MapUtils.isNotEmpty(errors)) { - + if (MapUtils.isNotEmpty(errors)) { tree.addErrors(errors); validationStructureList.setImportStructure(tree.getTree()); - //validationFileResponse.setStatus(ValidationFileStatus.Failure); - } else { - //validationFileResponse.setStatus(ValidationFileStatus.Success); } + } else { MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API, LoggerTragetServiceName.VALIDATE_FILE_TYPE, ErrorLevel.ERROR.name(), @@ -167,12 +163,11 @@ public class UploadValidationManagerImpl implements UploadValidationManager { } validationFileResponse.setValidationData(validationStructureList); - mdcDataDebugMessage.debugExitMessage(null, null); + MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, (String[]) null); return validationFileResponse; } - private Map> validateHeatUploadData(FileContentHandler fileContentMap) - throws IOException { + private Map> validateHeatUploadData(FileContentHandler fileContentMap) { ValidationManager validationManager = ValidationManagerUtil.initValidationManager(fileContentMap); return validationManager.validate(); diff --git a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java index 924a956628..53b05eb953 100644 --- a/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java +++ b/openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java @@ -29,6 +29,7 @@ import org.openecomp.sdc.common.utils.SdcCommon; import org.openecomp.sdc.datatypes.error.ErrorLevel; import org.openecomp.sdc.datatypes.error.ErrorMessage; +import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; @@ -43,11 +44,12 @@ public class ValidationManagerUtil { * @param errors the errors */ public static void handleMissingManifest(FileContentHandler fileContentMap, - Map> errors) { - InputStream manifest = fileContentMap.getFileContent(SdcCommon.MANIFEST_NAME); - if (manifest == null) { - ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors) - .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage())); + Map> errors) throws IOException { + try (InputStream manifest = fileContentMap.getFileContent(SdcCommon.MANIFEST_NAME)) { + if (manifest == null) { + ErrorMessage.ErrorMessageUtil.addMessage(SdcCommon.MANIFEST_NAME, errors) + .add(new ErrorMessage(ErrorLevel.ERROR, Messages.MANIFEST_NOT_EXIST.getErrorMessage())); + } } } -- cgit 1.2.3-korg