remove static bool
authorSmokowski, Kevin (ks6305) <ks6305@att.com>
Wed, 1 Aug 2018 18:04:04 +0000 (18:04 +0000)
committerSmokowski, Kevin (ks6305) <ks6305@att.com>
Wed, 1 Aug 2018 18:04:42 +0000 (18:04 +0000)
Don't use static boolean for legacy enumeration mapping, add additional parameter to the function

Change-Id: I5d8963a208f3ffdd3af83216aa55f7d34ee39eb9
Issue-ID: CCSDK-396
Signed-off-by: Smokowski, Kevin (ks6305) <ks6305@att.com>
sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelper.java
sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java

index e8f73e8..f87b7d3 100644 (file)
@@ -50,11 +50,6 @@ public class MdsalHelper {
 
     private static final Logger LOG = LoggerFactory.getLogger(MdsalHelper.class);
     private static Properties yangMappingProperties = new Properties();
-    protected static boolean useLegacyEnumerationMapping = false;
-    
-    public static void useLegacyEnumerationMapping(Boolean bool) {
-        useLegacyEnumerationMapping = bool;
-    }
     
     @Deprecated
     public static void setProperties(Properties input) {
@@ -88,25 +83,37 @@ public class MdsalHelper {
     }
 
     public static Properties toProperties(Properties props, Object fromObj) {
+        return toProperties(props, fromObj, false);
+    }
+    
+    public static Properties toProperties(Properties props, Object fromObj, Boolean useLegacyEnumerationMapping) {
         Class fromClass = null;
 
         if (fromObj != null) {
             fromClass = fromObj.getClass();
         }
-        return toProperties(props, "", fromObj, fromClass);
+        return toProperties(props, "", fromObj, fromClass,useLegacyEnumerationMapping );
     }
 
     public static Properties toProperties(Properties props, String pfx, Object fromObj) {
+        return toProperties(props, pfx, fromObj, false);
+    }
+    
+    public static Properties toProperties(Properties props, String pfx, Object fromObj, Boolean useLegacyEnumerationMapping) {
         Class fromClass = null;
 
         if (fromObj != null) {
             fromClass = fromObj.getClass();
         }
 
-        return toProperties(props, pfx, fromObj, fromClass);
+        return toProperties(props, pfx, fromObj, fromClass, useLegacyEnumerationMapping);
     }
 
     public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass) {
+        return toProperties(props, pfx, fromObj, fromClass, false);
+    }
+    
+    public static Properties toProperties(Properties props, String pfx, Object fromObj, Class fromClass, Boolean useLegacyEnumerationMapping) {
 
         if (fromObj == null) {
             return props;
@@ -121,7 +128,7 @@ public class MdsalHelper {
             List fromList = (List) fromObj;
 
             for (int i = 0; i < fromList.size(); i++) {
-                toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass);
+                toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass, useLegacyEnumerationMapping);
             }
             props.setProperty(pfx + "_length", Integer.toString(fromList.size()));
 
@@ -365,7 +372,7 @@ public class MdsalHelper {
                                     m.setAccessible(isAccessible);
                                 }
                                 if (retValue != null) {
-                                    toProperties(props, propNamePfx + "." + fieldName, retValue, returnType);
+                                    toProperties(props, propNamePfx + "." + fieldName, retValue, returnType, useLegacyEnumerationMapping);
                                 }
                             } catch (Exception e) {
 
@@ -398,7 +405,7 @@ public class MdsalHelper {
                             // this array.
                             Type paramType = m.getGenericReturnType();
                             Type elementType = ((ParameterizedType) paramType).getActualTypeArguments()[0];
-                            toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType);
+                            toProperties(props, propNamePfx + "." + fieldName, retList, (Class) elementType, useLegacyEnumerationMapping);
                         } catch (Exception e) {
                             LOG.error("Caught exception trying to convert List returned by " + fromClass.getName() + "."
                                     + m.getName() + "() to Properties entry", e);
index d5ca04d..307c69c 100644 (file)
@@ -147,7 +147,6 @@ public class MdsalHelperTest extends TestCase {
     // During the default enumeration mapping no properties file is needed, the yang value is returned
     // by the java object
     public void testDefaultEnumerationMapping() throws Exception {
-        MdsalHelper.useLegacyEnumerationMapping(false);
         Properties props = new Properties();
         MdsalHelper.toProperties(props, new WrapperObj());
         assertEquals("4COS", props.getProperty("wrapper-obj.cos-model-type"));
@@ -156,9 +155,8 @@ public class MdsalHelperTest extends TestCase {
     // When no properties file exists the default java value will be returned if legacy enumeration
     // mapping is enabled
     public void testLegacyEnumerationMappingNoProperties() throws Exception {
-        MdsalHelper.useLegacyEnumerationMapping(true);
         Properties props = new Properties();
-        MdsalHelper.toProperties(props, new WrapperObj());
+        MdsalHelper.toProperties(props, new WrapperObj(), true);
         assertEquals("_4COS", props.getProperty("wrapper-obj.cos-model-type"));
     }
 
@@ -166,9 +164,8 @@ public class MdsalHelperTest extends TestCase {
     // properties file should be returned
     public void testLegacyEnumerationMappingWithProperties() throws Exception {
         MdsalHelper.loadProperties("src/test/resources/EnumerationMapping.properties");
-        MdsalHelper.useLegacyEnumerationMapping(true);
         Properties props = new Properties();
-        MdsalHelper.toProperties(props, new WrapperObj());
+        MdsalHelper.toProperties(props, new WrapperObj(), true);
         assertEquals("HelloWorld", props.getProperty("wrapper-obj.cos-model-type"));
     }
 }