示例#1
0
  public Vertex findVertex(String propertyKey, Object value) {
    LOG.debug("Finding vertex for {}={}", propertyKey, value);

    GraphQuery query = titanGraph.query().has(propertyKey, value);
    Iterator<Vertex> results = query.vertices().iterator();
    // returning one since entityType, qualifiedName should be unique
    return results.hasNext() ? results.next() : null;
  }
  private Vertex getEntityVertex(String entityName, RelationshipType entityType) {
    GraphQuery entityQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), entityName)
            .has(RelationshipProperty.TYPE.getName(), entityType.getName());
    Iterator<Vertex> iterator = entityQuery.vertices().iterator();
    Assert.assertTrue(iterator.hasNext());

    Vertex entityVertex = iterator.next();
    Assert.assertNotNull(entityVertex);

    return entityVertex;
  }
  private void verifyFeedsClassifiedAsSecure(String feedType, List<String> expected) {
    GraphQuery classQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), "Secure")
            .has(RelationshipProperty.TYPE.getName(), RelationshipType.TAGS.getName());

    List<String> actual = new ArrayList<String>();
    for (Vertex feedVertex : classQuery.vertices()) {
      for (Vertex feed : feedVertex.getVertices(Direction.BOTH, "classified-as")) {
        if (feed.getProperty(RelationshipProperty.TYPE.getName()).equals(feedType)) {
          System.out.println(" Secure classification -> " + GraphUtils.vertexString(feed));
          actual.add(feed.<String>getProperty(RelationshipProperty.NAME.getName()));
        }
      }
    }

    Assert.assertTrue(actual.containsAll(expected), "Actual does not contain expected: " + actual);
  }
  private List<String> getFeedsOwnedByAUser(String feedType) {
    GraphQuery userQuery =
        getQuery()
            .has(RelationshipProperty.NAME.getName(), FALCON_USER)
            .has(RelationshipProperty.TYPE.getName(), RelationshipType.USER.getName());

    List<String> feedNames = new ArrayList<String>();
    for (Vertex userVertex : userQuery.vertices()) {
      for (Vertex feed : userVertex.getVertices(Direction.IN, RelationshipLabel.USER.getName())) {
        if (feed.getProperty(RelationshipProperty.TYPE.getName()).equals(feedType)) {
          System.out.println(FALCON_USER + " owns -> " + GraphUtils.vertexString(feed));
          feedNames.add(feed.<String>getProperty(RelationshipProperty.NAME.getName()));
        }
      }
    }

    return feedNames;
  }
  @Override
  @GraphTransaction
  public List<String> getEntityList(String entityType) throws RepositoryException {
    LOG.debug("Retrieving entity list for type={}", entityType);
    GraphQuery query = titanGraph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, entityType);
    Iterator<Vertex> results = query.vertices().iterator();
    if (!results.hasNext()) {
      return Collections.emptyList();
    }

    ArrayList<String> entityList = new ArrayList<>();
    while (results.hasNext()) {
      Vertex vertex = results.next();
      entityList.add(vertex.<String>getProperty(Constants.GUID_PROPERTY_KEY));
    }

    return entityList;
  }