Search in sources :

Example 1 with GetWalks

use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.

the class IfScoreResolverTest method shouldGetScoreForNestedOperations.

@Test
public void shouldGetScoreForNestedOperations() {
    // Given
    final Map map = mock(Map.class);
    final Conditional conditional = mock(Conditional.class);
    given(conditional.getTransform()).willReturn(map);
    final GetWalks getWalks = mock(GetWalks.class);
    given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(new GetAdjacentIds(), new GetAdjacentIds())));
    final GetAllElements getAllElements = new GetAllElements();
    final If operation = new If.Builder<>().conditional(conditional).then(getWalks).otherwise(getAllElements).build();
    final LinkedHashMap<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(Map.class, 3);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(GetAllElements.class, 3);
    final IfScoreResolver resolver = new IfScoreResolver();
    final DefaultScoreResolver defaultResolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(operation, defaultResolver);
    // Then
    assertEquals(7, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ToMap(uk.gov.gchq.gaffer.operation.impl.output.ToMap) LinkedHashMap(java.util.LinkedHashMap) Map(uk.gov.gchq.gaffer.operation.impl.Map) If(uk.gov.gchq.gaffer.operation.impl.If) Test(org.junit.jupiter.api.Test)

Example 2 with GetWalks

use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.

the class DefaultScoreResolverTest method shouldGetScoreForNestedOperations.

@Test
public void shouldGetScoreForNestedOperations() {
    // Given
    final GetElements getElements = mock(GetElements.class);
    final GetWalks getWalks = mock(GetWalks.class);
    final GetAdjacentIds getAdjacentIds = mock(GetAdjacentIds.class);
    given(getWalks.getOperations()).willReturn(Collections.singletonList(new OperationChain<>(getAdjacentIds, getAdjacentIds)));
    final Limit limit = mock(Limit.class);
    final List<Operation> opList = Arrays.asList(getElements, getWalks, limit);
    final OperationChain opChain = mock(OperationChain.class);
    given(opChain.getOperations()).willReturn(opList);
    final Map<Class<? extends Operation>, Integer> opScores = new LinkedHashMap<>();
    opScores.put(Operation.class, 1);
    opScores.put(GetElements.class, 2);
    opScores.put(GetAdjacentIds.class, 2);
    opScores.put(Limit.class, 1);
    final DefaultScoreResolver resolver = new DefaultScoreResolver(opScores);
    // When
    final int score = resolver.getScore(opChain);
    // Then
    assertEquals(7, score);
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) LinkedHashMap(java.util.LinkedHashMap) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 3 with GetWalks

use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.

the class AddOperationsToChainTest method shouldAddAllOperationsToGetWalksOperation.

@Test
public void shouldAddAllOperationsToGetWalksOperation() throws SerialisationException {
    // Given
    final AddOperationsToChain hook = new AddOperationsToChain();
    final java.util.Map<String, List<Operation>> after = new HashMap<>();
    after.put(GetElements.class.getName(), Lists.newArrayList(new Limit()));
    hook.setAfter(after);
    hook.setEnd(Lists.newArrayList(new Limit()));
    final GetElements getElements = new GetElements();
    final Limit limit = new Limit();
    final OperationChain getWalksOperations = new OperationChain.Builder().first(getElements).build();
    final GetWalks getWalks = new GetWalks.Builder().operations(getWalksOperations).build();
    final OperationChain opChain = new OperationChain.Builder().first(getWalks).build();
    // When
    hook.preExecute(opChain, new Context(new User()));
    // Then
    final GetWalks expectedGetWalks = new GetWalks.Builder().operations(new OperationChain(getElements, limit)).build();
    final OperationChain expectedOpChain = new OperationChain.Builder().first(expectedGetWalks).then(limit).build();
    JsonAssert.assertEquals(JSONSerialiser.serialise(expectedOpChain), JSONSerialiser.serialise(opChain));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) LinkedList(java.util.LinkedList) List(java.util.List) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) Test(org.junit.jupiter.api.Test)

Example 4 with GetWalks

use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.

the class GetWalksHandlerTest method shouldHandleNullInput.

