summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/logging
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-08-22 17:48:58 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-08-24 01:39:04 -0400
commitffb49f1552a9eabb8ec083edd91841253e173ae5 (patch)
treef4c47644c8c5f7f8d9132656599b18c3130d51cf /base/java-tools/src/com/netscape/cmstools/logging
parentc587da42da2b87dec2d1fbfd262a1fc6e8598452 (diff)
downloadpki-ffb49f1552a9eabb8ec083edd91841253e173ae5.tar.gz
pki-ffb49f1552a9eabb8ec083edd91841253e173ae5.tar.xz
pki-ffb49f1552a9eabb8ec083edd91841253e173ae5.zip
Added TPS activities resource.
New REST services and clients have been added for TPS activities. The activity database is currently implemented as in-memory database with some sample data. Later it will be converted into LDAP database. Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/logging')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java83
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java94
-rw-r--r--base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java56
3 files changed, 233 insertions, 0 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
new file mode 100644
index 000000000..4a9bf3828
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityCLI.java
@@ -0,0 +1,83 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.logging;
+
+import java.util.Arrays;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.logging.ActivityClient;
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityCLI extends CLI {
+
+ public ActivityClient activityClient;
+
+ public ActivityCLI(CLI parent) {
+ super("activity", "Activity management commands", parent);
+
+ addModule(new ActivityFindCLI(this));
+ addModule(new ActivityShowCLI(this));
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ client = parent.getClient();
+ activityClient = (ActivityClient)parent.getClient("activity");
+
+ if (args.length == 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String command = args[0];
+ String[] commandArgs = Arrays.copyOfRange(args, 1, args.length);
+
+ if (command == null) {
+ printHelp();
+ System.exit(1);
+ }
+
+ CLI module = getModule(command);
+ if (module != null) {
+ module.execute(commandArgs);
+
+ } else {
+ System.err.println("Error: Invalid command \"" + command + "\"");
+ printHelp();
+ System.exit(1);
+ }
+ }
+
+ public static void printActivity(ActivityData activity) {
+ System.out.println(" Activity ID: " + activity.getID());
+ if (activity.getTokenID() != null) System.out.println(" Token ID: " + activity.getTokenID());
+ if (activity.getUserID() != null) System.out.println(" User ID: " + activity.getUserID());
+ if (activity.getDate() != null) System.out.println(" Date: " + activity.getDate());
+
+ Link link = activity.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
new file mode 100644
index 000000000..0808a0a70
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityFindCLI.java
@@ -0,0 +1,94 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.logging;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.logging.ActivityCollection;
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityFindCLI extends CLI {
+
+ public ActivityCLI activityCLI;
+
+ public ActivityFindCLI(ActivityCLI activityCLI) {
+ super("find", "Find activities", activityCLI);
+ this.activityCLI = activityCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ ActivityCollection result = activityCLI.activityClient.findActivities(start, size);
+ Collection<ActivityData> activities = result.getEntries();
+
+ MainCLI.printMessage(activities.size() + " activity(s) matched");
+
+ boolean first = true;
+
+ for (ActivityData activityData : activities) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ ActivityCLI.printActivity(activityData);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + activities.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
new file mode 100644
index 000000000..6fa49c90c
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/logging/ActivityShowCLI.java
@@ -0,0 +1,56 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.logging;
+
+import com.netscape.certsrv.logging.ActivityData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class ActivityShowCLI extends CLI {
+
+ public ActivityCLI activityCLI;
+
+ public ActivityShowCLI(ActivityCLI activityCLI) {
+ super("show", "Show activity", activityCLI);
+ this.activityCLI = activityCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Activity ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String activityID = args[0];
+
+ ActivityData activityData = activityCLI.activityClient.getActivity(activityID);
+
+ MainCLI.printMessage("Activity \"" + activityID + "\"");
+
+ ActivityCLI.printActivity(activityData);
+ }
+}