use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnTrueWhenViewValidateWithValidElement.
@Test
public void shouldReturnTrueWhenViewValidateWithValidElement() {
// Given
final View view = mock(View.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final ViewElementDefinition elementDef = mock(ViewElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final ElementValidator validator = new ElementValidator(view);
given(elm.getGroup()).willReturn(group);
given(view.getElement(group)).willReturn(elementDef);
given(elementDef.getPreAggregationFilter()).willReturn(filter);
given(filter.test(elm)).willReturn(true);
// When
final boolean isValid = validator.validate(elm);
// Then
assertTrue(isValid);
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class FederatedOperationHandlerTest method shouldPassGlobalsOnToSubstores.
@Test
public final void shouldPassGlobalsOnToSubstores() throws Exception {
// Given
final ElementFilter filter = mock(ElementFilter.class);
final GlobalViewElementDefinition globalEntitiesAggregate = new GlobalViewElementDefinition.Builder().postAggregationFilter(filter).build();
final View view = new View.Builder().globalEntities(globalEntitiesAggregate).build();
final Operation operation = new GetElements.Builder().input("input").view(view).build();
final OperationChain op = new OperationChain.Builder().first(operation).build();
Schema unusedSchema = new Schema.Builder().build();
final Schema concreteSchema = new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition.Builder().vertex(TestTypes.ID_STRING).aggregate(false).build()).entity(TestGroups.ENTITY + "2", new SchemaEntityDefinition.Builder().vertex(TestTypes.ID_STRING).aggregate(false).build()).type(TestTypes.ID_STRING, new TypeDefinition.Builder().clazz(String.class).build()).build();
StoreProperties storeProperties = new StoreProperties();
Store mockStore1 = getMockStore(unusedSchema, storeProperties);
Store mockStore2 = getMockStore(concreteSchema, storeProperties);
Graph graph1 = getGraphWithMockStore(mockStore1);
Graph graph2 = getGraphWithMockStore(mockStore2);
FederatedStore mockStore = mock(FederatedStore.class);
LinkedHashSet<Graph> linkedGraphs = Sets.newLinkedHashSet();
linkedGraphs.add(graph1);
linkedGraphs.add(graph2);
when(mockStore.getGraphs(user, null, op)).thenReturn(linkedGraphs);
final ArgumentCaptor<OperationChain> capturedOperation = ArgumentCaptor.forClass(OperationChain.class);
// When
new FederatedOperationHandler().doOperation(op, context, mockStore);
verify(mockStore2).execute(capturedOperation.capture(), any(Context.class));
assertEquals(1, capturedOperation.getAllValues().size());
final OperationChain transformedOpChain = capturedOperation.getAllValues().get(0);
assertEquals(1, transformedOpChain.getOperations().size());
assertEquals(GetElements.class, transformedOpChain.getOperations().get(0).getClass());
final View mergedView = ((GetElements) transformedOpChain.getOperations().get(0)).getView();
assertTrue(mergedView.getGlobalEntities() == null);
assertEquals(2, mergedView.getEntities().size());
assertTrue(mergedView.getEntities().entrySet().stream().allMatch(x -> x.getValue().getPostAggregationFilter() != null));
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class RetrieveElementsFromFile method call.
@Override
public OperationException call() throws Exception {
if (null == elementFilter) {
elementFilter = new ViewElementDefinition.Builder().json(elementDefinitionJson).build().getPreAggregationFilter();
}
if (null == schemaUtils) {
schemaUtils = new SchemaUtils(Schema.fromJson(jsonGafferSchema));
}
try {
final ParquetReader<Element> fileReader = openParquetReader();
Element e = fileReader.read();
while (null != e) {
if (!visibility.isEmpty()) {
if (isVisible(e)) {
if (needsValidatorsAndFiltersApplying) {
final String group = e.getGroup();
final ElementFilter validatorFilter = gafferSchema.getElement(group).getValidator(false);
if (skipValidation || validatorFilter == null || validatorFilter.test(e)) {
if (elementFilter == null || elementFilter.test(e)) {
ViewUtil.removeProperties(view, e);
queue.add(e);
}
}
} else {
ViewUtil.removeProperties(view, e);
queue.add(e);
}
}
} else if (needsValidatorsAndFiltersApplying) {
final String group = e.getGroup();
final ElementFilter validatorFilter = gafferSchema.getElement(group).getValidator(false);
if (skipValidation || validatorFilter == null || validatorFilter.test(e)) {
if (elementFilter == null || elementFilter.test(e)) {
ViewUtil.removeProperties(view, e);
queue.add(e);
}
}
} else {
ViewUtil.removeProperties(view, e);
queue.add(e);
}
e = fileReader.read();
}
fileReader.close();
} catch (final IOException ignore) {
LOGGER.error("IOException reading file", ignore);
// ignore as this file does not exist
}
return null;
}
Aggregations