public String search(Graph graph, Authorizations authorizations) { Query query = graph.query(authorizations).limit(1); List<Vertex> vertices = Lists.newArrayList(query.vertices()); if (vertices.size() == 0) { throw new VisalloException("query returned no vertices"); } else if (vertices.size() > 1) { throw new VisalloException("query returned more than one vertex"); } return vertices.get(0).getId(); }
private Vertex findExistingVertexWithHash(String hash, Authorizations authorizations) { Iterator<Vertex> existingVertices = this.graph.query(authorizations) .has(VisalloProperties.CONTENT_HASH.getPropertyName(), hash) .vertices() .iterator(); if (existingVertices.hasNext()) { return existingVertices.next(); } return null; }
private StatisticsResult queryGraphQueryWithStatisticsAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); StatisticsAggregation agg = new StatisticsAggregation("stats", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", StatisticsAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("stats", StatisticsResult.class); }
private CardinalityResult queryGraphQueryWithCardinalityAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); CardinalityAggregation agg = new CardinalityAggregation("card", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", CardinalityAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("card", CardinalityResult.class); }
private CardinalityResult queryGraphQueryWithCardinalityAggregation(String propertyName, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); CardinalityAggregation agg = new CardinalityAggregation("card", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", CardinalityAggregation.class.getName()); return null; } q.addAggregation(agg); return q.vertices().getAggregationResult("card", CardinalityResult.class); }
@Override public Iterable<Vertex> getVertices(final String key, final Object value) { final Authorizations authorizations = getAuthorizationsProvider().getAuthorizations(); return new ConvertingIterable<org.vertexium.Vertex, Vertex>(getGraph().query(authorizations).has(key, Compare.EQUAL, value).vertices(getFetchHints())) { @Override protected Vertex convert(org.vertexium.Vertex vertex) { return VertexiumBlueprintsVertex.create(VertexiumBlueprintsGraph.this, vertex, authorizations); } }; }
private Map<Object, Long> queryGraphQueryWithTermsAggregation(String queryString, String propertyName, ElementType elementType, Authorizations authorizations) { Query q = (queryString == null ? graph.query(authorizations) : graph.query(queryString, authorizations)).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", agg.getClass().getName()); return null; } q.addAggregation(agg); QueryResultsIterable<? extends Element> elements = elementType == ElementType.VERTEX ? q.vertices() : q.edges(); TermsResult aggregationResult = elements.getAggregationResult("terms-count", TermsResult.class); return termsBucketToMap(aggregationResult.getBuckets()); }
private Map<Object, Long> queryGraphQueryWithTermsAggregation(String queryString, String propertyName, ElementType elementType, Authorizations authorizations) { Query q = (queryString == null ? graph.query(authorizations) : graph.query(queryString, authorizations)).limit(0); TermsAggregation agg = new TermsAggregation("terms-count", propertyName); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", agg.getClass().getName()); return null; } q.addAggregation(agg); QueryResultsIterable<? extends Element> elements = elementType == ElementType.VERTEX ? q.vertices() : q.edges(); TermsResult aggregationResult = elements.getAggregationResult("terms-count", TermsResult.class); return termsBucketToMap(aggregationResult.getBuckets()); }
private Map<String, Long> queryGraphQueryWithGeohashAggregation(String propertyName, int precision, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); GeohashAggregation agg = new GeohashAggregation("geo-count", propertyName, precision); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", GeohashAggregation.class.getName()); return null; } q.addAggregation(agg); return geoHashBucketToMap(q.vertices().getAggregationResult("geo-count", GeohashResult.class).getBuckets()); }
private Map<String, Long> queryGraphQueryWithGeohashAggregation(String propertyName, int precision, Authorizations authorizations) { Query q = graph.query(authorizations).limit(0); GeohashAggregation agg = new GeohashAggregation("geo-count", propertyName, precision); if (!q.isAggregationSupported(agg)) { LOGGER.warn("%s unsupported", GeohashAggregation.class.getName()); return null; } q.addAggregation(agg); return geoHashBucketToMap(q.vertices().getAggregationResult("geo-count", GeohashResult.class).getBuckets()); }
@Override public User findByPasswordResetToken(String token) { QueryResultsIterable<Vertex> userVertices = graph.query(authorizations) .has(UserVisalloProperties.PASSWORD_RESET_TOKEN.getPropertyName(), token) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), userConceptId) .vertices(); Vertex user = singleOrDefault(userVertices, null); return createFromVertex(user); }
@Test public void testGraphQueryVertexHasWithSecurityCantSeeProperty() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("age", 25, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A) .has("age", Compare.EQUAL, 25) .vertices(); Assert.assertEquals(0, count(vertices)); }
@Override public Iterable<Relationship> getRelationshipsByIRI(List<String> relationshipIRIs, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_RELATIONSHIP) .has(OntologyProperties.ONTOLOGY_TITLE.getPropertyName(), Contains.IN, relationshipIRIs) .vertices(); return transformRelationships(vertices, workspaceId); }
@Override protected List<Concept> findLoadedConceptsByIntent(String intent, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_CONCEPT) .has(OntologyProperties.INTENT.getPropertyName(), intent) .vertices(); return transformConcepts(vertices, workspaceId); }
@Override public Iterable<OntologyProperty> getPropertiesByIRI(List<String> propertyIRIs, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_PROPERTY) .has(OntologyProperties.ONTOLOGY_TITLE.getPropertyName(), Contains.IN, propertyIRIs) .vertices(); return transformProperties(vertices, workspaceId); }
@Override public List<OntologyProperty> getPropertiesByIntent(String intent, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_PROPERTY) .has(OntologyProperties.INTENT.getPropertyName(), intent) .vertices(); return transformProperties(vertices, workspaceId); }
@Override public Iterable<Concept> getConceptsByIRI(List<String> conceptIRIs, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_CONCEPT) .has(OntologyProperties.ONTOLOGY_TITLE.getPropertyName(), Contains.IN, conceptIRIs) .vertices(); return transformConcepts(vertices, workspaceId); }
@Override protected List<Relationship> findLoadedRelationshipsByIntent(String intent, String workspaceId) { QueryResultsIterable<Vertex> vertices = getGraph().query(getAuthorizations(workspaceId)) .has(VisalloProperties.CONCEPT_TYPE.getPropertyName(), OntologyRepository.TYPE_RELATIONSHIP) .has(OntologyProperties.INTENT.getPropertyName(), intent) .vertices(); return transformRelationships(vertices, workspaceId); }
@Test public void testGraphQueryVertexHasWithSecurityCantSeeProperty() { graph.prepareVertex("v1", VISIBILITY_A) .setProperty("age", 25, VISIBILITY_B) .save(AUTHORIZATIONS_A_AND_B); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A) .has("age", Compare.EQUAL, 25) .vertices(); Assert.assertEquals(0, count(vertices)); }
@Test public void testAddVertexWithoutIndexing() { assumeTrue("add vertex without indexing not supported", !isDefaultSearchIndex()); graph.prepareVertex("v1", VISIBILITY_A) .setProperty("prop1", "value1", VISIBILITY_A) .setIndexHint(IndexHint.DO_NOT_INDEX) .save(AUTHORIZATIONS_A); graph.flush(); Iterable<Vertex> vertices = graph.query(AUTHORIZATIONS_A_AND_B) .has("prop1", "value1") .vertices(); assertVertexIds(vertices); }