コード例 #1
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    User user = getUser(request);
    Authorizations authorizations = getAuthorizations(request, user);
    String workspaceId = getWorkspaceId(request);

    String graphVertexId = (String) request.getAttribute("graphVertexId");
    long offset = getOptionalParameterLong(request, "offset", 0);
    long size = getOptionalParameterLong(request, "size", 25);

    Vertex vertex = graph.getVertex(graphVertexId, authorizations);
    if (vertex == null) {
      respondWithNotFound(response);
      return;
    }

    Iterable<Edge> edges = vertex.getEdges(Direction.BOTH, authorizations);

    JSONObject json = new JSONObject();
    JSONArray relationshipsJson = new JSONArray();
    long referencesAdded = 0, skipped = 0, totalReferences = 0;
    for (Edge edge : edges) {
      Vertex otherVertex = edge.getOtherVertex(vertex.getId(), authorizations);
      if (otherVertex == null) { // user doesn't have access to other side of edge
        continue;
      }

      if (edge.getLabel().equals("http://lumify.io/dev#rawHasEntity")) {
        totalReferences++;
        if (referencesAdded >= size) continue;
        if (skipped < offset) {
          skipped++;
          continue;
        }

        referencesAdded++;
      }

      JSONObject relationshipJson = new JSONObject();
      relationshipJson.put("relationship", toJson(edge, workspaceId));
      relationshipJson.put("vertex", toJson(otherVertex, workspaceId));
      relationshipsJson.put(relationshipJson);
    }
    json.put("totalReferences", totalReferences);
    json.put("relationships", relationshipsJson);

    respondWithJson(response, json);
  }
コード例 #2
0
  @Override
  public void handle(HttpServletRequest request, HttpServletResponse response, HandlerChain chain)
      throws Exception {
    final String graphVertexId = getAttributeString(request, "graphVertexId");
    User user = getUser(request);
    Authorizations authorizations = getAuthorizations(request, user);
    ModelUserContext modelUserContext =
        userProvider.getModelUserContext(authorizations, getWorkspaceId(request));
    String workspaceId = getWorkspaceId(request);

    Vertex vertex = graph.getVertex(graphVertexId, authorizations);
    if (vertex == null) {
      respondWithNotFound(response);
      return;
    }
    JSONObject json = GraphUtil.toJson(vertex, workspaceId);

    json.put(
        "detectedObjects",
        detectedObjectRepository.toJSON(vertex, modelUserContext, authorizations, workspaceId));

    respondWithJson(response, json);
  }
コード例 #3
0
 public static Iterable<Vertex> toVertices(
     Graph graph, Iterable<WorkspaceEntity> workspaceEntities, Authorizations authorizations) {
   Iterable<Object> vertexIds = toVertexIds(workspaceEntities);
   return graph.getVertices(vertexIds, authorizations);
 }