Search in sources :

Example 1 with AddOperationsToChain

use of uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain in project Gaffer by gchq.

the class GraphConfigTest method getTestObject.

@Override
protected GraphConfig getTestObject() {
    final String graphId = "graphId";
    final GraphLibrary library = new HashMapGraphLibrary();
    final View view = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).build();
    final GraphHook hook1 = new AddOperationsToChain();
    final GraphHook hook2 = new OperationChainLimiter();
    return new GraphConfig.Builder().graphId(graphId).library(library).description("testGraphConfig").addHook(hook1).addHook(hook2).view(view).build();
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChainLimiter(uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter)

Example 2 with AddOperationsToChain

use of uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain in project Gaffer by gchq.

the class GraphConfigTest method shouldDeserialisationJson.

@Test
public void shouldDeserialisationJson() throws IOException {
    // Given
    final GraphConfig config = JSONSerialiser.deserialise(StreamUtil.graphConfig(getClass()), GraphConfig.class);
    // Then
    assertEquals("graphId1", config.getGraphId());
    assertEquals(HashMapGraphLibrary.class, config.getLibrary().getClass());
    final List<GraphHook> graphHooks = config.getHooks();
    assertThat(graphHooks).hasSize(1);
    final AddOperationsToChain addOperationsToChain = (AddOperationsToChain) graphHooks.get(0);
    for (final Class op : new Class[] { ToSet.class, ToArray.class, ToList.class, ExportToSet.class }) {
        assertEquals(RESULT_LIMIT, (int) ((Limit) addOperationsToChain.getBefore().get(op.getName()).get(0)).getResultLimit());
    }
    for (final Class op : new Class[] { GetElements.class, GetAllElements.class, GetAdjacentIds.class }) {
        assertEquals(RESULT_LIMIT, (int) ((Limit) addOperationsToChain.getAfter().get(op.getName()).get(0)).getResultLimit());
    }
}
Also used : ToArray(uk.gov.gchq.gaffer.operation.impl.output.ToArray) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ToList(uk.gov.gchq.gaffer.operation.impl.output.ToList) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) ExportToSet(uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 3 with AddOperationsToChain

use of uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain in project Gaffer by gchq.

the class GetWalksIT method shouldGetPathsWithSimpleGraphHook_2.

@Test
public void shouldGetPathsWithSimpleGraphHook_2() throws Exception {
    // Given
    final AddOperationsToChain graphHook = new AddOperationsToChain();
    final java.util.Map<String, List<Operation>> graphHookConfig = new HashMap<>();
    graphHookConfig.put(GetElements.class.getName(), Lists.newArrayList(new Limit.Builder<>().resultLimit(1).build()));
    graphHook.setAfter(graphHookConfig);
    final GraphConfig config = new GraphConfig.Builder().addHook(graphHook).graphId("integrationTest").build();
    createGraph(config);
    addDefaultElements();
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(getPaths(results)).isEqualTo("ABC");
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) HashMap(java.util.HashMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) List(java.util.List) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) Test(org.junit.Test)

Example 4 with AddOperationsToChain

use of uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain in project Gaffer by gchq.

the class GetWalksIT method shouldGetPathsWithSimpleGraphHook_1.

@Test
public void shouldGetPathsWithSimpleGraphHook_1() throws Exception {
    // Given
    final AddOperationsToChain graphHook = new AddOperationsToChain();
    graphHook.setEnd(Lists.newArrayList(new Limit.Builder<>().resultLimit(1).build()));
    final GraphConfig config = new GraphConfig.Builder().addHook(graphHook).graphId("integrationTest").build();
    createGraph(config);
    addDefaultElements();
    final GetElements operation = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().properties(TestPropertyNames.COUNT).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(operation, operation).build();
    // When
    final Iterable<Walk> results = graph.execute(op, getUser());
    // Then
    assertThat(Lists.newArrayList(results)).hasSize(1);
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) Test(org.junit.Test)

Aggregations

AddOperationsToChain (uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)3 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)3 Test (org.junit.Test)2 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)2 Walk (uk.gov.gchq.gaffer.data.graph.Walk)2 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)2 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)2 GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)2 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (org.junit.jupiter.api.Test)1 OperationChainLimiter (uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter)1 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)1 ExportToSet (uk.gov.gchq.gaffer.operation.impl.export.set.ExportToSet)1 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)1 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)1 ToArray (uk.gov.gchq.gaffer.operation.impl.output.ToArray)1 ToList (uk.gov.gchq.gaffer.operation.impl.output.ToList)1