>From b4174fa26cba3e55a642f271bbebe26250348592 Mon Sep 17 00:00:00 2001
From: "Endi S. Dewata" <edewata@redhat.com>
Date: Fri, 24 Mar 2017 03:56:03 +0100
Subject: [PATCH] Refactored TPS ConfigCLI.

The TPS ConfigCLI and its submodules have been modified to use
lazy initialization to get the PKIClient object.
---
 .../src/com/netscape/cmstools/tps/config/ConfigCLI.java          | 9 ++++++---
 .../src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java    | 4 +++-
 .../src/com/netscape/cmstools/tps/config/ConfigShowCLI.java      | 4 +++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigCLI.java
index f7b53ed63ba55cb3afed541bf4e821d2b345156f..d97e9b103faa07fb96c769b46703794e7705ea04 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigCLI.java
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
+import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.tps.config.ConfigClient;
 import com.netscape.certsrv.tps.config.ConfigData;
 import com.netscape.cmstools.cli.CLI;
@@ -41,12 +42,14 @@ public class ConfigCLI extends CLI {
         addModule(new ConfigShowCLI(this));
     }
 
-    public void execute(String[] args) throws Exception {
+    public ConfigClient getConfigClient() throws Exception {
 
-        client = parent.getClient();
+        if (configClient != null) return configClient;
+
+        PKIClient client = getClient();
         configClient = (ConfigClient)parent.getClient("config");
 
-        super.execute(args);
+        return configClient;
     }
 
     public static void printConfigData(ConfigData configData) throws IOException {
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
index c5da9431087aaa22640ea1b6e281847af9977384..06aaf1936c4c336bc7bd0da411ca6a20277d112f 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigModifyCLI.java
@@ -28,6 +28,7 @@ import java.util.Arrays;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 
+import com.netscape.certsrv.tps.config.ConfigClient;
 import com.netscape.certsrv.tps.config.ConfigData;
 import com.netscape.cmstools.cli.CLI;
 import com.netscape.cmstools.cli.MainCLI;
@@ -93,7 +94,8 @@ public class ConfigModifyCLI extends CLI {
             configData = ConfigData.valueOf(sw.toString());
         }
 
-        configData = configCLI.configClient.updateConfig(configData);
+        ConfigClient configClient = configCLI.getConfigClient();
+        configData = configClient.updateConfig(configData);
 
         MainCLI.printMessage("Updated configuration");
 
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
index d7f20e80da329aa3bb1b954c3a893fd736cb45d1..627d2fef335bfe2c318a1bcacc34103d294bd897 100644
--- a/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/tps/config/ConfigShowCLI.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 
+import com.netscape.certsrv.tps.config.ConfigClient;
 import com.netscape.certsrv.tps.config.ConfigData;
 import com.netscape.cmstools.cli.CLI;
 import com.netscape.cmstools.cli.MainCLI;
@@ -70,7 +71,8 @@ public class ConfigShowCLI extends CLI {
 
         String output = cmd.getOptionValue("output");
 
-        ConfigData configData = configCLI.configClient.getConfig();
+        ConfigClient configClient = configCLI.getConfigClient();
+        ConfigData configData = configClient.getConfig();
 
         if (output == null) {
             MainCLI.printMessage("Configuration");
-- 
2.9.3

