Search in sources :

Example 1 with EdgeSeed

use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.

the class EdgeSeedExtractorTest method shouldGetIdentifierFromEdge.

@Test
public void shouldGetIdentifierFromEdge() {
    // Given
    final EdgeSeedExtractor extractor = new EdgeSeedExtractor();
    final Edge edge = new Edge(TestGroups.EDGE, "source", "destination", true);
    // When
    final EdgeSeed seed = extractor.getObject(edge);
    // Then
    assertEquals("source", seed.getSource());
    assertEquals("destination", seed.getDestination());
    assertTrue(seed.isDirected());
}
Also used : EdgeSeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EdgeSeedExtractor) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 2 with EdgeSeed

use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.

the class GafferResultCacheExporter method get.

public CloseableIterable<?> get(final String key) throws OperationException {
    final GetEdges<EdgeSeed> getEdges = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed(jobId, key, true)).view(new View.Builder().edge("result", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("opAuths").execute(new AreIn(userOpAuths)).build()).build()).build()).build();
    final CloseableIterable<Edge> edges = resultCache.execute(getEdges, user);
    if (null == edges) {
        return new WrappedCloseableIterable<>(Collections.emptyList());
    }
    return new TransformJsonResult(edges, jsonSerialiser);
}
Also used : AreIn(uk.gov.gchq.gaffer.function.filter.AreIn) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 3 with EdgeSeed

use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testUndirectedEdgeSeedQueries.

private void testUndirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.UNDIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("B", edge.getDestination());
    }
    //We should have only 1000 returned the i-B edges that are undirected
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 4 with EdgeSeed

use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.

the class AccumuloSingleIDRetrieverTest method testDirectedEdgeSeedQueries.

private void testDirectedEdgeSeedQueries(final AccumuloStore store) throws AccumuloException, StoreException {
    setupGraph(store, numEntries);
    final User user = new User();
    // Create set to query for
    final Set<ElementSeed> ids = new HashSet<>();
    for (int i = 0; i < numEntries; i++) {
        ids.add(new EdgeSeed("" + i, "B", false));
        ids.add(new EdgeSeed("" + i, "C", true));
    }
    final View view = new View.Builder().edge(TestGroups.EDGE).build();
    AccumuloSingleIDRetriever retriever = null;
    final GetElements<ElementSeed, ?> operation = new GetElements<>(view, ids);
    operation.setIncludeEdges(IncludeEdgeType.DIRECTED);
    try {
        retriever = new AccumuloSingleIDRetriever(store, operation, user);
    } catch (IteratorSettingException e) {
        e.printStackTrace();
    }
    for (final Element element : retriever) {
        Edge edge = (Edge) element;
        assertEquals("C", edge.getDestination());
    }
    //Should find 1000 only A-C
    assertEquals(numEntries, Iterables.size(retriever));
}
Also used : User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) IteratorSettingException(uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet)

Example 5 with EdgeSeed

use of uk.gov.gchq.gaffer.operation.data.EdgeSeed in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetRelatedEntities.

@Test
public void shouldAddAndGetRelatedEntities() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the entities
    final OperationChain<CloseableIterable<SimpleEntityDataObject>> opChain = new OperationChain.Builder().first(new GetEntities.Builder<>().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Entity, SimpleEntityDataObject>().generator(new SimpleEntityGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEntityDataObject> results = graph.execute(opChain, new User());
    //check the results by converting our edges back into SimpleDataObjects
    if (!results.iterator().hasNext()) {
        fail("No results returned");
    } else {
        for (final SimpleEntityDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEntityDataObject> resultList = Lists.newArrayList(results);
        int index = 0;
        SimpleEntityDataObject obj = resultList.get(index++);
        assertEquals(1, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Red", obj.getProperties());
        obj = resultList.get(index);
        assertEquals(2, obj.getId());
        assertEquals(1, obj.getVisibility());
        assertEquals("Orange", obj.getProperties());
    }
    results.close();
}
Also used : SimpleEntityGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEntityGenerator) User(uk.gov.gchq.gaffer.user.User) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Aggregations

EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)31 Edge (uk.gov.gchq.gaffer.data.element.Edge)16 Test (org.junit.Test)14 Element (uk.gov.gchq.gaffer.data.element.Element)12 User (uk.gov.gchq.gaffer.user.User)11 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)9 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)8 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)8 Graph (uk.gov.gchq.gaffer.graph.Graph)7 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)6 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)6 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)5 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 HashSet (java.util.HashSet)4 Entity (uk.gov.gchq.gaffer.data.element.Entity)4 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)4 ArrayList (java.util.ArrayList)3 Iterator (java.util.Iterator)3