Skip to content
Snippets Groups Projects
Commit e99d5c27 authored by felmer's avatar felmer
Browse files

LMS-1485 Admin Console

SVN: 15479
parent dbf6a329
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,9 @@
<property name="jar.file.name" value="${ant.project.name}.jar" />
<property name="jar.file" value="${dist}/${jar.file.name}" />
<property name="client.jar.file" value="${dist}/${ant.project.name}-client.jar" />
<property name="admin.console" value="openbis-admin-console" />
<property name="admin.jar.file" value="${dist}/${admin.console}.jar" />
<property name="admin.dist.file" value="${dist}/${admin.console}.zip" />
<property name="webapp.file.name" value="openBIS.war" />
<property name="webapp.file" value="${server.dist}/${webapp.file.name}" />
......@@ -138,7 +141,23 @@
</antcall>
</target>
<target name="make-dist" description="Makes a distribution file." depends="check-dictionary-syntax, clean, war">
<target name="admin-console-dist" depends="jar"
description="Makes a distribution file for the admin console.">
<zip destfile="${admin.dist.file}">
<zipfileset prefix="${admin.console}" file="${admin.jar.file}"/>
<zipfileset prefix="${admin.console}" file="${lib}/cisd-base/cisd-base.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/commons-codec/commons-codec.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/commons-httpclient/commons-httpclient.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/commons-io/commons-io.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/commons-logging/commons-logging.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/jline/jline.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/log4j/log4j.jar"/>
<zipfileset prefix="${admin.console}" file="${lib}/spring/spring.jar"/>
</zip>
</target>
<target name="make-dist" description="Makes a distribution file."
depends="check-dictionary-syntax, clean, war, admin-console-dist">
<copy file="${lib}/tomcat5/apache-tomcat.zip" todir="${server.dist}" />
<loadfile property="tomcat.version" srcFile="${lib}/tomcat5/version.txt">
<filterchain>
......@@ -148,6 +167,7 @@
<echo file="${server.dist}/tomcat-version.txt">${tomcat.version}</echo>
<copy file="${original.openbis.server.dist}/server.xml" todir="${server.dist}" />
<move file="${client.jar.file}" todir="${server.dist}" />
<move file="${admin.dist.file}" todir="${server.dist}" />
<copy file="${original.server.dist}/service.properties" todir="${server.dist}" />
<copy file="${original.server.dist}/openbis.conf" todir="${server.dist}" />
<copy file="${original.openbis.server.dist}/openBIS.keystore" todir="${server.dist}" />
......@@ -375,7 +395,7 @@
<include name="**/shared/I*.class" />
<include name="**/shared/basic/dto/*.class" />
<include name="**/shared/basic/*.class" />
<include name="**/shared/dto/*.class" />
<include name="**/shared/dto/**/*.class" />
<exclude name="**/shared/dto/*PE.class" />
<include name="**/shared/authorization/annotation/*.class" />
<include name="**/shared/authorization/ISessionProvider.class" />
......@@ -393,6 +413,33 @@
<attribute name="Main-Class" value="ch.systemsx.cisd.openbis.BuildAndEnvironmentInfo" />
</manifest>
</jar>
<jar destfile="${admin.jar.file}">
<zipfileset src="${jar.file}">
<include name="ch/systemsx/cisd/common/spring/HttpInvokerUtils.class" />
<include name="ch/systemsx/cisd/common/**/*.class" />
<include name="ch/systemsx/cisd/openbis/generic/client/console/**/*.class" />
<include name="**/shared/I*.class" />
<include name="**/shared/basic/dto/*.class" />
<include name="**/shared/basic/*.class" />
<include name="**/shared/dto/**/*.class" />
<exclude name="**/shared/dto/*PE.class" />
<include name="**/shared/authorization/annotation/*.class" />
<include name="**/shared/authorization/ISessionProvider.class" />
<include name="**/*BuildAndEnvironmentInfo.class" />
<include name="*.INFO" />
</zipfileset>
<zipfileset src="${lib}/gwt2.0/gwt-user.jar">
<include name="com/google/gwt/user/client/rpc/IsSerializable.class" />
<include name="com/google/gwt/user/client/rpc/SerializableException.class" />
</zipfileset>
<manifest>
<attribute name="Main-Class" value="ch.systemsx.cisd.openbis.generic.client.console.AdminConsole" />
<attribute name="Class-Path"
value="${admin.console}.jar cisd-base.jar commons-codec.jar
commons-httpclient.jar commons-io.jar commons-logging.jar
log4j.jar jline.jar spring.jar"/>
</manifest>
</jar>
</target>
<!--
......
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import jline.ConsoleReader;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.exceptions.UserFailureException;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.spring.HttpInvokerUtils;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
import ch.systemsx.cisd.openbis.generic.shared.dto.SessionContextDTO;
/**
*
*
* @author Franz-Josef Elmer
*/
public class AdminConsole
{
private static final String SERVICE_PATH = "/rmi-common";
public static void main(String[] args) throws Exception
{
if (args.length < 3)
{
System.err.println("Usage: java -jar openbis-admin-console.jar "
+ " <server url> <script path> <user ID> [<password>]");
System.exit(1);
}
String serverURL = args[0];
String script = args[1];
String userID = args[2];
String password;
if (args.length == 4)
{
password =args[3];
} else
{
password = getConsoleReader().readLine("Password: ", Character.valueOf('*'));
}
ICommonServer service = HttpInvokerUtils.createServiceStub(ICommonServer.class, serverURL + SERVICE_PATH, 5);
SessionContextDTO session = service.tryToAuthenticate(userID, password);
if (session == null)
{
System.err.println("Authentication failed");
} else
{
System.out.println("Run script " + script);
Map<String, ICommand> commands = createCommands();
String sessionToken = session.getSessionToken();
List<String> lines = FileUtilities.loadToStringList(new File(script));
ScriptContext context = new ScriptContext();
for (int i = 0; i < lines.size(); i++)
{
String line = lines.get(i).trim();
if (line.length() > 0 && line.startsWith("--") == false)
{
int indexOfSpace = line.indexOf(' ');
String command = indexOfSpace < 0 ? line : line.substring(0, indexOfSpace);
String argument = indexOfSpace < 0 ? "" : line.substring(indexOfSpace).trim();
argument = context.resolveVariables(argument);
ICommand cmd = commands.get(command);
if (cmd == null)
{
throw createException(i, line, "Unknown command: " + command);
}
try
{
cmd.execute(service, sessionToken, context, argument);
} catch (RuntimeException ex)
{
throw createException(i, line, ex);
}
}
}
service.logout(sessionToken);
}
}
private static UserFailureException createException(int lineIndex, String line, Object reason)
{
String message = "Error in line " + (lineIndex + 1) + " [" + line
+ "]\nReason: " + reason;
if (reason instanceof Throwable)
{
Throwable throwable = (Throwable) reason;
return new UserFailureException(message, throwable);
}
return new UserFailureException(message);
}
private static ConsoleReader getConsoleReader()
{
try
{
return new ConsoleReader();
} catch (final IOException ex)
{
throw new EnvironmentFailureException("ConsoleReader could not be instantiated.",
ex);
}
}
private static Map<String, ICommand> createCommands()
{
HashMap<String, ICommand> map = new HashMap<String, ICommand>();
map.put("register-type", new RegisterType());
map.put("assign-to", new Assignment());
map.put("set", new Set());
return map;
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.EntityKind;
/**
*
*
* @author Franz-Josef Elmer
*/
class Assignment implements ICommand
{
private static final String MANDATORY = "mandatory";
public void execute(ICommonServer server, String sessionToken, ScriptContext context, String argument)
{
String[] arguments = argument.split(" ");
String[] entityKindAndType = arguments[0].split(":");
EntityKind entityKind = EntityKind.valueOf(entityKindAndType[0]);
String entityTypeCode = entityKindAndType[1];
String propertyTypeCode = arguments[1];
boolean isMandatory = false;
if (arguments.length > 2)
{
if (arguments[2].equals(MANDATORY) == false)
{
throw new IllegalArgumentException("'" + MANDATORY + "' expected instead of '"
+ arguments[2] + "'.");
}
isMandatory = true;
}
server.assignPropertyType(sessionToken, entityKind, propertyTypeCode, entityTypeCode,
isMandatory, null, null, 0L);
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
/**
*
*
* @author Franz-Josef Elmer
*/
interface ICommand
{
public void execute(ICommonServer server, String sessionToken, ScriptContext context, String argument);
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
import ch.systemsx.cisd.openbis.generic.shared.basic.dto.DataSetType;
/**
*
*
* @author Franz-Josef Elmer
*/
class RegisterDataSetType implements ICommand
{
public void execute(ICommonServer server, String sessionToken, ScriptContext context, String argument)
{
server.registerDataSetType(sessionToken, new DataSetType(argument));
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import java.util.HashMap;
import java.util.Map;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
/**
*
*
* @author Franz-Josef Elmer
*/
class RegisterType implements ICommand
{
private final Map<String, ICommand> commands;
RegisterType()
{
commands = new HashMap<String, ICommand>();
commands.put("DATA_SET", new RegisterDataSetType());
}
public void execute(ICommonServer server, String sessionToken, ScriptContext context, String argument)
{
int indexOfSpace = argument.indexOf(' ');
String command = indexOfSpace < 0 ? argument : argument.substring(0, indexOfSpace);
ICommand cmd = commands.get(command);
if (cmd == null)
{
throw new IllegalArgumentException("Unkown register command: " + command);
}
cmd.execute(server, sessionToken, null, indexOfSpace < 0 ? "" : argument.substring(indexOfSpace).trim());
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import ch.systemsx.cisd.common.utilities.Template;
/**
*
*
* @author Franz-Josef Elmer
*/
class ScriptContext
{
private final Map<String, String> bindings = new HashMap<String, String>();
void bind(String variable, String value)
{
bindings.put(variable, value);
}
public String resolveVariables(String argument)
{
Template template = new Template(argument);
Set<String> placeholderNames = template.getPlaceholderNames();
for (String placeholderName : placeholderNames)
{
String value = bindings.get(placeholderName);
if (value == null)
{
throw new IllegalArgumentException("Place holder '" + placeholderName
+ "' is undefined.");
}
template.bind(placeholderName, value);
}
return template.createText();
}
}
/*
* Copyright 2010 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.openbis.generic.client.console;
import ch.systemsx.cisd.openbis.generic.shared.ICommonServer;
/**
*
*
* @author Franz-Josef Elmer
*/
class Set implements ICommand
{
public void execute(ICommonServer server, String sessionToken, ScriptContext context,
String argument)
{
int indexOfAssignmentSymbol = argument.indexOf('=');
if (indexOfAssignmentSymbol < 0)
{
throw new IllegalArgumentException("Missing '='.");
}
String name = argument.substring(0, indexOfAssignmentSymbol).trim();
String value = argument.substring(indexOfAssignmentSymbol + 1).trim();
context.bind(name, value);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment