summaryrefslogtreecommitdiffstats
path: root/openecomp-be/backend/openecomp-sdc-validation-manager/src
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2017-10-23 13:28:46 +0300
committervempo <vitaliy.emporopulo@amdocs.com>2017-10-23 13:39:10 +0300
commit5f3a0ea3230fc09bb66a5b6fbd65868fe2a46e6c (patch)
tree6d5928c7947746eab1c38cf7d6ebbed060ca6390 /openecomp-be/backend/openecomp-sdc-validation-manager/src
parentb8aabbe3590c90be5c6f3e2c63b57c0e396baed6 (diff)
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 <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/backend/openecomp-sdc-validation-manager/src')
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/impl/UploadValidationManagerImpl.java21
-rw-r--r--openecomp-be/backend/openecomp-sdc-validation-manager/src/main/java/org/openecomp/sdc/validation/util/ValidationManagerUtil.java12
2 files changed, 15 insertions, 18 deletions
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<String> 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<String, List<ErrorMessage>> 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<String, List<ErrorMessage>> validateHeatUploadData(FileContentHandler fileContentMap)
- throws IOException {
+ private Map<String, List<ErrorMessage>> 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<String, List<ErrorMessage>> 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<String, List<ErrorMessage>> 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()));
+ }
}
}