コード例 #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
  public List<Audit> auditRelationship(
      AuditAction action,
      Vertex sourceVertex,
      Vertex destVertex,
      Edge edge,
      String process,
      String comment,
      User user,
      Visibility visibility) {
    checkNotNull(action, "action cannot be null");
    checkNotNull(sourceVertex, "sourceVertex cannot be null");
    checkNotNull(destVertex, "destVertex cannot be null");
    checkNotNull(edge, "edge cannot be null");
    checkNotNull(process, "process cannot be null");
    checkNotNull(comment, "comment cannot be null");
    checkNotNull(user, "user cannot be null");

    Audit auditSourceDest = new Audit(AuditRowKey.build(sourceVertex.getId(), destVertex.getId()));
    Audit auditDestSource = new Audit(AuditRowKey.build(destVertex.getId(), sourceVertex.getId()));
    Audit auditEdge = new Audit(AuditRowKey.build(edge.getId()));
    visibility = orVisibility(visibility);

    List<Audit> audits = new ArrayList<Audit>();
    String displayLabel = ontologyRepository.getDisplayNameForLabel(edge.getLabel());
    audits.add(
        auditRelationshipHelper(
            auditSourceDest,
            action,
            sourceVertex,
            destVertex,
            displayLabel,
            process,
            comment,
            user,
            visibility));
    audits.add(
        auditRelationshipHelper(
            auditDestSource,
            action,
            sourceVertex,
            destVertex,
            displayLabel,
            process,
            comment,
            user,
            visibility));
    auditEdge
        .getAuditCommon()
        .setUser(user, visibility)
        .setAction(action, visibility)
        .setType(OntologyRepository.TYPE_RELATIONSHIP, visibility)
        .setComment(comment, visibility)
        .setProcess(process, visibility)
        .setUnixBuildTime(
            versionService.getUnixBuildTime() != null ? versionService.getUnixBuildTime() : -1L,
            visibility)
        .setScmBuildNumber(
            versionService.getScmBuildNumber() != null ? versionService.getScmBuildNumber() : "",
            visibility)
        .setVersion(
            versionService.getVersion() != null ? versionService.getVersion() : "", visibility);

    auditEdge
        .getAuditRelationship()
        .setSourceId(sourceVertex.getId(), visibility)
        .setSourceType(CONCEPT_TYPE.getPropertyValue(sourceVertex), visibility)
        .setSourceTitle(TITLE.getPropertyValue(sourceVertex), visibility)
        .setDestId(destVertex.getId(), visibility)
        .setDestTitle(TITLE.getPropertyValue(destVertex), visibility)
        .setDestType(CONCEPT_TYPE.getPropertyValue(destVertex), visibility)
        .setLabel(displayLabel, visibility);

    audits.add(auditEdge);

    saveMany(audits);
    return audits;
  }