Search in sources :

Example 1 with WrappedCloseableIterable

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

the class GetGafferResultCacheExportHandlerTest method shouldHandleOperationByDelegatingToAnExistingExporter.

@Test
public void shouldHandleOperationByDelegatingToAnExistingExporter() throws OperationException {
    // Given
    final GetGafferResultCacheExport export = new GetGafferResultCacheExport.Builder().key("key").build();
    final Context context = new Context();
    final Store store = mock(Store.class);
    final JSONSerialiser jsonSerialiser = mock(JSONSerialiser.class);
    final Long timeToLive = 10000L;
    final String visibility = "visibility value";
    final GafferResultCacheExporter exporter = mock(GafferResultCacheExporter.class);
    final CloseableIterable results = new WrappedCloseableIterable<>(Arrays.asList(1, 2, 3));
    given(exporter.get("key")).willReturn(results);
    context.addExporter(exporter);
    final GetGafferResultCacheExportHandler handler = new GetGafferResultCacheExportHandler();
    handler.setStorePropertiesPath(StreamUtil.STORE_PROPERTIES);
    handler.setJsonSerialiser(jsonSerialiser);
    handler.setTimeToLive(timeToLive);
    handler.setVisibility(visibility);
    // When
    final Object handlerResult = handler.doOperation(export, context, store);
    // Then
    verify(exporter).get("key");
    assertSame(results, handlerResult);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GetGafferResultCacheExport(uk.gov.gchq.gaffer.operation.impl.export.resultcache.GetGafferResultCacheExport) GafferResultCacheExporter(uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) Store(uk.gov.gchq.gaffer.store.Store) Test(org.junit.Test)

Example 2 with WrappedCloseableIterable

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

the class GafferResultCacheExporter method get.

public CloseableIterable<?> get(final String key) throws OperationException {
    final GetEdges<EdgeSeed> getEdges = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed(jobId, key, true)).view(new View.Builder().edge("result", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("opAuths").execute(new AreIn(userOpAuths)).build()).build()).build()).build();
    final CloseableIterable<Edge> edges = resultCache.execute(getEdges, user);
    if (null == edges) {
        return new WrappedCloseableIterable<>(Collections.emptyList());
    }
    return new TransformJsonResult(edges, jsonSerialiser);
}
Also used : AreIn(uk.gov.gchq.gaffer.function.filter.AreIn) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) GetEdges(uk.gov.gchq.gaffer.operation.impl.get.GetEdges) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 3 with WrappedCloseableIterable

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

the class CountGroupsHandlerTest method getElements.

private CloseableIterable<Element> getElements() {
    final Entity entity1 = mock(Entity.class);
    final Entity entity2 = mock(Entity.class);
    final Entity entity3 = mock(Entity.class);
    final Entity entity4 = mock(Entity.class);
    final Edge edge1 = mock(Edge.class);
    final Edge edge2 = mock(Edge.class);
    final Edge edge3 = mock(Edge.class);
    final Edge edge4 = mock(Edge.class);
    given(entity1.getGroup()).willReturn(GROUP1);
    given(entity2.getGroup()).willReturn(GROUP2);
    given(entity3.getGroup()).willReturn(GROUP1);
    given(entity4.getGroup()).willReturn(GROUP1);
    given(edge1.getGroup()).willReturn(GROUP1);
    given(edge2.getGroup()).willReturn(GROUP2);
    given(edge3.getGroup()).willReturn(GROUP2);
    given(edge4.getGroup()).willReturn(GROUP2);
    return new WrappedCloseableIterable<>(Arrays.asList(entity1, entity2, entity3, entity4, edge1, edge2, edge3, edge4));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 4 with WrappedCloseableIterable

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

the class NamedOperationJCSCache method getAllNamedOperations.

/**
     * Gets all the keys from the cache and iterates through each ExtendedNamedOperation stored in the cache. Assuming
     * the user has read permission (therefore can execute the NamedOperation) it either adds a NamedOperation or
     * ExtendedNamedOperation to a set, depending on the simple flag which would ordinarily be set to true.
     *
     * @param user   The user making the request
     * @param simple flag determining whether to return a set of NamedOperations with a basic name and description or
     *               the full ExtendedNamedOperation with details of the opChain, and access controls
     * @return a set of NamedOperations
     */
@Override
public CloseableIterable<NamedOperation> getAllNamedOperations(final User user, final boolean simple) {
    Set keys = getCache().getGroupKeys(CACHE_GROUP);
    Set<NamedOperation> executables = new HashSet<>();
    for (final Object key : keys) {
        try {
            ExtendedNamedOperation op = getFromCache((String) key);
            if (op.hasReadAccess(user)) {
                if (simple) {
                    executables.add(op.getBasic());
                } else {
                    executables.add(op);
                }
            }
        } catch (CacheOperationFailedException e) {
            LOGGER.error(e.getMessage(), e);
        }
    }
    return new WrappedCloseableIterable<>(executables);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException) ExtendedNamedOperation(uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) HashSet(java.util.HashSet)

Example 5 with WrappedCloseableIterable

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

the class DeduplicateHandlerTest method shouldDeduplicateResults.

@Test
public void shouldDeduplicateResults() throws OperationException {
    // Given
    final CloseableIterable<Integer> originalResults = new WrappedCloseableIterable<>(Arrays.asList(1, 2, 2, 2, 3, 4, 1, 5, 6, 7, 8, 5, 9, 1, 6, 8, 2, 10));
    final DeduplicateHandler<Integer> handler = new DeduplicateHandler<>();
    final Deduplicate<Integer> operation = mock(Deduplicate.class);
    given(operation.getInput()).willReturn(originalResults);
    // When
    final Iterable<Integer> results = handler.doOperation(operation, new Context(), null);
    // Then
    assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), Lists.newArrayList(results));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Test(org.junit.Test)

Aggregations

WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)7 Test (org.junit.Test)4 Context (uk.gov.gchq.gaffer.store.Context)4 Edge (uk.gov.gchq.gaffer.data.element.Edge)2 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)2 Store (uk.gov.gchq.gaffer.store.Store)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 Entity (uk.gov.gchq.gaffer.data.element.Entity)1 AreIn (uk.gov.gchq.gaffer.function.filter.AreIn)1 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)1 JSONSerialiser (uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser)1 ExtendedNamedOperation (uk.gov.gchq.gaffer.named.operation.ExtendedNamedOperation)1 NamedOperation (uk.gov.gchq.gaffer.named.operation.NamedOperation)1 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.CacheOperationFailedException)1 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)1 GafferResultCacheExporter (uk.gov.gchq.gaffer.operation.export.resultcache.GafferResultCacheExporter)1 Validate (uk.gov.gchq.gaffer.operation.impl.Validate)1