use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class Man method getApp.
private App getApp(AppCommandParser parser) throws Exception {
String appName = parser.arguments().get(0).toLowerCase();
App app = this.getServer().findApp(appName);
if (app == null) {
throw new ShellException("No manual entry for '" + appName + "'");
}
return app;
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class AbstractAppServer method interpretLine.
@Override
public Response interpretLine(Serializable clientId, String line, Output out) throws ShellException {
Session session = getClientSession(clientId);
if (line == null || line.trim().length() == 0) {
return new Response(getPrompt(session), Continuation.INPUT_COMPLETE);
}
try {
Continuation commandResult = null;
for (String command : line.split(Pattern.quote("&&"))) {
command = TextUtil.removeSpaces(command);
command = replaceAlias(command, session);
AppCommandParser parser = new AppCommandParser(this, command);
commandResult = parser.app().execute(parser, session, out);
}
return new Response(getPrompt(session), commandResult);
} catch (Exception e) {
throw wrapException(e);
}
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class IndexProviderShellApp method index.
private void index(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
NodeOrRelationship current = getCurrent(session);
String index = getIndexName(parser);
String key = parser.argument(1, "Key not supplied");
Object value = parser.arguments().size() > 2 ? parser.arguments().get(2) : current.getProperty(key, null);
if (value == null) {
throw new ShellException("No value to index");
}
Index theIndex = current.isNode() ? getServer().getDb().index().forNodes(index) : getServer().getDb().index().forRelationships(index);
theIndex.add(current.asPropertyContainer(), key, value);
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class Mkrel method exec.
@Override
protected Continuation exec(AppCommandParser parser, Session session, Output out) throws ShellException, RemoteException {
assertCurrentIsNode(session);
boolean createNode = parser.options().containsKey("c");
boolean suppliedNode = !parser.arguments().isEmpty();
Node node = null;
if (createNode) {
node = getServer().getDb().createNode(parseLabels(parser));
session.set(KEY_LAST_CREATED_NODE, "" + node.getId());
setProperties(node, parser.options().get("np"));
} else if (suppliedNode) {
node = getNodeById(Long.parseLong(parser.arguments().get(0)));
} else {
throw new ShellException("Must either create node (-c)" + " or supply node id as the first argument");
}
if (parser.options().get("t") == null) {
throw new ShellException("Must supply relationship type " + "(-t <relationship-type-name>)");
}
RelationshipType type = getRelationshipType(parser.options().get("t"));
Direction direction = getDirection(parser.options().get("d"));
NodeOrRelationship current = getCurrent(session);
Node currentNode = current.asNode();
Node startNode = direction == Direction.OUTGOING ? currentNode : node;
Node endNode = direction == Direction.OUTGOING ? node : currentNode;
Relationship relationship = startNode.createRelationshipTo(endNode, type);
setProperties(relationship, parser.options().get("rp"));
session.set(KEY_LAST_CREATED_RELATIONSHIP, relationship.getId());
boolean verbose = parser.options().containsKey("v");
if (createNode && verbose) {
out.println("Node " + getDisplayName(getServer(), session, node, false) + " created");
}
if (verbose) {
out.println("Relationship " + getDisplayName(getServer(), session, relationship, true, false) + " created");
}
if (parser.options().containsKey("cd")) {
cdTo(session, node);
}
return Continuation.INPUT_COMPLETE;
}
use of org.neo4j.shell.ShellException in project neo4j by neo4j.
the class TransactionProvidingApp method getCurrent.
/**
* @param server the {@link GraphDatabaseShellServer} to get the current
* node/relationship from.
* @param session the {@link Session} used by the client.
* @return the current node/relationship the client stands on
* at the moment.
* @throws ShellException if some error occured.
*/
public static NodeOrRelationship getCurrent(GraphDatabaseShellServer server, Session session) throws ShellException {
String currentThing = session.getCurrent();
NodeOrRelationship result;
/* Note: Artifact of removing the ref node, revisit and clean up */
if (currentThing == null || currentThing.equals("(?)")) {
throw new ShellException("Not currently standing on any entity.");
} else {
TypedId typedId = new TypedId(currentThing);
result = getThingById(server, typedId);
}
return result;
}
Aggregations