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