예제 #1
0
 private TypedId getStartOrEnd(NodeOrRelationship current, String arg) throws ShellException {
   if (!current.isRelationship()) {
     throw new ShellException("Only allowed on relationships");
   }
   Node newNode = null;
   if (arg.equals(START_ALIAS)) {
     newNode = current.asRelationship().getStartNode();
   } else if (arg.equals(END_ALIAS)) {
     newNode = current.asRelationship().getEndNode();
   } else {
     throw new ShellException("Unknown alias '" + arg + "'");
   }
   return NodeOrRelationship.wrap(newNode).getTypedId();
 }
예제 #2
0
 @Override
 public List<String> completionCandidates(String partOfLine, Session session) {
   String lastWord = TextUtil.lastWordOrQuoteOf(partOfLine, false);
   if (lastWord.startsWith("-")) {
     return super.completionCandidates(partOfLine, session);
   }
   try {
     TreeSet<String> result = new TreeSet<String>();
     NodeOrRelationship current = getCurrent(session);
     if (current.isNode()) {
       // TODO Check if -r is supplied
       Node node = current.asNode();
       for (Node otherNode : RelationshipToNodeIterable.wrap(node.getRelationships(), node)) {
         long otherNodeId = otherNode.getId();
         String title = findTitle(getServer(), session, otherNode);
         if (title != null) {
           if (!result.contains(title)) {
             maybeAddCompletionCandidate(result, title + "," + otherNodeId, lastWord);
           }
         }
         maybeAddCompletionCandidate(result, "" + otherNodeId, lastWord);
       }
     } else {
       maybeAddCompletionCandidate(result, START_ALIAS, lastWord);
       maybeAddCompletionCandidate(result, END_ALIAS, lastWord);
       Relationship rel = current.asRelationship();
       maybeAddCompletionCandidate(result, "" + rel.getStartNode().getId(), lastWord);
       maybeAddCompletionCandidate(result, "" + rel.getEndNode().getId(), lastWord);
     }
     return new ArrayList<String>(result);
   } catch (ShellException e) {
     e.printStackTrace();
     return super.completionCandidates(partOfLine, session);
   }
 }
예제 #3
0
  private boolean isConnected(NodeOrRelationship current, TypedId newId) throws ShellException {
    if (current.isNode()) {
      Node currentNode = current.asNode();
      for (Relationship rel : currentNode.getRelationships()) {
        if (newId.isNode()) {
          if (rel.getOtherNode(currentNode).getId() == newId.getId()) {
            return true;
          }
        } else {
          if (rel.getId() == newId.getId()) {
            return true;
          }
        }
      }
    } else {
      if (newId.isRelationship()) {
        return false;
      }

      Relationship relationship = current.asRelationship();
      if (relationship.getStartNode().getId() == newId.getId()
          || relationship.getEndNode().getId() == newId.getId()) {
        return true;
      }
    }
    return false;
  }
예제 #4
0
 /**
  * @param server the {@link GraphDatabaseShellServer} to run at.
  * @param session the {@link Session} used by the client.
  * @param thing the thing to get the name-representation for.
  * @return the display name for a {@link Node}.
  */
 public static String getDisplayName(
     GraphDatabaseShellServer server,
     Session session,
     NodeOrRelationship thing,
     boolean checkForMe)
     throws ShellException {
   if (thing.isNode()) {
     return getDisplayName(server, session, thing.asNode(), checkForMe);
   } else {
     return getDisplayName(server, session, thing.asRelationship(), true, checkForMe);
   }
 }