Search in sources :

Example 36 with ElementFilter

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());
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Test(org.junit.jupiter.api.Test)

Example 37 with ElementFilter

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());
}
Also used : ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ElementAggregator(uk.gov.gchq.gaffer.data.element.function.ElementAggregator) Test(org.junit.jupiter.api.Test)

Example 38 with ElementFilter

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;
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with ElementFilter

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;
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType)

Example 40 with ElementFilter

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"));
}
Also used : Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ValidationResult(uk.gov.gchq.koryphe.ValidationResult) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43 Test (org.junit.jupiter.api.Test)35 Schema (uk.gov.gchq.gaffer.store.schema.Schema)11 Element (uk.gov.gchq.gaffer.data.element.Element)10 ValidationResult (uk.gov.gchq.koryphe.ValidationResult)10 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 Context (uk.gov.gchq.gaffer.store.Context)6 Store (uk.gov.gchq.gaffer.store.Store)6 Exists (uk.gov.gchq.koryphe.impl.predicate.Exists)6 ElementAggregator (uk.gov.gchq.gaffer.data.element.function.ElementAggregator)5 ElementTransformer (uk.gov.gchq.gaffer.data.element.function.ElementTransformer)5 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)5 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)5 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)5 SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)5 HashMap (java.util.HashMap)4 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)4 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4