From 81ef7152c0be247b2009b84b9a4f997e3ab09117 Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Mon, 5 May 2014 18:16:56 -0400 Subject: Renamed TPS connection to TPS connector (part 1). The TPS connection CLI has been renamed to TPS connector. Ticket #977 --- .../src/com/netscape/cmstools/cli/TPSCLI.java | 4 +- .../cmstools/tps/connection/ConnectionAddCLI.java | 108 ------------------ .../cmstools/tps/connection/ConnectionCLI.java | 75 ------------ .../cmstools/tps/connection/ConnectionFindCLI.java | 109 ------------------ .../tps/connection/ConnectionModifyCLI.java | 126 --------------------- .../tps/connection/ConnectionRemoveCLI.java | 77 ------------- .../cmstools/tps/connection/ConnectionShowCLI.java | 99 ---------------- .../cmstools/tps/connector/ConnectorAddCLI.java | 108 ++++++++++++++++++ .../cmstools/tps/connector/ConnectorCLI.java | 75 ++++++++++++ .../cmstools/tps/connector/ConnectorFindCLI.java | 109 ++++++++++++++++++ .../cmstools/tps/connector/ConnectorModifyCLI.java | 126 +++++++++++++++++++++ .../cmstools/tps/connector/ConnectorRemoveCLI.java | 77 +++++++++++++ .../cmstools/tps/connector/ConnectorShowCLI.java | 99 ++++++++++++++++ 13 files changed, 596 insertions(+), 596 deletions(-) delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionAddCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionModifyCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionRemoveCLI.java delete mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionShowCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java create mode 100644 base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java (limited to 'base/java-tools/src') diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java index b6df2995a..1931b2baa 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java @@ -27,7 +27,7 @@ import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.tps.authenticator.AuthenticatorCLI; import com.netscape.cmstools.tps.cert.TPSCertCLI; import com.netscape.cmstools.tps.config.ConfigCLI; -import com.netscape.cmstools.tps.connection.ConnectionCLI; +import com.netscape.cmstools.tps.connector.ConnectorCLI; import com.netscape.cmstools.tps.profile.ProfileCLI; import com.netscape.cmstools.tps.token.TokenCLI; import com.netscape.cmstools.user.UserCLI; @@ -47,7 +47,7 @@ public class TPSCLI extends SubsystemCLI { addModule(new AuthenticatorCLI(this)); addModule(new TPSCertCLI(this)); addModule(new ConfigCLI(this)); - addModule(new ConnectionCLI(this)); + addModule(new ConnectorCLI(this)); addModule(new GroupCLI(this)); addModule(new ProfileCLI(this)); addModule(new SelfTestCLI(this)); diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionAddCLI.java deleted file mode 100644 index 06307b96a..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionAddCLI.java +++ /dev/null @@ -1,108 +0,0 @@ -// --- 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.tps.connection; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Arrays; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.tps.connection.ConnectionData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionAddCLI extends CLI { - - public ConnectionCLI connectionCLI; - - public ConnectionAddCLI(ConnectionCLI connectionCLI) { - super("add", "Add connection", connectionCLI); - this.connectionCLI = connectionCLI; - - createOptions(); - } - - public void printHelp() { - formatter.printHelp(getFullName() + " --input [OPTIONS...]", options); - } - - public void createOptions() { - Option option = new Option(null, "input", true, "Input file containing connection properties."); - option.setArgName("file"); - option.setRequired(true); - options.addOption(option); - } - - public void execute(String[] args) throws Exception { - // Always check for "--help" prior to parsing - if (Arrays.asList(args).contains("--help")) { - // Display usage - printHelp(); - System.exit(0); - } - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(-1); - } - - String[] cmdArgs = cmd.getArgs(); - - if (cmdArgs.length != 0) { - System.err.println("Error: Too many arguments specified."); - printHelp(); - System.exit(-1); - } - - String input = cmd.getOptionValue("input"); - - ConnectionData connectionData; - - try (BufferedReader in = new BufferedReader(new FileReader(input)); - StringWriter sw = new StringWriter(); - PrintWriter out = new PrintWriter(sw, true)) { - - String line; - while ((line = in.readLine()) != null) { - out.println(line); - } - - connectionData = ConnectionData.valueOf(sw.toString()); - } - - connectionData = connectionCLI.connectionClient.addConnection(connectionData); - - MainCLI.printMessage("Added connection \"" + connectionData.getID() + "\""); - - ConnectionCLI.printConnectionData(connectionData, true); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionCLI.java deleted file mode 100644 index c0802ba13..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionCLI.java +++ /dev/null @@ -1,75 +0,0 @@ -// --- 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.tps.connection; - -import java.io.IOException; -import java.util.Map; - -import org.jboss.resteasy.plugins.providers.atom.Link; - -import com.netscape.certsrv.tps.connection.ConnectionClient; -import com.netscape.certsrv.tps.connection.ConnectionData; -import com.netscape.cmstools.cli.CLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionCLI extends CLI { - - public ConnectionClient connectionClient; - - public ConnectionCLI(CLI parent) { - super("connection", "Connection management commands", parent); - - addModule(new ConnectionAddCLI(this)); - addModule(new ConnectionFindCLI(this)); - addModule(new ConnectionModifyCLI(this)); - addModule(new ConnectionRemoveCLI(this)); - addModule(new ConnectionShowCLI(this)); - } - - public void execute(String[] args) throws Exception { - - client = parent.getClient(); - connectionClient = (ConnectionClient)parent.getClient("connection"); - - super.execute(args); - } - - public static void printConnectionData(ConnectionData connectionData, boolean showProperties) throws IOException { - System.out.println(" Connection ID: " + connectionData.getID()); - if (connectionData.getStatus() != null) System.out.println(" Status: " + connectionData.getStatus()); - - if (showProperties) { - System.out.println(" Properties:"); - Map properties = connectionData.getProperties(); - if (properties != null) { - for (String name : properties.keySet()) { - String value = properties.get(name); - System.out.println(" " + name + ": " + value); - } - } - } - - Link link = connectionData.getLink(); - if (verbose && link != null) { - System.out.println(" Link: " + link.getHref()); - } - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java deleted file mode 100644 index 0685c5050..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionFindCLI.java +++ /dev/null @@ -1,109 +0,0 @@ -// --- 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.tps.connection; - -import java.util.Arrays; -import java.util.Collection; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.tps.connection.ConnectionCollection; -import com.netscape.certsrv.tps.connection.ConnectionData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionFindCLI extends CLI { - - public ConnectionCLI connectionCLI; - - public ConnectionFindCLI(ConnectionCLI connectionCLI) { - super("find", "Find connections", connectionCLI); - this.connectionCLI = connectionCLI; - - createOptions(); - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options); - } - - public void createOptions() { - 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); - } - - public void execute(String[] args) throws Exception { - // Always check for "--help" prior to parsing - if (Arrays.asList(args).contains("--help")) { - // Display usage - printHelp(); - System.exit(0); - } - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(-1); - } - - String[] cmdArgs = cmd.getArgs(); - String filter = cmdArgs.length > 0 ? cmdArgs[0] : null; - - 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); - - ConnectionCollection result = connectionCLI.connectionClient.findConnections(filter, start, size); - - MainCLI.printMessage(result.getTotal() + " entries matched"); - if (result.getTotal() == 0) return; - - Collection connections = result.getEntries(); - boolean first = true; - - for (ConnectionData connectionData : connections) { - - if (first) { - first = false; - } else { - System.out.println(); - } - - ConnectionCLI.printConnectionData(connectionData, false); - } - - MainCLI.printMessage("Number of entries returned " + connections.size()); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionModifyCLI.java deleted file mode 100644 index 0d5de705a..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionModifyCLI.java +++ /dev/null @@ -1,126 +0,0 @@ -// --- 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.tps.connection; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.Arrays; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.tps.connection.ConnectionData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionModifyCLI extends CLI { - - public ConnectionCLI connectionCLI; - - public ConnectionModifyCLI(ConnectionCLI connectionCLI) { - super("mod", "Modify connection", connectionCLI); - this.connectionCLI = connectionCLI; - - createOptions(); - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void createOptions() { - Option option = new Option(null, "action", true, "Action: update (default), approve, reject, enable, disable."); - option.setArgName("action"); - options.addOption(option); - - option = new Option(null, "input", true, "Input file containing connection properties."); - option.setArgName("file"); - options.addOption(option); - } - - public void execute(String[] args) throws Exception { - // Always check for "--help" prior to parsing - if (Arrays.asList(args).contains("--help")) { - // Display usage - printHelp(); - System.exit(0); - } - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(-1); - } - - String[] cmdArgs = cmd.getArgs(); - - if (cmdArgs.length != 1) { - System.err.println("Error: No Connection ID specified."); - printHelp(); - System.exit(-1); - } - - String connectionID = cmdArgs[0]; - String action = cmd.getOptionValue("action", "update"); - String input = cmd.getOptionValue("input"); - - ConnectionData connectionData; - - if (action.equals("update")) { - - if (input == null) { - System.err.println("Error: Missing input file"); - printHelp(); - System.exit(-1); - return; - } - - try (BufferedReader in = new BufferedReader(new FileReader(input)); - StringWriter sw = new StringWriter(); - PrintWriter out = new PrintWriter(sw, true)) { - - String line; - while ((line = in.readLine()) != null) { - out.println(line); - } - - connectionData = ConnectionData.valueOf(sw.toString()); - } - - connectionData = connectionCLI.connectionClient.updateConnection(connectionID, connectionData); - - } else { // other actions - connectionData = connectionCLI.connectionClient.changeConnectionStatus(connectionID, action); - } - - MainCLI.printMessage("Modified connection \"" + connectionID + "\""); - - ConnectionCLI.printConnectionData(connectionData, true); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionRemoveCLI.java deleted file mode 100644 index 68289109a..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionRemoveCLI.java +++ /dev/null @@ -1,77 +0,0 @@ -// --- 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.tps.connection; - -import java.util.Arrays; - -import org.apache.commons.cli.CommandLine; - -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionRemoveCLI extends CLI { - - public ConnectionCLI connectionCLI; - - public ConnectionRemoveCLI(ConnectionCLI connectionCLI) { - super("del", "Remove connection", connectionCLI); - this.connectionCLI = connectionCLI; - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void execute(String[] args) throws Exception { - // Always check for "--help" prior to parsing - if (Arrays.asList(args).contains("--help")) { - // Display usage - printHelp(); - System.exit(0); - } - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(-1); - } - - String[] cmdArgs = cmd.getArgs(); - - if (cmdArgs.length != 1) { - System.err.println("Error: No Connection ID specified."); - printHelp(); - System.exit(-1); - } - - String connectionID = args[0]; - - connectionCLI.connectionClient.removeConnection(connectionID); - - MainCLI.printMessage("Deleted connection \"" + connectionID + "\""); - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionShowCLI.java deleted file mode 100644 index 5a37aaffe..000000000 --- a/base/java-tools/src/com/netscape/cmstools/tps/connection/ConnectionShowCLI.java +++ /dev/null @@ -1,99 +0,0 @@ -// --- 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.tps.connection; - -import java.io.FileWriter; -import java.io.PrintWriter; -import java.util.Arrays; - -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.Option; - -import com.netscape.certsrv.tps.connection.ConnectionData; -import com.netscape.cmstools.cli.CLI; -import com.netscape.cmstools.cli.MainCLI; - -/** - * @author Endi S. Dewata - */ -public class ConnectionShowCLI extends CLI { - - public ConnectionCLI connectionCLI; - - public ConnectionShowCLI(ConnectionCLI connectionCLI) { - super("show", "Show connection", connectionCLI); - this.connectionCLI = connectionCLI; - - createOptions(); - } - - public void printHelp() { - formatter.printHelp(getFullName() + " [OPTIONS...]", options); - } - - public void createOptions() { - Option option = new Option(null, "output", true, "Output file to store connection properties."); - option.setArgName("file"); - options.addOption(option); - } - - public void execute(String[] args) throws Exception { - // Always check for "--help" prior to parsing - if (Arrays.asList(args).contains("--help")) { - // Display usage - printHelp(); - System.exit(0); - } - - CommandLine cmd = null; - - try { - cmd = parser.parse(options, args); - - } catch (Exception e) { - System.err.println("Error: " + e.getMessage()); - printHelp(); - System.exit(-1); - } - - String[] cmdArgs = cmd.getArgs(); - - if (cmdArgs.length != 1) { - System.err.println("Error: No Connection ID specified."); - printHelp(); - System.exit(-1); - } - - String connectionID = args[0]; - String output = cmd.getOptionValue("output"); - - ConnectionData connectionData = connectionCLI.connectionClient.getConnection(connectionID); - - if (output == null) { - MainCLI.printMessage("Connection \"" + connectionID + "\""); - ConnectionCLI.printConnectionData(connectionData, true); - - } else { - try (PrintWriter out = new PrintWriter(new FileWriter(output))) { - out.println(connectionData); - } - MainCLI.printMessage("Stored connection \"" + connectionID + "\" into " + output); - } - } -} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java new file mode 100644 index 000000000..72653dac3 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorAddCLI.java @@ -0,0 +1,108 @@ +// --- 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.tps.connector; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.connection.ConnectionData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorAddCLI extends CLI { + + public ConnectorCLI connectorCLI; + + public ConnectorAddCLI(ConnectorCLI connectorCLI) { + super("add", "Add connector", connectorCLI); + this.connectorCLI = connectorCLI; + + createOptions(); + } + + public void printHelp() { + formatter.printHelp(getFullName() + " --input [OPTIONS...]", options); + } + + public void createOptions() { + Option option = new Option(null, "input", true, "Input file containing connector properties."); + option.setArgName("file"); + option.setRequired(true); + options.addOption(option); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 0) { + System.err.println("Error: Too many arguments specified."); + printHelp(); + System.exit(-1); + } + + String input = cmd.getOptionValue("input"); + + ConnectionData connectionData; + + try (BufferedReader in = new BufferedReader(new FileReader(input)); + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw, true)) { + + String line; + while ((line = in.readLine()) != null) { + out.println(line); + } + + connectionData = ConnectionData.valueOf(sw.toString()); + } + + connectionData = connectorCLI.connectionClient.addConnection(connectionData); + + MainCLI.printMessage("Added connector \"" + connectionData.getID() + "\""); + + ConnectorCLI.printConnectionData(connectionData, true); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorCLI.java new file mode 100644 index 000000000..73422f12e --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorCLI.java @@ -0,0 +1,75 @@ +// --- 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.tps.connector; + +import java.io.IOException; +import java.util.Map; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.tps.connection.ConnectionClient; +import com.netscape.certsrv.tps.connection.ConnectionData; +import com.netscape.cmstools.cli.CLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorCLI extends CLI { + + public ConnectionClient connectionClient; + + public ConnectorCLI(CLI parent) { + super("connector", "Connector management commands", parent); + + addModule(new ConnectorAddCLI(this)); + addModule(new ConnectorFindCLI(this)); + addModule(new ConnectorModifyCLI(this)); + addModule(new ConnectorRemoveCLI(this)); + addModule(new ConnectorShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + connectionClient = (ConnectionClient)parent.getClient("connection"); + + super.execute(args); + } + + public static void printConnectionData(ConnectionData connectionData, boolean showProperties) throws IOException { + System.out.println(" Connector ID: " + connectionData.getID()); + if (connectionData.getStatus() != null) System.out.println(" Status: " + connectionData.getStatus()); + + if (showProperties) { + System.out.println(" Properties:"); + Map properties = connectionData.getProperties(); + if (properties != null) { + for (String name : properties.keySet()) { + String value = properties.get(name); + System.out.println(" " + name + ": " + value); + } + } + } + + Link link = connectionData.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java new file mode 100644 index 000000000..cc93fbb94 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorFindCLI.java @@ -0,0 +1,109 @@ +// --- 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.tps.connector; + +import java.util.Arrays; +import java.util.Collection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.connection.ConnectionCollection; +import com.netscape.certsrv.tps.connection.ConnectionData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorFindCLI extends CLI { + + public ConnectorCLI connectorCLI; + + public ConnectorFindCLI(ConnectorCLI connectorCLI) { + super("find", "Find connectors", connectorCLI); + this.connectorCLI = connectorCLI; + + createOptions(); + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [FILTER] [OPTIONS...]", options); + } + + public void createOptions() { + 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); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + String filter = cmdArgs.length > 0 ? cmdArgs[0] : null; + + 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); + + ConnectionCollection result = connectorCLI.connectionClient.findConnections(filter, start, size); + + MainCLI.printMessage(result.getTotal() + " entries matched"); + if (result.getTotal() == 0) return; + + Collection connections = result.getEntries(); + boolean first = true; + + for (ConnectionData connectionData : connections) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + ConnectorCLI.printConnectionData(connectionData, false); + } + + MainCLI.printMessage("Number of entries returned " + connections.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java new file mode 100644 index 000000000..f92e7c153 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorModifyCLI.java @@ -0,0 +1,126 @@ +// --- 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.tps.connector; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.connection.ConnectionData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorModifyCLI extends CLI { + + public ConnectorCLI connectorCLI; + + public ConnectorModifyCLI(ConnectorCLI connectorCLI) { + super("mod", "Modify connector", connectorCLI); + this.connectorCLI = connectorCLI; + + createOptions(); + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void createOptions() { + Option option = new Option(null, "action", true, "Action: update (default), approve, reject, enable, disable."); + option.setArgName("action"); + options.addOption(option); + + option = new Option(null, "input", true, "Input file containing connector properties."); + option.setArgName("file"); + options.addOption(option); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 1) { + System.err.println("Error: No Connector ID specified."); + printHelp(); + System.exit(-1); + } + + String connectorID = cmdArgs[0]; + String action = cmd.getOptionValue("action", "update"); + String input = cmd.getOptionValue("input"); + + ConnectionData connectionData; + + if (action.equals("update")) { + + if (input == null) { + System.err.println("Error: Missing input file"); + printHelp(); + System.exit(-1); + return; + } + + try (BufferedReader in = new BufferedReader(new FileReader(input)); + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw, true)) { + + String line; + while ((line = in.readLine()) != null) { + out.println(line); + } + + connectionData = ConnectionData.valueOf(sw.toString()); + } + + connectionData = connectorCLI.connectionClient.updateConnection(connectorID, connectionData); + + } else { // other actions + connectionData = connectorCLI.connectionClient.changeConnectionStatus(connectorID, action); + } + + MainCLI.printMessage("Modified connector \"" + connectorID + "\""); + + ConnectorCLI.printConnectionData(connectionData, true); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java new file mode 100644 index 000000000..d8c9b2a71 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorRemoveCLI.java @@ -0,0 +1,77 @@ +// --- 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.tps.connector; + +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorRemoveCLI extends CLI { + + public ConnectorCLI connectorCLI; + + public ConnectorRemoveCLI(ConnectorCLI connectorCLI) { + super("del", "Remove connector", connectorCLI); + this.connectorCLI = connectorCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 1) { + System.err.println("Error: No Connector ID specified."); + printHelp(); + System.exit(-1); + } + + String connectorID = args[0]; + + connectorCLI.connectionClient.removeConnection(connectorID); + + MainCLI.printMessage("Deleted connector \"" + connectorID + "\""); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java new file mode 100644 index 000000000..57eac7d33 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/connector/ConnectorShowCLI.java @@ -0,0 +1,99 @@ +// --- 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.tps.connector; + +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Arrays; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.connection.ConnectionData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class ConnectorShowCLI extends CLI { + + public ConnectorCLI connectorCLI; + + public ConnectorShowCLI(ConnectorCLI connectorCLI) { + super("show", "Show connector", connectorCLI); + this.connectorCLI = connectorCLI; + + createOptions(); + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void createOptions() { + Option option = new Option(null, "output", true, "Output file to store connector properties."); + option.setArgName("file"); + options.addOption(option); + } + + public void execute(String[] args) throws Exception { + // Always check for "--help" prior to parsing + if (Arrays.asList(args).contains("--help")) { + // Display usage + printHelp(); + System.exit(0); + } + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(-1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 1) { + System.err.println("Error: No Connector ID specified."); + printHelp(); + System.exit(-1); + } + + String connectorID = args[0]; + String output = cmd.getOptionValue("output"); + + ConnectionData connectionData = connectorCLI.connectionClient.getConnection(connectorID); + + if (output == null) { + MainCLI.printMessage("Connector \"" + connectorID + "\""); + ConnectorCLI.printConnectionData(connectionData, true); + + } else { + try (PrintWriter out = new PrintWriter(new FileWriter(output))) { + out.println(connectionData); + } + MainCLI.printMessage("Stored connector \"" + connectorID + "\" into " + output); + } + } +} -- cgit