aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormojahidi <mojahidul.islam@amdocs.com>2017-12-13 17:19:34 +0530
committerMojahidul Islam <mojahidul.islam@amdocs.com>2017-12-21 12:43:59 +0000
commit9c1eec7da6f3895aa5d86dc1b031d52f9201167c (patch)
tree1ea4028437d56b9135c9886bf3057326f0debeea
parent8e9c0653dd6c6862123c9609ae34e1206d86456e (diff)
Fixed sonar issues - ManifestValidator
Removed unnecessary cast to Logger Moved private methods into ManifestScanner Change-Id: I40e581ec03a5400b8728057d766317615299b3e8 Issue-ID: SDC-343 Signed-off-by: mojahidi <mojahidul.islam@amdocs.com>
-rw-r--r--openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java148
1 files changed, 72 insertions, 76 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
index e3a35af6dc..08cd2450f2 100644
--- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
+++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/ManifestValidator.java
@@ -1,21 +1,17 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * Copyright © 2016-2017 European Support Limited
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- * ============LICENSE_END=========================================================
*/
package org.openecomp.sdc.validation.impl.validators;
@@ -46,8 +42,8 @@ import java.util.Optional;
public class ManifestValidator implements Validator {
- public static final MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
- private static Logger logger = (Logger) LoggerFactory.getLogger(YamlValidator.class);
+ private static final MdcDataDebugMessage MDC_DATA_DEBUG_MESSAGE = new MdcDataDebugMessage();
+ private static final Logger LOGGER = LoggerFactory.getLogger(YamlValidator.class);
private static final ErrorMessageCode ERROR_CODE_MNF_1 = new ErrorMessageCode("MNF1");
private static final ErrorMessageCode ERROR_CODE_MNF_2 = new ErrorMessageCode("MNF2");
private static final ErrorMessageCode ERROR_CODE_MNF_3 = new ErrorMessageCode("MNF3");
@@ -59,7 +55,7 @@ public class ManifestValidator implements Validator {
@Override
public void validate(GlobalValidationContext globalContext) {
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
Optional<InputStream> content = globalContext.getFileContent(SdcCommon.MANIFEST_NAME);
ManifestContent manifestContent;
@@ -74,7 +70,7 @@ public class ManifestValidator implements Validator {
throw new Exception("The manifest file '" + SdcCommon.MANIFEST_NAME + "' has no content");
}
} catch (Exception re) {
- logger.debug("",re);
+ LOGGER.debug("",re);
globalContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
ErrorMessagesFormatBuilder
.getErrorWithParameters(ERROR_CODE_MNF_6,
@@ -103,7 +99,7 @@ public class ManifestValidator implements Validator {
LoggerTragetServiceName.VALIDATE_FILE_IN_MANIFEST, LoggerErrorDescription.MISSING_FILE)
);
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
}
private boolean isNotManifestFiles(List<String> manifestFiles, String name) {
@@ -119,18 +115,18 @@ public class ManifestValidator implements Validator {
GlobalValidationContext context) {
- mdcDataDebugMessage.debugEntryMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugEntryMessage(null, null);
ManifestScanner manifestScanner = new ManifestScanner();
manifestScanner.scan(null, manifestContent.getData(), context);
- mdcDataDebugMessage.debugExitMessage(null, null);
+ MDC_DATA_DEBUG_MESSAGE.debugExitMessage(null, null);
return manifestScanner.getFileList();
}
private class ManifestScanner {
- private List<String> fileList=new ArrayList<>();
+ private List<String> fileList = new ArrayList<>();
public void scan(FileData fileData, List<FileData> data,
GlobalValidationContext globalContext) {
@@ -152,75 +148,75 @@ public class ManifestValidator implements Validator {
public List<String> getFileList() {
return this.fileList;
}
- }
- private void validateFileTypeVsFileName(GlobalValidationContext globalValidationContext,
- FileData fileData) {
- String fileName = fileData.getFile();
- validateIfFileExists(globalValidationContext,fileName);
- FileData.Type type = fileData.getType();
- if (type == null) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_8,
- Messages.INVALID_FILE_TYPE.getErrorMessage()),
- LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME, "Invalid file type");
- } else if (type.equals(FileData.Type.HEAT_NET) || type.equals(FileData.Type.HEAT_VOL)
- || type.equals(FileData.Type.HEAT)) {
- validateIfFileHasYamlExtenstion(globalValidationContext,fileName);
- } else if (type.equals(FileData.Type.HEAT_ENV)) {
- validateIfFileHasEnvExtension(globalValidationContext,fileName);
+ private void validateFileTypeVsFileName(GlobalValidationContext globalValidationContext,
+ FileData fileData) {
+ String fileName = fileData.getFile();
+ validateIfFileExists(globalValidationContext,fileName);
+ FileData.Type type = fileData.getType();
+ if (type == null) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder.getErrorWithParameters(ERROR_CODE_MNF_8,
+ Messages.INVALID_FILE_TYPE.getErrorMessage()),
+ LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME, "Invalid file type");
+ } else if (type.equals(FileData.Type.HEAT_NET) || type.equals(FileData.Type.HEAT_VOL)
+ || type.equals(FileData.Type.HEAT)) {
+ validateIfFileHasYamlExtenstion(globalValidationContext,fileName);
+ } else if (type.equals(FileData.Type.HEAT_ENV)) {
+ validateIfFileHasEnvExtension(globalValidationContext,fileName);
+ }
}
- }
- private void validateIfFileHasEnvExtension(GlobalValidationContext globalValidationContext,
- String fileName) {
- if (fileName != null && !fileName.endsWith(".env")) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_3,
- Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(),
- fileName), LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
- "Wrong env file extention");
+ private void validateIfEnvIsAssociatedToHeat(GlobalValidationContext globalContext,
+ FileData childFileData) {
+ if (childFileData.getType() != null
+ && childFileData.getType().equals(FileData.Type.HEAT_ENV)) {
+ globalContext.addMessage(childFileData.getFile(), ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_1,
+ Messages.ENV_NOT_ASSOCIATED_TO_HEAT.getErrorMessage()),
+ LoggerTragetServiceName.SCAN_MANIFEST_STRUCTURE,
+ "env file is not associated to HEAT file");
+ }
}
- }
- private void validateIfFileHasYamlExtenstion(GlobalValidationContext globalValidationContext,
+ private void validateIfFileHasEnvExtension(GlobalValidationContext globalValidationContext,
String fileName) {
- if (fileName != null && !fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
- globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_2,
- Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(),
- fileName), LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
- "Wrong HEAT file extention");
+ if (fileName != null && !fileName.endsWith(".env")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_3,
+ Messages.WRONG_ENV_FILE_EXTENSION.getErrorMessage(),
+ fileName), LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
+ "Wrong env file extention");
+ }
}
- }
-
- private void validateIfFileExists(GlobalValidationContext globalValidationContext,
- String fileName) {
- if (fileName == null) {
- globalValidationContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_7,
- Messages.MISSING_FILE_NAME_IN_MANIFEST.getErrorMessage()),
- LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
- "Missing file name in manifest");
+ private void validateIfFileHasYamlExtenstion(GlobalValidationContext globalValidationContext,
+ String fileName) {
+ if (fileName != null && !fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) {
+ globalValidationContext.addMessage(fileName, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_2,
+ Messages.WRONG_HEAT_FILE_EXTENSION.getErrorMessage(),
+ fileName), LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
+ "Wrong HEAT file extention");
+ }
}
- }
- private void validateIfEnvIsAssociatedToHeat(GlobalValidationContext globalContext,
- FileData childFileData) {
- if (childFileData.getType() != null
- && childFileData.getType().equals(FileData.Type.HEAT_ENV)) {
- globalContext.addMessage(childFileData.getFile(), ErrorLevel.ERROR,
- ErrorMessagesFormatBuilder
- .getErrorWithParameters(ERROR_CODE_MNF_1,
- Messages.ENV_NOT_ASSOCIATED_TO_HEAT.getErrorMessage()),
- LoggerTragetServiceName.SCAN_MANIFEST_STRUCTURE,
- "env file is not associated to HEAT file");
- }
- }
+ private void validateIfFileExists(GlobalValidationContext globalValidationContext,
+ String fileName) {
+ if (fileName == null) {
+ globalValidationContext.addMessage(SdcCommon.MANIFEST_NAME, ErrorLevel.ERROR,
+ ErrorMessagesFormatBuilder
+ .getErrorWithParameters(ERROR_CODE_MNF_7,
+ Messages.MISSING_FILE_NAME_IN_MANIFEST.getErrorMessage()),
+ LoggerTragetServiceName.VALIDATE_FILE_TYPE_AND_NAME,
+ "Missing file name in manifest");
+ }
+ }
+ }
+
}