Fix Sonar violations - ValidationUtil 09/27109/3
authorAbhai Singh <Abhai.Singh@amdocs.com>
Thu, 28 Dec 2017 13:56:59 +0000 (19:26 +0530)
committerVitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com>
Sun, 31 Dec 2017 10:20:08 +0000 (10:20 +0000)
Fixed few reported sonar issues.
Fixed as per review comment

Change-Id: Id3cbdcefe120eb9d807f7b66e1b0f329881ef658
Issue-ID: SDC-343
Signed-off-by: Abhai Singh <Abhai.Singh@amdocs.com>
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-sdk/src/main/java/org/openecomp/sdc/validation/util/ValidationUtil.java

index 76b4aff..925949b 100644 (file)
@@ -38,7 +38,9 @@ import static java.util.Objects.nonNull;
 public class ValidationUtil {
 
   private static MdcDataDebugMessage mdcDataDebugMessage = new MdcDataDebugMessage();
-  private final static Logger log = (Logger) LoggerFactory.getLogger(ValidationUtil.class.getName());
+  private static final Logger LOG = LoggerFactory.getLogger(ValidationUtil.class.getName());
+
+  private ValidationUtil(){}
 
   public static void removeExposedResourcesCalledByGetResource(String fileName,
                                                                Set<String> actualExposedResources,
@@ -64,10 +66,8 @@ public class ValidationUtil {
                                                                 Map<String, Resource> resourcesMap) {
     for (String referencedResourceName : referencedResources) {
       Resource currResource = resourcesMap.get(referencedResourceName);
-      if (Objects.nonNull(currResource)) {
-        if (isExpectedToBeExposed(currResource.getType())) {
+      if (Objects.nonNull(currResource) && isExpectedToBeExposed(currResource.getType())) {
           actualExposedResources.add(referencedResourceName);
-        }
       }
     }
   }
@@ -89,7 +89,7 @@ public class ValidationUtil {
   public static boolean evalPattern(Object paramVal, String[] regexList) {
     String value = "";
     if (paramVal instanceof String) {
-      value = ((String) paramVal);
+      value = (String) paramVal;
     }
     if (paramVal instanceof Integer) {
       value = paramVal.toString();
@@ -140,7 +140,7 @@ public class ValidationUtil {
         throw new Exception("The file '" + envFileName + "' has no content");
       }
     } catch (Exception exception) {
-      log.debug("",exception);
+      LOG.debug("",exception);
       mdcDataDebugMessage.debugExitMessage("file", envFileName);
       return null;
     }
@@ -157,8 +157,7 @@ public class ValidationUtil {
     mdcDataDebugMessage.debugEntryMessage("file", fileName);
 
     String propertyValue = getWantedNameFromPropertyValueGetParam(nameValue);
-    if (nonNull(propertyValue)) {
-      if (!evalPattern(propertyValue, regexList)) {
+    if (nonNull(propertyValue) && !evalPattern(propertyValue, regexList)) {
         globalContext.addMessage(
             fileName,
             ErrorLevel.WARNING,
@@ -171,7 +170,6 @@ public class ValidationUtil {
         mdcDataDebugMessage.debugExitMessage("file", fileName);
         return true;
       }
-    }
 
     mdcDataDebugMessage.debugExitMessage("file", fileName);
     return false;
@@ -189,7 +187,7 @@ public class ValidationUtil {
     try {
       manifestContent = JsonUtil.json2Object(manifest.get(), ManifestContent.class);
     } catch (Exception exception) {
-      log.debug("",exception);
+      LOG.debug("",exception);
       MdcDataErrorMessage.createErrorMessageAndUpdateMdc(LoggerConstants.TARGET_ENTITY_API,
           LoggerTragetServiceName.VALIDATE_MANIFEST_CONTENT, ErrorLevel.ERROR.name(),
           LoggerErrorCode.DATA_ERROR.getErrorCode(), LoggerErrorDescription.INVALID_MANIFEST);