Search in sources :

Example 26 with ShellException

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;
}
Also used : App(org.neo4j.shell.App) AbstractApp(org.neo4j.shell.impl.AbstractApp) ShellException(org.neo4j.shell.ShellException)

Example 27 with ShellException

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);
    }
}
Also used : Response(org.neo4j.shell.Response) Continuation(org.neo4j.shell.Continuation) AppCommandParser(org.neo4j.shell.AppCommandParser) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException) Session(org.neo4j.shell.Session)

Example 28 with ShellException

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);
}
Also used : JSONObject(org.neo4j.shell.util.json.JSONObject) Index(org.neo4j.graphdb.index.Index) ShellException(org.neo4j.shell.ShellException)

Example 29 with ShellException

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;
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) RelationshipType(org.neo4j.graphdb.RelationshipType) ShellException(org.neo4j.shell.ShellException) Direction(org.neo4j.graphdb.Direction)

Example 30 with ShellException

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;
}
Also used : ShellException.stackTraceAsString(org.neo4j.shell.ShellException.stackTraceAsString) ShellException(org.neo4j.shell.ShellException)

Aggregations

ShellException (org.neo4j.shell.ShellException)33 RemoteException (java.rmi.RemoteException)12 Node (org.neo4j.graphdb.Node)6 Test (org.junit.Test)5 Relationship (org.neo4j.graphdb.Relationship)4 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)4 GraphDatabaseShellServer (org.neo4j.shell.kernel.GraphDatabaseShellServer)4 Serializable (java.io.Serializable)3 Kernel (org.neo4j.jmx.Kernel)3 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)3 Response (org.neo4j.shell.Response)3 Session (org.neo4j.shell.Session)3 ShellServer (org.neo4j.shell.ShellServer)3 JSONException (org.neo4j.shell.util.json.JSONException)3 ManagementFactory.getPlatformMBeanServer (java.lang.management.ManagementFactory.getPlatformMBeanServer)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MBeanServer (javax.management.MBeanServer)2 Label (org.neo4j.graphdb.Label)2 ThreadToStatementContextBridge (org.neo4j.kernel.impl.core.ThreadToStatementContextBridge)2