Search in sources :

Example 1 with SimpleEntityDataObject

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

the class ArrayListStoreTest method shouldAddAndGetEntitiesBySeed.

@Test
public void shouldAddAndGetEntitiesBySeed() 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 EntitySeed(1)).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());
    }
    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) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 2 with SimpleEntityDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject 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 3 with SimpleEntityDataObject

use of uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject 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)

Example 4 with SimpleEntityDataObject

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

the class ArrayListStoreTest method shouldAddAndGetEdgesThenEntities.

@Test
public void shouldAddAndGetEdgesThenEntities() 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 GetEdges.Builder<>().addSeed(new EntitySeed(1)).build()).then(new GenerateObjects.Builder<Edge, EntitySeed>().generator(new EntitySeedExtractor(IdentifierType.DESTINATION)).build()).then(new GetEntities.Builder().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);
        assertEquals(1, resultList.size());
        assertEquals(1, resultList.get(0).getId());
        assertEquals(1, resultList.get(0).getVisibility());
        assertEquals("Red", resultList.get(0).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) GetEntities(uk.gov.gchq.gaffer.operation.impl.get.GetEntities) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) EntitySeedExtractor(uk.gov.gchq.gaffer.operation.data.generator.EntitySeedExtractor) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject) Test(org.junit.Test)

Example 5 with SimpleEntityDataObject

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

the class SimpleEntityGenerator method getObject.

public SimpleEntityDataObject getObject(final Element element) {
    final Entity entity = (Entity) element;
    int id = (Integer) entity.getVertex();
    final Integer visibility = (Integer) entity.getProperty(TestPropertyNames.INT);
    final String properties = (String) entity.getProperty(TestPropertyNames.STRING);
    return new SimpleEntityDataObject(id, visibility, properties);
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) SimpleEntityDataObject(uk.gov.gchq.gaffer.arrayliststore.data.SimpleEntityDataObject)

Aggregations

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