Search in sources :

Example 6 with DirectedType

use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.

the class ByteEntityIteratorSettingsFactory method getElementPropertyRangeQueryFilter.

@Override
public IteratorSetting getElementPropertyRangeQueryFilter(final GraphFilters operation) {
    final boolean includeEntities = operation.getView().hasEntities();
    final boolean includeEdges = operation.getView().hasEdges();
    final DirectedType directedType = operation.getDirectedType();
    final SeededGraphFilters.IncludeIncomingOutgoingType inOutType;
    if (operation instanceof SeededGraphFilters) {
        inOutType = ((SeededGraphFilters) operation).getIncludeIncomingOutGoing();
    } else {
        inOutType = SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING;
    }
    final boolean deduplicateUndirectedEdges = operation instanceof GetAllElements;
    if (includeEdges && DirectedType.isEither(directedType) && (null == inOutType || inOutType == SeededGraphFilters.IncludeIncomingOutgoingType.EITHER) && includeEntities && !deduplicateUndirectedEdges) {
        LOGGER.debug("Returning null from getElementPropertyRangeQueryFilter (" + "inOutType = {}, includeEdges = {}, " + "directedType = {}, deduplicateUndirectedEdges = {})", inOutType, includeEdges, directedType, deduplicateUndirectedEdges);
        return null;
    }
    final IteratorSetting is = new IteratorSettingBuilder(AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_NAME, RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR).all().includeIncomingOutgoing(inOutType).includeEdges(includeEdges).directedType(directedType).includeEntities(includeEntities).deduplicateUndirectedEdges(deduplicateUndirectedEdges).build();
    LOGGER.debug("Creating IteratorSetting for iterator class {} with priority = {}, " + " includeIncomingOutgoing = {}, directedType = {}," + " includeEdges = {}, includeEntities = {}, deduplicateUndirectedEdges = {}", RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR, AccumuloStoreConstants.RANGE_ELEMENT_PROPERTY_FILTER_ITERATOR_PRIORITY, inOutType, directedType, includeEdges, includeEntities, deduplicateUndirectedEdges);
    return is;
}
Also used : IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeededGraphFilters(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters) IteratorSettingBuilder(uk.gov.gchq.gaffer.accumulostore.utils.IteratorSettingBuilder)

Example 7 with DirectedType

use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.

the class GetElementsHandlerTest method testGetElementsDirectedTypeOption.

@Test
public void testGetElementsDirectedTypeOption() throws OperationException {
    // Given
    final Graph graph = GetAllElementsHandlerTest.getGraph();
    final AddElements addElements = new AddElements.Builder().input(getElements()).build();
    graph.execute(addElements, new User());
    // When directedType is EITHER
    GetElements getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.EITHER).build();
    CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
    // Then
    final Set<Element> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    final Set<Element> expectedResults = new HashSet<>();
    getElements().stream().filter(element -> {
        if (element instanceof Entity) {
            final Entity entity = (Entity) element;
            return entity.getVertex().equals("A") || entity.getVertex().equals("X");
        } else {
            final Edge edge = (Edge) element;
            return edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X");
        }
    }).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When view has no edges
    getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
    results = graph.execute(getElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> {
        if (element instanceof Entity) {
            final Entity entity = (Entity) element;
            return entity.getVertex().equals("A") || entity.getVertex().equals("X");
        } else {
            return false;
        }
    }).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When directedType is DIRECTED
    getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.DIRECTED).build();
    results = graph.execute(getElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> {
        if (element instanceof Entity) {
            final Entity entity = (Entity) element;
            return entity.getVertex().equals("A") || entity.getVertex().equals("X");
        } else {
            final Edge edge = (Edge) element;
            return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && edge.isDirected();
        }
    }).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When directedType is UNDIRECTED
    getElements = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("X")).directedType(DirectedType.UNDIRECTED).build();
    results = graph.execute(getElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> {
        if (element instanceof Entity) {
            final Entity entity = (Entity) element;
            return entity.getVertex().equals("A") || entity.getVertex().equals("X");
        } else {
            final Edge edge = (Edge) element;
            return (edge.getSource().equals("A") || edge.getDestination().equals("A") || edge.getSource().equals("X") || edge.getDestination().equals("X")) && !edge.isDirected();
        }
    }).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) SeedMatchingType(uk.gov.gchq.gaffer.operation.SeedMatching.SeedMatchingType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) KorypheFunction(uk.gov.gchq.koryphe.function.KorypheFunction) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) Collections(java.util.Collections) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 8 with DirectedType

use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.

the class GetAllElementsHandlerTest method testGetAllElementsDirectedTypeOption.

