Search in sources :

Example 1 with EmptyClosableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable in project Gaffer by gchq.

the class GetWalksHandler method doOperation.

@Override
public Iterable<Walk> doOperation(final GetWalks getWalks, final Context context, final Store store) throws OperationException {
    // Check input
    if (null == getWalks.getInput()) {
        return null;
    }
    // Check there are some operations
    if (null == getWalks.getOperations()) {
        return new EmptyClosableIterable<>();
    }
    final Integer resultLimit = getWalks.getResultsLimit();
    final int hops = getWalks.getNumberOfGetEdgeOperations();
    final LimitedCloseableIterable limitedInputItr = new LimitedCloseableIterable<>(getWalks.getInput(), 0, resultLimit, false);
    final List<EntityId> originalInput = Lists.newArrayList(limitedInputItr);
    // Check hops and maxHops (if set)
    if (hops == 0) {
        return new EmptyClosableIterable<>();
    } else if (maxHops != null && hops > maxHops) {
        throw new OperationException("GetWalks operation contains " + hops + " hops. The maximum number of hops is: " + maxHops);
    }
    final AdjacencyMaps adjacencyMaps = prune && !getWalks.isIncludePartial() ? new PrunedAdjacencyMaps() : new SimpleAdjacencyMaps();
    final EntityMaps entityMaps = new SimpleEntityMaps();
    List<?> seeds = originalInput;
    // Execute the operations
    for (final OperationChain<Iterable<Element>> operation : getWalks.getOperations()) {
        if (isWhileOperation(operation)) {
            seeds = executeWhileOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
        } else {
            seeds = executeOperation(operation, seeds, resultLimit, context, store, hops, adjacencyMaps, entityMaps);
        }
    }
    // requested by the user.
    if (entityMaps.size() == adjacencyMaps.size()) {
        entityMaps.add(new EntityMap());
    }
    final GraphWindow graphWindow = new GraphWindow(adjacencyMaps, entityMaps);
    // Track/recombine the edge objects and convert to return type
    final Stream<Walk> walks = Streams.toStream(originalInput).flatMap(seed -> walk(seed.getVertex(), null, graphWindow, new LinkedList<>(), new LinkedList<>(), hops, getWalks.isIncludePartial()).stream());
    return applyConditionalFiltering(walks, getWalks, context, store);
}
Also used : Walk(uk.gov.gchq.gaffer.data.graph.Walk) LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) LimitedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) PrunedAdjacencyMaps(uk.gov.gchq.gaffer.data.graph.adjacency.PrunedAdjacencyMaps) SimpleEntityMaps(uk.gov.gchq.gaffer.data.graph.entity.SimpleEntityMaps) UnwrapEntityId(uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) GraphWindow(uk.gov.gchq.gaffer.data.graph.GraphWindow) SimpleEntityMaps(uk.gov.gchq.gaffer.data.graph.entity.SimpleEntityMaps) EntityMaps(uk.gov.gchq.gaffer.data.graph.entity.EntityMaps) EntityMap(uk.gov.gchq.gaffer.data.graph.entity.EntityMap) PrunedAdjacencyMaps(uk.gov.gchq.gaffer.data.graph.adjacency.PrunedAdjacencyMaps) AdjacencyMaps(uk.gov.gchq.gaffer.data.graph.adjacency.AdjacencyMaps) SimpleAdjacencyMaps(uk.gov.gchq.gaffer.data.graph.adjacency.SimpleAdjacencyMaps) SimpleAdjacencyMaps(uk.gov.gchq.gaffer.data.graph.adjacency.SimpleAdjacencyMaps) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 2 with EmptyClosableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable in project Gaffer by gchq.

the class GetElementsHandlerTest method testGetElementsWhenNoEdgeIdsProvided.

@Test
public void testGetElementsWhenNoEdgeIdsProvided() throws OperationException {
    // Given
    final Graph graph = GetAllElementsHandlerTest.getGraph();
    final AddElements addElements = new AddElements.Builder().input(getElements()).build();
    graph.execute(addElements, new User());
    // When
    final GetElements getElements = new GetElements.Builder().input(new EmptyClosableIterable<>()).build();
    final CloseableIterable<? extends Element> results = graph.execute(getElements, new User());
    // Then
    final Set<Element> resultsSet = new HashSet<>();
    Streams.toStream(results).forEach(resultsSet::add);
    assertEquals(Collections.emptySet(), resultsSet);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Graph(uk.gov.gchq.gaffer.graph.Graph) User(uk.gov.gchq.gaffer.user.User) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with EmptyClosableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable in project Gaffer by gchq.

the class AbstractLoaderIT method shouldReturnEmptyIteratorIfNoSeedsProvidedForGetElements.

@Test
public void shouldReturnEmptyIteratorIfNoSeedsProvidedForGetElements() throws Exception {
    // Then
    final GetElements op = new GetElements.Builder().input(new EmptyClosableIterable<>()).build();
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    assertThat(results.iterator().hasNext()).isFalse();
}
Also used : EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.Test)

Example 4 with EmptyClosableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable in project Gaffer by gchq.

the class GetElementsIT method shouldReturnEmptyIteratorIfNoSeedsProvidedForGetElementsBySeed.

@Test
public void shouldReturnEmptyIteratorIfNoSeedsProvidedForGetElementsBySeed() throws Exception {
    // Given
    final GetElements op = new GetElements.Builder().input(new EmptyClosableIterable<>()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    assertThat(results.iterator().hasNext()).isFalse();
}
Also used : EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.Test)

Example 5 with EmptyClosableIterable

use of uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable in project Gaffer by gchq.

the class GetElementsIT method shouldReturnEmptyIteratorIfNoSeedsProvidedForGetRelatedElements.

@Test
public void shouldReturnEmptyIteratorIfNoSeedsProvidedForGetRelatedElements() throws Exception {
    // Given
    final GetElements op = new GetElements.Builder().input(new EmptyClosableIterable<>()).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    assertThat(results.iterator().hasNext()).isFalse();
}
Also used : EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.Test)

Aggregations

EmptyClosableIterable (uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable)8 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)5 Test (org.junit.jupiter.api.Test)4 Element (uk.gov.gchq.gaffer.data.element.Element)4 Graph (uk.gov.gchq.gaffer.graph.Graph)4 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)4 Test (org.junit.Test)3 HashSet (java.util.HashSet)2 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 User (uk.gov.gchq.gaffer.user.User)2 IsEqual (uk.gov.gchq.koryphe.impl.predicate.IsEqual)2 LimitedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.LimitedCloseableIterable)1 UnwrapEntityId (uk.gov.gchq.gaffer.data.element.function.UnwrapEntityId)1 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)1 Builder (uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder)1 GraphWindow (uk.gov.gchq.gaffer.data.graph.GraphWindow)1 Walk (uk.gov.gchq.gaffer.data.graph.Walk)1 AdjacencyMaps (uk.gov.gchq.gaffer.data.graph.adjacency.AdjacencyMaps)1 PrunedAdjacencyMaps (uk.gov.gchq.gaffer.data.graph.adjacency.PrunedAdjacencyMaps)1