Add support for profile include exclude 69/34669/2
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Wed, 7 Mar 2018 15:11:06 +0000 (20:41 +0530)
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Thu, 8 Mar 2018 05:48:10 +0000 (11:18 +0530)
Issue-ID: CLI-95

Change-Id: I454020229481e2893459f7b29bf815bc0c701bed
Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
framework/src/main/java/org/onap/cli/fw/input/cache/OnapCommandParameterCache.java
framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
framework/src/test/java/org/onap/cli/fw/registrar/OnapCommandRegistrarTest.java
main/src/main/java/org/onap/cli/main/OnapCli.java

index ee6dbed..5b00be1 100644 (file)
@@ -58,6 +58,13 @@ public class OnapCommandParameterCache {
         return single;
     }
 
+    public void includeProfile(String profile) {
+        this.load(profile, true);
+    }
+
+    public void excludeProfile(String profile) {
+        this.load(profile, false);
+    }
 
     public void add(String productVersion, String paramName, String paramValue) {
 
@@ -111,15 +118,23 @@ public class OnapCommandParameterCache {
     }
 
     private void load() {
+        this.load(this.profileName, true);
+    }
+
+    private void load(String profileName, boolean include) {
         List<OnapCommandParamEntity> params= new ArrayList<>();
         try {
-            params = this.loadParamFromCache(this.profileName);
+            params = this.loadParamFromCache(profileName);
         } catch (OnapCommandLoadProfileFailed e) {
             throw new RuntimeException(e);   // NOSONAR
         }
 
         for (OnapCommandParamEntity p : params) {
-            this.add(p.getProduct(), p.getName(), p.getValue());
+            if (include) {
+                this.add(p.getProduct(), p.getName(), p.getValue());
+            } else {
+                this.remove(p.getProduct(), p.getName());
+            }
         }
     }
 
index 8ba215e..6564628 100644 (file)
@@ -90,8 +90,16 @@ public class OnapCommandRegistrar {
         paramCache.remove(this.getEnabledProductVersion(), paramName);
     }
 
-    public void setProfile(String profileName) {
+    public void setProfile(String profileName, List<String> includes, List<String> excludes) {
         this.paramCache.setProfile(profileName);
+
+        for (String profile: includes) {
+            this.paramCache.includeProfile(profile);
+        }
+
+        for (String profile: excludes) {
+            this.paramCache.excludeProfile(profile);
+        }
     }
 
     public List<String> getUserProfiles() {
index 124b956..d70c152 100644 (file)
@@ -23,6 +23,7 @@ import static org.junit.Assert.fail;
 
 import java.io.File;
 import java.net.URL;
+import java.util.ArrayList;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -90,7 +91,7 @@ public class OnapCommandRegistrarTest {
     @Test
     public void testProfile() throws OnapCommandException {
         try {
-                OnapCommandRegistrar.getRegistrar().setProfile("test12312");
+                OnapCommandRegistrar.getRegistrar().setProfile("test234", new ArrayList<String>(), new ArrayList<String>());
                 OnapCommandRegistrar.getRegistrar().addParamCache("a", "b");
                 OnapCommandRegistrar.getRegistrar().getParamCache();
                 OnapCommandRegistrar.getRegistrar().removeParamCache("a");
index ca3c365..aa1f1e7 100644 (file)
@@ -142,7 +142,10 @@ public class OnapCli {
             if ((args.size() == 2) && (this.getLongOption(OnapCliConstants.PARAM_PROFILE_LONG).equals(args.get(0))
                         || this.getShortOption(OnapCliConstants.PARAM_PROFILE_SHORT).equals(args.get(0)))) {
 
-                OnapCommandRegistrar.getRegistrar().setProfile(args.get(1));
+                OnapCommandRegistrar.getRegistrar().setProfile(
+                        args.get(1),
+                        new ArrayList<String>(),
+                        new ArrayList<String>());
                 //Make space of interactive mode
                 this.args = new ArrayList<>();
             }