nova server validator 83/23783/2
authortalio <tali.orenbach@amdocs.com>
Thu, 16 Nov 2017 08:05:26 +0000 (10:05 +0200)
committertalio <tali.orenbach@amdocs.com>
Thu, 16 Nov 2017 10:36:29 +0000 (12:36 +0200)
fixed validation of nova server name value inside env file

Issue - Id : SDC-670

Change-Id: If407a2c1f601b4b724c50c1994fd056b569588ac
Signed-off-by: talio <tali.orenbach@amdocs.com>
onboarding/pom.xml
openecomp-be/lib/openecomp-heat-lib/src/main/java/org/openecomp/sdc/heat/datatypes/DefinedHeatParameterTypes.java
openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/main/java/org/openecomp/sdc/validation/impl/validators/namingconvention/NovaServerNamingConventionGuideLineValidator.java

index a50e986..6fb5e6a 100644 (file)
@@ -39,7 +39,7 @@
         <openecomp.sdc.common.version>${project.version}</openecomp.sdc.common.version>
 
         <!-- Onboarding 3rd party versions -->
-        <jtosca.version>1.1.1-SNAPSHOT</jtosca.version>
+        <jtosca.version>1.1.1</jtosca.version>
         <aspectj.version>1.8.9</aspectj.version>
         <bsh.version>2.0b5</bsh.version>
         <cassandra.version>2.1.9</cassandra.version>
index d4b6a88..54b071f 100644 (file)
@@ -21,6 +21,7 @@
 package org.openecomp.sdc.heat.datatypes;
 
 import org.apache.commons.lang.math.NumberUtils;
+import org.apache.commons.lang3.ClassUtils;
 
 import java.util.HashMap;
 import java.util.List;
@@ -72,14 +73,13 @@ public enum DefinedHeatParameterTypes {
           return HeatBoolean.isValueBoolean(value);
 
         case COMMA_DELIMITED_LIST:
-          String valAsString = String.valueOf(value);
-          return valAsString.split(",") instanceof String[];
+          return isValueCommaDelimitedList(value);
 
         case JSON:
-          return (value instanceof Map) || (value instanceof List);
+          return isValueJson(value);
 
         case STRING:
-          return true;
+          return isValueString(value);
         default:
       }
     }
@@ -92,6 +92,20 @@ public enum DefinedHeatParameterTypes {
         || isValueIsFromGivenType(value, STRING.getType());
   }
 
+  private static boolean isValueCommaDelimitedList(Object value) {
+    return String.valueOf(value).contains(",")
+            || isValueIsFromGivenType(value, DefinedHeatParameterTypes.STRING.type);
+  }
+
+  private static boolean isValueString(Object value) {
+    return value instanceof String
+            || ClassUtils.isPrimitiveOrWrapper(value.getClass());
+  }
+
+  private static boolean isValueJson(Object value) {
+    return (value instanceof Map) || (value instanceof List);
+  }
+
   public static boolean isEmptyValueInEnv(Object value) {
     return Objects.isNull(value);
   }
index 299eabf..0a7ff87 100644 (file)
@@ -389,7 +389,7 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
     if (nonNull(novaNameGetParam)) {
       novaName =
           checkNovaNameGetParamValueMap(fileName, novaNameGetParam, resourceEntry, globalContext);
-      checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, resourceEntry, novaName,
+      checkIfNovaNameParameterInEnvIsStringOrList(fileName, envFileName, novaName, resourceEntry,
           globalContext);
     } else {
       globalContext.addMessage(
@@ -457,7 +457,7 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
     if (getParamValue instanceof List) {
       List<Object> getParamNameList = (List) getParamValue;
       String[] regexName = new String[]{".*_names"};
-      return isNovaNameAsListLegal(fileName, getParamNameList, regexName, resourceEntry,
+      return isNovaNameAsListLegal(fileName, regexName, getParamNameList, resourceEntry,
           globalContext);
     } else if (getParamValue instanceof String) {
       String[] regexName = new String[]{".*_name_(\\d+)"};
@@ -468,9 +468,10 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
     return null;
   }
 
-  private void checkIfNovaNameParameterInEnvIsStringOrList(String fileName, String envFileName,
-                                                           Map.Entry<String, Resource> resourceEntry,
+  private void checkIfNovaNameParameterInEnvIsStringOrList(String fileName,
+                                                           String envFileName,
                                                            String novaServerName,
+                                                           Map.Entry<String, Resource> resourceEntry,
                                                            GlobalValidationContext globalContext) {
     if (nonNull(envFileName)) {
       Environment environment = ValidationUtil.validateEnvContent(envFileName, globalContext);
@@ -495,8 +496,9 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
     }
   }
 
-  private String isNovaNameAsListLegal(String fileName, List<Object> getParamNameList,
+  private String isNovaNameAsListLegal(String fileName,
                                        String[] regexName,
+                                       List<Object> getParamNameList,
                                        Map.Entry<String, Resource> resourceEntry,
                                        GlobalValidationContext globalContext) {
 
@@ -516,7 +518,9 @@ public class NovaServerNamingConventionGuideLineValidator implements ResourceVal
     return (String) getParamNameList.get(0);
   }
 
-  private String isNovaNameAsStringLegal(String fileName, String novaName, String[] regexName,
+  private String isNovaNameAsStringLegal(String fileName,
+                                         String novaName,
+                                         String[] regexName,
                                          Map.Entry<String, Resource> resourceEntry,
                                          GlobalValidationContext globalContext) {
     if (!ValidationUtil.evalPattern(novaName, regexName)) {