コード例 #1
0
  @Override
  protected String exec(AppCommandParser parser, Session session, Output out)
      throws ShellException {
    if (parser.arguments().size() < 2) {
      throw new ShellException(
          "Must supply <from-key> <to-key> " + "arguments, like: mv name \"given_name\"");
    }
    String fromKey = parser.arguments().get(0);
    String toKey = parser.arguments().get(1);
    boolean mayOverwrite = parser.options().containsKey("o");
    NodeOrRelationship thing = getCurrent(session);
    if (!thing.hasProperty(fromKey)) {
      throw new ShellException("Property '" + fromKey + "' doesn't exist");
    }
    if (thing.hasProperty(toKey)) {
      if (!mayOverwrite) {
        throw new ShellException(
            "Property '" + toKey + "' already exists, supply -o flag to overwrite");
      } else {
        thing.removeProperty(toKey);
      }
    }

    Object value = thing.removeProperty(fromKey);
    thing.setProperty(toKey, value);
    return null;
  }
コード例 #2
0
ファイル: Cd.java プロジェクト: eldersantos/community
  @Override
  protected String exec(AppCommandParser parser, Session session, Output out)
      throws ShellException, RemoteException {
    List<TypedId> paths = readCurrentWorkingDir(session);

    NodeOrRelationship current = getCurrent(session);
    NodeOrRelationship newThing = null;
    if (parser.arguments().isEmpty()) {
      newThing = NodeOrRelationship.wrap(getServer().getDb().getReferenceNode());
      paths.clear();
    } else {
      String arg = parser.arguments().get(0);
      TypedId newId = current.getTypedId();
      if (arg.equals("..")) {
        if (paths.size() > 0) {
          newId = paths.remove(paths.size() - 1);
        }
      } else if (arg.equals(".")) {
      } else if (arg.equals(START_ALIAS) || arg.equals(END_ALIAS)) {
        newId = getStartOrEnd(current, arg);
        paths.add(current.getTypedId());
      } else {
        long suppliedId = -1;
        try {
          suppliedId = Long.parseLong(arg);
        } catch (NumberFormatException e) {
          suppliedId = findNodeWithTitle(current.asNode(), arg, session);
          if (suppliedId == -1) {
            throw new ShellException("No connected node with title '" + arg + "'");
          }
        }

        newId =
            parser.options().containsKey("r")
                ? new TypedId(NodeOrRelationship.TYPE_RELATIONSHIP, suppliedId)
                : new TypedId(NodeOrRelationship.TYPE_NODE, suppliedId);
        if (newId.equals(current.getTypedId())) {
          throw new ShellException("Can't cd to where you stand");
        }
        boolean absolute = parser.options().containsKey("a");
        if (!absolute && !this.isConnected(current, newId)) {
          throw new ShellException(
              getDisplayName(getServer(), session, newId, false)
                  + " isn't connected to the current primitive,"
                  + " use -a to force it to go there anyway");
        }
        paths.add(current.getTypedId());
      }
      newThing = this.getThingById(newId);
    }

    setCurrent(session, newThing);
    writeCurrentWorkingDir(paths, session);
    return null;
  }
コード例 #3
0
ファイル: Man.java プロジェクト: lassewesth/neo4j
 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;
 }
コード例 #4
0
ファイル: Rmnode.java プロジェクト: Analect/neo4j
  @Override
  protected Continuation exec(AppCommandParser parser, Session session, Output out)
      throws ShellException, RemoteException {
    NodeOrRelationship node = null;
    if (parser.arguments().isEmpty()) {
      node = getCurrent(session);
    } else {
      long id = parseInt(parser.arguments().get(0));
      try {
        node = wrap(getNodeById(id));
      } catch (NotFoundException e) {
        throw new ShellException("No node " + id + " found");
      }
    }

    if (!node.isNode()) {
      out.println("Please select a node to delete");
      return Continuation.INPUT_COMPLETE;
    }

    boolean forceDeletion = parser.options().containsKey("f");
    if (forceDeletion) {
      for (Relationship relationship : node.asNode().getRelationships()) {
        out.println(
            "Relationship "
                + getDisplayName(getServer(), session, relationship, true, false)
                + " deleted");
        relationship.delete();
      }
    }

    if (node.asNode().hasRelationship()) {
      throw new ShellException(
          getDisplayName(getServer(), session, node.asNode(), false)
              + " cannot be deleted because it still has relationships. Use -f to force deletion of its relationships");
    }
    node.asNode().delete();
    return Continuation.INPUT_COMPLETE;
  }
コード例 #5
0
ファイル: Man.java プロジェクト: lassewesth/neo4j
  @Override
  public Continuation execute(AppCommandParser parser, Session session, Output out)
      throws Exception {
    if (parser.arguments().size() == 0) {
      boolean list = parser.options().containsKey("l");
      printHelpString(out, getServer(), list);
      return Continuation.INPUT_COMPLETE;
    }

    App app = this.getApp(parser);
    out.println("");
    for (String line : splitLongLine(fixDesciption(app.getDescription()), CONSOLE_WIDTH)) {
      out.println(line);
    }
    println(out, "");
    boolean hasOptions = false;
    for (String option : app.getAvailableOptions()) {
      hasOptions = true;
      String description = fixDesciption(app.getDescription(option));
      String[] descriptionLines = splitLongLine(description, CONSOLE_WIDTH);
      for (int i = 0; i < descriptionLines.length; i++) {
        String line = "";
        if (i == 0) {
          String optionPrefix = option.length() > 1 ? "--" : "-";
          line = optionPrefix + option;
        }
        line += "\t ";
        line += descriptionLines[i];
        println(out, line);
      }
    }
    if (hasOptions) {
      println(out, "");
    }
    return Continuation.INPUT_COMPLETE;
  }