package bosdk;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import com.businessobjects.sdk.plugin.desktop.common.IConfiguredContainer;
import com.businessobjects.sdk.plugin.desktop.common.IExecProps;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.ISessionMgr;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.plugin.desktop.server.ExpectedRunState;
import com.crystaldecisions.sdk.plugin.desktop.server.IServer;
public class ChangeServerCommandLine {
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void main(String[] args) {
// Process the input parameter
Map<String, String> m_args = null;
if (args.length > 0) {
m_args = new HashMap();
parseArgs(args, m_args);
} else {
System.err.println(
"Arguments not passed. Usage:-cms <cms> -username <username> -password <password> -serverid <serverid> and -authentication <authentication> Note: authentication argument is optional");
System.exit(0);
}
String cms = (String) m_args.get("cms");
String username = (String) m_args.get("username");
String password = (String) m_args.get("password");
String serverid = (String) m_args.get("serverid");
if ((username == null) || (password == null) || (cms == null) || (serverid == null) || (username.length() == 0)
|| (password.length() == 0) || (cms.length() == 0) || (serverid.length() == 0)) {
System.err.println(
"Arguments not passed. Usage:-cms <cms> -username <username> -password <password> -serverid <serverid> and -authentication <authentication> Note: authentication argument is optional");
System.exit(0);
}
String authentication = (String) m_args.get("authentication");
if ((authentication == null) || (authentication.length() <= 0)) {
authentication = "secEnterprise";
}
IEnterpriseSession enterpriseSession = null;
ISessionMgr enterpriseSessionMgr;
try {
// Login and get the server infoobject
enterpriseSessionMgr = CrystalEnterprise.getSessionMgr();
enterpriseSession = enterpriseSessionMgr.logon(username, password, cms, authentication);
IInfoStore infostore = (IInfoStore) enterpriseSession.getService("InfoStore");
String serverQuery = "select * from CI_SYSTEMOBJECTS where SI_ID = " + serverid;
IServer server = (IServer) infostore.query(serverQuery).get(0);
// Get the server command parameter
IConfiguredContainer cfgContainer = server.getContainer();
IExecProps execProps = cfgContainer.getExecProps();
// Print Current Server name and command line info
System.out.println("Server you want to change is: " + server.getTitle());
System.out.println("Command line before change: " + execProps.getArgs());
// Prompt user to input the new command line
System.out.println("Please input the new command line: ");
InputStreamReader is = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(is);
String command = br.readLine();
// Change the command line
execProps.setArgs(command);
// Prompt user to input if server will be restarted now
System.out.println("Please tell us whether you want to restart the server: (yes or no)");
is = new InputStreamReader(System.in);
br = new BufferedReader(is);
String restart = br.readLine();
// if yes, restart server
if (restart.toLowerCase().equals("yes")) {
server.setExpectedRunState(ExpectedRunState.RESTART);
}
// Save the change and print the process is done.
server.save();
System.out.println("Change is done! New command line after change: " + execProps.getArgs());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
private static void parseArgs(String[] args, Map<String, String> m_args) {
for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) {
String arg = trimArg(args[i]);
if (arg.length() != 0) {
i++;
String value = "";
if (i < args.length) {
value = args[i];
if (value.startsWith("-")) {
value = "";
i--;
}
}
m_args.put(arg, value);
}
}
}
}
private static String trimArg(String arg) {
if (arg == null) {
return arg;
}
int i = 0;
for (i = 0; i < arg.length(); i++) {
if (arg.charAt(i) != '-') {
break;
}
}
String trimmedArg = arg.substring(i);
return trimmedArg;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
38 | |
25 | |
17 | |
13 | |
7 | |
7 | |
7 | |
7 | |
6 | |
6 |