@Test
public void testGetAllElementsDirectedTypeOption() throws OperationException {
    // Given
    final Graph graph = GetAllElementsHandlerTest.getGraph();
    final AddElements addElements = new AddElements.Builder().input(getElements()).build();
    graph.execute(addElements, new User());
    // When directedType is ALL
    GetAllElements getAllElements = new GetAllElements.Builder().directedType(DirectedType.EITHER).build();
    CloseableIterable<? extends Element> results = graph.execute(getAllElements, new User());
    // Then
    final Set<Element> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    final Set<Element> expectedResults = new HashSet<>();
    getElements().forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When view has no edges
    getAllElements = new GetAllElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).build()).build();
    results = graph.execute(getAllElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> element instanceof Entity).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When directedType is DIRECTED
    getAllElements = new GetAllElements.Builder().directedType(DirectedType.DIRECTED).build();
    results = graph.execute(getAllElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> element instanceof Entity || ((Edge) element).isDirected()).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
    // When directedType is UNDIRECTED
    getAllElements = new GetAllElements.Builder().directedType(DirectedType.UNDIRECTED).build();
    results = graph.execute(getAllElements, new User());
    // Then
    resultsSet.clear();
    Streams.toStream(results).forEach(resultsSet::add);
    expectedResults.clear();
    getElements().stream().filter(element -> element instanceof Entity || !((Edge) element).isDirected()).forEach(expectedResults::add);
    assertEquals(expectedResults, resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) IntStream(java.util.stream.IntStream) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) HashMap(java.util.HashMap) GraphConfig(uk.gov.gchq.gaffer.graph.GraphConfig) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Graph(uk.gov.gchq.gaffer.graph.Graph) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Map(java.util.Map) Edge(uk.gov.gchq.gaffer.data.element.Edge) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) MapStoreProperties(uk.gov.gchq.gaffer.mapstore.MapStoreProperties) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) Streams(uk.gov.gchq.gaffer.commonutil.stream.Streams) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Edge(uk.gov.gchq.gaffer.data.element.Edge) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 9 with DirectedType

use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.

the class AbstractLoaderIT method getAllElements.

private void getAllElements() throws Exception {
    for (final boolean includeEntities : Arrays.asList(true, false)) {
        for (final boolean includeEdges : Arrays.asList(true, false)) {
            if (!includeEntities && !includeEdges) {
                // Cannot query for nothing!
                continue;
            }
            for (final DirectedType directedType : DirectedType.values()) {
                try {
                    final View.Builder viewBuilder = new View.Builder();
                    if (includeEntities) {
                        viewBuilder.entity(TestGroups.ENTITY);
                    }
                    if (includeEdges) {
                        viewBuilder.edge(TestGroups.EDGE);
                    }
                    getAllElements(includeEntities, includeEdges, directedType, viewBuilder.build());
                } catch (final AssertionError e) {
                    throw new AssertionError("GetAllElements failed with parameters: includeEntities=" + includeEntities + ", includeEdges=" + includeEdges + ", directedType=" + directedType.name(), e);
                }
            }
        }
    }
}
Also used : Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View)

Example 10 with DirectedType

use of uk.gov.gchq.gaffer.data.element.id.DirectedType in project Gaffer by gchq.

the class AbstractLoaderIT method getAllElements.

private void getAllElements(final boolean includeEntities, final boolean includeEdges, final DirectedType directedType, final View view) throws Exception {
    // Given
    List<Element> expectedElements = new ArrayList<>();
    if (includeEntities) {
        expectedElements.addAll(getQuerySummarisedEntities(view));
    }
    if (includeEdges) {
        for (final Edge edge : getQuerySummarisedEdges(view)) {
            if (DirectedType.EITHER == directedType || (edge.isDirected() && DirectedType.DIRECTED == directedType) || (!edge.isDirected() && DirectedType.UNDIRECTED == directedType)) {
                expectedElements.add(edge);
            }
        }
    }
    if (!user.getDataAuths().isEmpty()) {
        final String dataAuths = user.getDataAuths().stream().collect(Collectors.joining(","));
        final List<Element> nonVisibleElements = expectedElements.stream().filter(e -> {
            final String visibility = (String) e.getProperties().get(TestPropertyNames.VISIBILITY);
            if (null != visibility) {
                return !dataAuths.contains(visibility);
            } else {
                return false;
            }
        }).collect(toList());
        expectedElements.removeAll(nonVisibleElements);
    }
    getAllElements(expectedElements, directedType, view);
}
Also used : Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) JsonUtil(uk.gov.gchq.gaffer.commonutil.JsonUtil) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Lists(com.google.common.collect.Lists) ElementUtil.assertElementEquals(uk.gov.gchq.gaffer.data.util.ElementUtil.assertElementEquals) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) Edge(uk.gov.gchq.gaffer.data.element.Edge) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) TestPropertyNames(uk.gov.gchq.gaffer.commonutil.TestPropertyNames) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Test(org.junit.Test) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) AbstractStoreIT(uk.gov.gchq.gaffer.integration.AbstractStoreIT) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement) VisibilityUser(uk.gov.gchq.gaffer.integration.VisibilityUser) Consumer(java.util.function.Consumer) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) 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) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Aggregations

DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)16 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)7 IncludeIncomingOutgoingType (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType)7 ArrayList (java.util.ArrayList)6 Edge (uk.gov.gchq.gaffer.data.element.Edge)5 Entity (uk.gov.gchq.gaffer.data.element.Entity)5 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 SeededGraphFilters (uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 Test (org.junit.Test)4 TestGroups (uk.gov.gchq.gaffer.commonutil.TestGroups)4 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)4 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)4 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)4 Collectors (java.util.stream.Collectors)3