Search in sources :

Example 1 with SimpleEdgeDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject in project Gaffer by gchq.

the class ArrayListStoreTest method getDomainObjects.

private ArrayList<Object> getDomainObjects() {
    ArrayList<Object> domainObjs = new ArrayList<>();
    domainObjs.add(new SimpleEntityDataObject(1, 1, "Red"));
    domainObjs.add(new SimpleEntityDataObject(2, 1, "Orange"));
    domainObjs.add(new SimpleEntityDataObject(3, 2, "Yellow"));
    domainObjs.add(new SimpleEntityDataObject(4, 2, "Green"));
    domainObjs.add(new SimpleEdgeDataObject(1, 2, 1, "121"));
    domainObjs.add(new SimpleEdgeDataObject(2, 3, 1, "231"));
    domainObjs.add(new SimpleEdgeDataObject(3, 4, 1, "342"));
    domainObjs.add(new SimpleEdgeDataObject(4, 1, 1, "142"));
    domainObjs.add(new SimpleEdgeDataObject(1, 3, 2, "132"));
    domainObjs.add(new SimpleEdgeDataObject(2, 4, 2, "242"));
    return domainObjs;
}
Also used : ArrayList(java.util.ArrayList) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject)

Example 2 with SimpleEdgeDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetRelatedEdges.

@Test
public void shouldAddAndGetRelatedEdges() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the edges
    final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder<>().addSeed(new EntitySeed(1)).addSeed(new EntitySeed(2)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEdgeDataObject> 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 SimpleEdgeDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
        assertEquals(3, resultList.size());
        int index = 0;
        SimpleEdgeDataObject obj = resultList.get(index++);
        assertEquals(1, obj.getLeft());
        assertEquals(2, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("121", obj.getProperties());
        obj = resultList.get(index++);
        assertEquals(2, obj.getLeft());
        assertEquals(3, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("231", obj.getProperties());
        obj = resultList.get(index);
        assertEquals(4, obj.getLeft());
        assertEquals(1, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("142", obj.getProperties());
    }
    results.close();
}
Also used : 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) SimpleEdgeGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) Test(org.junit.Test)

Example 3 with SimpleEdgeDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject in project Gaffer by gchq.

the class SimpleEdgeGenerator method getObject.

public SimpleEdgeDataObject getObject(final Element element) {
    final Edge edge = (Edge) element;
    int left = (Integer) edge.getDestination();
    int right = (Integer) edge.getSource();
    final Integer visibility = (Integer) edge.getProperty(TestPropertyNames.INT);
    final String properties = (String) edge.getProperty(TestPropertyNames.STRING);
    return new SimpleEdgeDataObject(left, right, visibility, properties);
}
Also used : Edge(uk.gov.gchq.gaffer.data.element.Edge) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject)

Example 4 with SimpleEdgeDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject in project Gaffer by gchq.

the class ArrayListStoreTest method shouldAddAndGetEdgesBySeed.

@Test
public void shouldAddAndGetEdgesBySeed() throws OperationException {
    final Graph graph = createGraph();
    addElementsToGraph(graph);
    //set up the operation to fetch the edges
    final OperationChain<CloseableIterable<SimpleEdgeDataObject>> opChain = new OperationChain.Builder().first(new GetEdges.Builder().addSeed(new EdgeSeed(2, 1, false)).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build()).then(new GenerateObjects.Builder<Edge, SimpleEdgeDataObject>().generator(new SimpleEdgeGenerator()).build()).build();
    //now do the hop
    final CloseableIterable<SimpleEdgeDataObject> 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 SimpleEdgeDataObject obj : results) {
            LOGGER.info(obj.toString());
        }
        final List<SimpleEdgeDataObject> resultList = Lists.newArrayList(results);
        assertEquals(1, resultList.size());
        int index = 0;
        SimpleEdgeDataObject obj = resultList.get(index);
        assertEquals(1, obj.getLeft());
        assertEquals(2, obj.getRight());
        assertEquals(1, obj.getVisibility());
        assertEquals("121", obj.getProperties());
    }
    results.close();
}
Also used : 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) SimpleEdgeGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator) 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) SimpleEdgeDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject) Test(org.junit.Test)

Aggregations

SimpleEdgeDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEdgeDataObject)4 Test (org.junit.Test)2 SimpleEdgeGenerator (uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleEdgeGenerator)2 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)2 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)2 Graph (uk.gov.gchq.gaffer.graph.Graph)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 User (uk.gov.gchq.gaffer.user.User)2 ArrayList (java.util.ArrayList)1 SimpleEntityDataObject (uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 GetEdges (uk.gov.gchq.gaffer.operation.impl.get.GetEdges)1