use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ViewElementDefinitionTest method shouldFailToBuildElementDefinitionWhenPostAggregationFilterSpecifiedTwice.
@Test
public void shouldFailToBuildElementDefinitionWhenPostAggregationFilterSpecifiedTwice() {
final ElementTransformer transformer = mock(ElementTransformer.class);
final ElementFilter filter = mock(ElementFilter.class);
assertThatIllegalArgumentException().isThrownBy(() -> new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_1, String.class).transientProperty(TestPropertyNames.PROP_2, String.class).transformer(transformer).postAggregationFilter(filter).postAggregationFilter(filter).build());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ViewElementDefinitionTest method shouldBuildElementDefinition.
@Test
public void shouldBuildElementDefinition() {
// Given
final ElementTransformer transformer = mock(ElementTransformer.class);
final ElementFilter preFilter = mock(ElementFilter.class);
final ElementAggregator aggregator = mock(ElementAggregator.class);
final ElementFilter postFilter = mock(ElementFilter.class);
// When
final ViewElementDefinition elementDef = new ViewElementDefinition.Builder().transientProperty(TestPropertyNames.PROP_1, String.class).transientProperty(TestPropertyNames.PROP_2, String.class).properties(TestPropertyNames.COUNT, TestPropertyNames.DATE).preAggregationFilter(preFilter).aggregator(aggregator).postTransformFilter(postFilter).transformer(transformer).build();
// Then
assertEquals(2, elementDef.getTransientProperties().size());
assertTrue(elementDef.containsTransientProperty(TestPropertyNames.PROP_1));
assertTrue(elementDef.containsTransientProperty(TestPropertyNames.PROP_2));
assertEquals(Sets.newHashSet(TestPropertyNames.COUNT, TestPropertyNames.DATE), elementDef.getProperties());
assertNull(elementDef.getExcludeProperties());
assertSame(preFilter, elementDef.getPreAggregationFilter());
assertSame(aggregator, elementDef.getAggregator());
assertSame(postFilter, elementDef.getPostTransformFilter());
assertSame(transformer, elementDef.getTransformer());
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class FilterValidator method validateOperation.
@Override
protected ValidationResult validateOperation(final Filter operation, final Schema schema) {
final ValidationResult result = new ValidationResult();
final Map<String, ?> entities = null != operation.getEntities() ? operation.getEntities() : new HashMap<>();
final Map<String, ?> edges = null != operation.getEdges() ? operation.getEdges() : new HashMap<>();
for (final Map.Entry<String, ?> entry : edges.entrySet()) {
result.add(validateEdge(entry, schema));
result.add(validateElementFilter((ElementFilter) entry.getValue()));
result.add(validateFilterPropertyClasses(schema.getEdge(entry.getKey()), (ElementFilter) entry.getValue()));
}
for (final Map.Entry<String, ?> entry : entities.entrySet()) {
result.add(validateEntity(entry, schema));
result.add(validateElementFilter((ElementFilter) entry.getValue()));
result.add(validateFilterPropertyClasses(schema.getEntity(entry.getKey()), (ElementFilter) entry.getValue()));
}
if (null != operation.getGlobalElements()) {
for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalElements()));
}
for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalElements()));
}
}
if (null != operation.getGlobalEdges()) {
for (final SchemaEdgeDefinition edgeDefinition : schema.getEdges().values()) {
result.add(validateFilterPropertyClasses(edgeDefinition, operation.getGlobalEdges()));
}
}
if (null != operation.getGlobalEntities()) {
for (final SchemaEntityDefinition entityDefinition : schema.getEntities().values()) {
result.add(validateFilterPropertyClasses(entityDefinition, operation.getGlobalEntities()));
}
}
return result;
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class SchemaElementDefinition method getValidator.
public ElementFilter getValidator(final boolean includeIsA) {
ElementFilter fullValidatorTmp;
if (includeIsA) {
fullValidatorTmp = fullValidatorWithIsACache;
} else {
fullValidatorTmp = fullValidatorCache;
}
if (null == fullValidatorTmp) {
fullValidatorTmp = new ElementFilter();
if (null != validator) {
fullValidatorTmp.setComponents(new ArrayList<>(validator.getComponents()));
}
for (final Entry<IdentifierType, String> entry : getIdentifierMap().entrySet()) {
final String key = entry.getKey().name();
if (includeIsA) {
addIsAFunction(fullValidatorTmp, key, entry.getValue());
}
addTypeValidatorFunctions(fullValidatorTmp, key, entry.getValue());
}
for (final Entry<String, String> entry : getPropertyMap().entrySet()) {
final String key = entry.getKey();
if (includeIsA) {
addIsAFunction(fullValidatorTmp, key, entry.getValue());
}
addTypeValidatorFunctions(fullValidatorTmp, key, entry.getValue());
}
fullValidatorTmp.lock();
if (includeIsA) {
fullValidatorWithIsACache = fullValidatorTmp;
} else {
fullValidatorCache = fullValidatorTmp;
}
}
return fullValidatorTmp;
}
use of uk.gov.gchq.gaffer.data.element.function.ElementFilter in project Gaffer by gchq.
the class ElementValidatorTest method shouldReturnFailedValidationResultWhenSchemaValidateWithInvalidElement.
@Test
public void shouldReturnFailedValidationResultWhenSchemaValidateWithInvalidElement() {
// Given
final Schema schema = mock(Schema.class);
final String group = TestGroups.EDGE;
final Element elm = mock(Element.class);
final SchemaElementDefinition elementDef = mock(SchemaElementDefinition.class);
final ElementFilter filter = mock(ElementFilter.class);
final boolean includeIsA = true;
final ElementValidator validator = new ElementValidator(schema, includeIsA);
given(elm.getGroup()).willReturn(group);
given(schema.getElement(group)).willReturn(elementDef);
given(elementDef.getValidator(includeIsA)).willReturn(filter);
given(filter.testWithValidationResult(elm)).willReturn(new ValidationResult("some error"));
// When
final ValidationResult result = validator.validateWithValidationResult(elm);
// Then
assertFalse(result.isValid());
assertTrue(result.getErrorString().contains("some error"));
}
Aggregations