Esempio n. 1
0
  @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;
  }