Search in sources :

Example 76 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class AbstractOperationTest method shouldCopyFieldsFromGivenOperationWhenConstructing.

@Test
public void shouldCopyFieldsFromGivenOperationWhenConstructing() {
    // Given
    final Operation<String, ?> operationToCopy = mock(Operation.class);
    final View view = mock(View.class);
    final String input = "input value";
    given(operationToCopy.getView()).willReturn(view);
    given(operationToCopy.getInput()).willReturn(input);
    // When
    final Operation<String, String> operation = new OperationImpl<>(operationToCopy);
    // Then
    assertSame(view, operation.getView());
    assertSame(input, operation.getInput());
}
Also used : OperationImpl(uk.gov.gchq.gaffer.operation.impl.OperationImpl) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 77 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class Graph method updateOperationChainView.

private <OUTPUT> void updateOperationChainView(final OperationChain<OUTPUT> operationChain) {
    for (final Operation operation : operationChain.getOperations()) {
        final View opView;
        if (null == operation.getView()) {
            opView = view;
        } else if (!operation.getView().hasGroups()) {
            opView = new View.Builder().merge(view).merge(operation.getView()).build();
        } else {
            opView = operation.getView();
        }
        opView.expandGlobalDefinitions();
        operation.setView(opView);
    }
}
Also used : Operation(uk.gov.gchq.gaffer.operation.Operation) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 78 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View in project Gaffer by gchq.

the class GraphTest method shouldExposeGetTraitsMethod.

@Test
public void shouldExposeGetTraitsMethod() throws OperationException {
    // Given
    final Store store = mock(Store.class);
    final View view = mock(View.class);
    final Graph graph = new Graph.Builder().store(store).view(view).build();
    // When
    final Set<StoreTrait> storeTraits = new HashSet<>(Arrays.asList(StoreTrait.STORE_AGGREGATION, StoreTrait.TRANSFORMATION));
    given(store.getTraits()).willReturn(storeTraits);
    final Collection<StoreTrait> returnedTraits = graph.getStoreTraits();
    // Then
    assertEquals(returnedTraits, storeTraits);
}
Also used : StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Store(uk.gov.gchq.gaffer.store.Store) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 79 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View 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 80 with View

use of uk.gov.gchq.gaffer.data.elementdefinition.view.View 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

View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)107 Test (org.junit.Test)70 Element (uk.gov.gchq.gaffer.data.element.Element)42 User (uk.gov.gchq.gaffer.user.User)38 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)32 HashSet (java.util.HashSet)29 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)28 Graph (uk.gov.gchq.gaffer.graph.Graph)20 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)19 ArrayList (java.util.ArrayList)16 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)14 Edge (uk.gov.gchq.gaffer.data.element.Edge)13 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)13 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)12 IsLessThan (uk.gov.gchq.gaffer.function.filter.IsLessThan)11 SQLContext (org.apache.spark.sql.SQLContext)10 ExampleTransformFunction (uk.gov.gchq.gaffer.function.ExampleTransformFunction)9 IsMoreThan (uk.gov.gchq.gaffer.function.filter.IsMoreThan)9 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8