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);
}
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);
}
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));
}
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);
}
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));
}
Aggregations