@Test
public void shouldHandleNullInput() throws Exception {
    // Given
    final GetElements getElements = new GetElements.Builder().view(new View.Builder().edge(TestGroups.EDGE).build()).build();
    final GetWalks operation = new GetWalks.Builder().operations(getElements).build();
    final GetWalksHandler handler = new GetWalksHandler();
    // When
    final Iterable<Walk> result = handler.doOperation(operation, null, null);
    // Then
    assertThat(result).isNull();
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 5 with GetWalks

use of uk.gov.gchq.gaffer.operation.impl.GetWalks in project Gaffer by gchq.

the class GetWalksIT method shouldGetPathsWithEntities.

@Test
public void shouldGetPathsWithEntities() throws Exception {
    // Given
    final GetElements getEntities = new GetElements.Builder().directedType(DirectedType.DIRECTED).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
    final GetElements getElements = new GetElements.Builder().directedType(DirectedType.DIRECTED).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).build();
    final GetWalks op = new GetWalks.Builder().input(seedA).operations(getElements, getElements, getEntities).build();
    // When
    final List<Walk> results = Lists.newArrayList(graph.execute(op, getUser()));
    // Then
    assertThat(getPaths(results)).isEqualTo("AED,ABC");
    results.forEach(r -> r.getEntities().forEach(l -> {
        assertThat(l).isNotEmpty();
    }));
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ExtractProperty(uk.gov.gchq.gaffer.data.element.function.ExtractProperty) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Edge(uk.gov.gchq.gaffer.data.element.Edge) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) StringConcat(uk.gov.gchq.koryphe.impl.binaryoperator.StringConcat) Exists(uk.gov.gchq.koryphe.impl.predicate.Exists) Predicate(java.util.function.Predicate) TestPropertyNames(uk.gov.gchq.gaffer.commonutil.TestPropertyNames) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) AgeOff(uk.gov.gchq.koryphe.impl.predicate.AgeOff) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Conditional(uk.gov.gchq.gaffer.operation.util.Conditional) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Limit(uk.gov.gchq.gaffer.operation.impl.Limit) HashMap(java.util.HashMap) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Lists(com.google.common.collect.Lists) While(uk.gov.gchq.gaffer.operation.impl.While) Map(uk.gov.gchq.gaffer.operation.impl.Map) Max(uk.gov.gchq.koryphe.impl.binaryoperator.Max) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Sum(uk.gov.gchq.koryphe.impl.binaryoperator.Sum) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) Walk(uk.gov.gchq.gaffer.data.graph.Walk) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) CollectionContains(uk.gov.gchq.koryphe.impl.predicate.CollectionContains) Test(org.junit.Test) Entity(uk.gov.gchq.gaffer.data.element.Entity) KorypheFunction(uk.gov.gchq.koryphe.function.KorypheFunction) IterableConcat(uk.gov.gchq.koryphe.impl.function.IterableConcat) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) ExtractWalkEntities(uk.gov.gchq.gaffer.data.graph.function.walk.ExtractWalkEntities) AbstractStoreIT(uk.gov.gchq.gaffer.integration.AbstractStoreIT) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) TestTypes(uk.gov.gchq.gaffer.store.TestTypes) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) GetWalks(uk.gov.gchq.gaffer.operation.impl.GetWalks) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) Builder(uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Aggregations

GetWalks (uk.gov.gchq.gaffer.operation.impl.GetWalks)31 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)27 Test (org.junit.Test)19 Walk (uk.gov.gchq.gaffer.data.graph.Walk)19 Builder (uk.gov.gchq.gaffer.operation.impl.GetWalks.Builder)19 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Test (org.junit.jupiter.api.Test)11 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)9 Conditional (uk.gov.gchq.gaffer.operation.util.Conditional)8 HashMap (java.util.HashMap)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 If (uk.gov.gchq.gaffer.operation.impl.If)5 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)5 List (java.util.List)4 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)4 Limit (uk.gov.gchq.gaffer.operation.impl.Limit)4 LinkedHashMap (java.util.LinkedHashMap)3 GraphConfig (uk.gov.gchq.gaffer.graph.GraphConfig)3 AddOperationsToChain (uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain)3