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

The ActivityCLI and its submodules have been modified to use lazy
initialization to get the PKIClient object.
---
 .../src/com/netscape/cmstools/logging/ActivityCLI.java           | 9 ++++++---
 .../src/com/netscape/cmstools/logging/ActivityFindCLI.java       | 4 +++-
 .../src/com/netscape/cmstools/logging/ActivityShowCLI.java       | 4 +++-
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
index f53e687001f80ce6976ba537abcd6b00572e55c2..f0f125edd1ef080d767bc7c8e478e65a9edc08f9 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
@@ -20,6 +20,7 @@ package com.netscape.cmstools.logging;
 
 import org.jboss.resteasy.plugins.providers.atom.Link;
 
+import com.netscape.certsrv.client.PKIClient;
 import com.netscape.certsrv.logging.ActivityClient;
 import com.netscape.certsrv.logging.ActivityData;
 import com.netscape.cmstools.cli.CLI;
@@ -38,12 +39,14 @@ public class ActivityCLI extends CLI {
         addModule(new ActivityShowCLI(this));
     }
 
-    public void execute(String[] args) throws Exception {
+    public ActivityClient getActivityClient() throws Exception {
 
-        client = parent.getClient();
+        if (activityClient != null) return activityClient;
+
+        PKIClient client = getClient();
         activityClient = (ActivityClient)parent.getClient("activity");
 
-        super.execute(args);
+        return activityClient;
     }
 
     public static void printActivity(ActivityData activity, boolean showAll) {
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
index 9e31795b4415fe34dc37a6e2f835c4a0a39b3d3e..75c635bdcff0cc525f8f70d73d984f739761ccb6 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -24,6 +24,7 @@ import java.util.Collection;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 
+import com.netscape.certsrv.logging.ActivityClient;
 import com.netscape.certsrv.logging.ActivityCollection;
 import com.netscape.certsrv.logging.ActivityData;
 import com.netscape.cmstools.cli.CLI;
@@ -75,7 +76,8 @@ public class ActivityFindCLI extends CLI {
         s = cmd.getOptionValue("size");
         Integer size = s == null ? null : Integer.valueOf(s);
 
-        ActivityCollection result = activityCLI.activityClient.findActivities(filter, start, size);
+        ActivityClient activityClient = activityCLI.getActivityClient();
+        ActivityCollection result = activityClient.findActivities(filter, start, size);
 
         MainCLI.printMessage(result.getTotal() + " entries matched");
         if (result.getTotal() == 0) return;
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
index bae172c7912eb854ecdfb716cb1eafa67efdcfa3..e31cbf6ab50159ae1995f12533900270eabf7af4 100644
--- a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 
 import org.apache.commons.cli.CommandLine;
 
+import com.netscape.certsrv.logging.ActivityClient;
 import com.netscape.certsrv.logging.ActivityData;
 import com.netscape.cmstools.cli.CLI;
 import com.netscape.cmstools.cli.MainCLI;
@@ -59,7 +60,8 @@ public class ActivityShowCLI extends CLI {
 
         String activityID = args[0];
 
-        ActivityData activityData = activityCLI.activityClient.getActivity(activityID);
+        ActivityClient activityClient = activityCLI.getActivityClient();
+        ActivityData activityData = activityClient.getActivity(activityID);
 
         MainCLI.printMessage("Activity \"" + activityID + "\"");
 
-- 
2.9.3

