Search in sources :

Example 16 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class ViewValidator method validate.

/**
     * Checks all {@link uk.gov.gchq.gaffer.function.FilterFunction}s and {@link uk.gov.gchq.gaffer.function.TransformFunction}s defined are
     * compatible with the identifiers and properties in the {@link Schema}
     * and transient properties in the {@link View}.
     *
     * @param view           the {@link View} to validate
     * @param schema         the {@link Schema} to validate the view against
     * @param isStoreOrdered true if the store is ordered
     * @return true if the element definition is valid, otherwise false and an error is logged
     */
public boolean validate(final View view, final Schema schema, final boolean isStoreOrdered) {
    boolean isValid = true;
    if (null != view) {
        if (null != view.getEntities()) {
            for (final Entry<String, ViewElementDefinition> entry : view.getEntities().entrySet()) {
                final String group = entry.getKey();
                final SchemaEntityDefinition schemaElDef = schema.getEntity(group);
                final ViewElementDefinition viewElDef = entry.getValue();
                if (null == schemaElDef) {
                    LOGGER.error("Entity group " + group + " does not exist in the schema");
                    isValid = false;
                } else {
                    for (final String transProp : viewElDef.getTransientProperties()) {
                        if (schemaElDef.containsProperty(transProp)) {
                            LOGGER.error("Transient property " + transProp + " for entity group " + group + " is not transient as it has been found in the schema");
                            isValid = false;
                        }
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPreAggregationFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPostAggregationFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getTransformer(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPostTransformFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateGroupBy(isStoreOrdered, group, viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                }
            }
        }
        if (null != view.getEdges()) {
            for (final Entry<String, ViewElementDefinition> entry : view.getEdges().entrySet()) {
                final String group = entry.getKey();
                final SchemaEdgeDefinition schemaElDef = schema.getEdge(group);
                final ViewElementDefinition viewElDef = entry.getValue();
                if (null == schemaElDef) {
                    LOGGER.error("Edge group " + group + " does not exist in the schema");
                    isValid = false;
                } else {
                    for (final String transProp : viewElDef.getTransientProperties()) {
                        if (schemaElDef.containsProperty(transProp)) {
                            LOGGER.error("Transient property " + transProp + " for edge group " + group + " is not transient as it has been found in the schema");
                            isValid = false;
                        }
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPreAggregationFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPostAggregationFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getTransformer(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateFunctionArgumentTypes(viewElDef.getPostTransformFilter(), viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                    if (!validateGroupBy(isStoreOrdered, group, viewElDef, schemaElDef)) {
                        isValid = false;
                    }
                }
            }
        }
    }
    return isValid;
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)

Example 17 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class ViewValidator method validateEntities.

protected void validateEntities(final View view, final Schema schema, final Set<StoreTrait> storeTraits, final boolean isStoreOrdered, final ValidationResult result) {
    if (null != view.getEntities()) {
        for (final Map.Entry<String, ViewElementDefinition> entry : view.getEntities().entrySet()) {
            final String group = entry.getKey();
            final SchemaEntityDefinition schemaElDef = schema.getEntity(group);
            final ViewElementDefinition viewElDef = entry.getValue();
            if (null == schemaElDef) {
                result.addError("Entity group " + group + " does not exist in the schema");
            } else {
                for (final String transProp : viewElDef.getTransientProperties()) {
                    if (schemaElDef.containsProperty(transProp)) {
                        result.addError("Transient property " + transProp + " for entity group " + group + " is not transient as it has been found in the schema");
                    }
                }
                result.add(validateAgainstStoreTraits(viewElDef, storeTraits));
                if (!Boolean.parseBoolean(view.getConfig(SKIP_VIEW_VALIDATION))) {
                    result.add(validateFunctionArgumentTypes(viewElDef.getPreAggregationFilter(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getAggregator(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getPostAggregationFilter(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getTransformer(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getPostTransformFilter(), viewElDef, schemaElDef));
                }
                result.add(validateGroupBy(isStoreOrdered, group, viewElDef, schemaElDef));
            }
        }
    }
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Map(java.util.Map)

Example 18 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class ViewValidator method validateEdge.

protected void validateEdge(final View view, final Schema schema, final Set<StoreTrait> storeTraits, final boolean isStoreOrdered, final ValidationResult result) {
    if (null != view.getEdges()) {
        for (final Map.Entry<String, ViewElementDefinition> entry : view.getEdges().entrySet()) {
            final String group = entry.getKey();
            final SchemaEdgeDefinition schemaElDef = schema.getEdge(group);
            final ViewElementDefinition viewElDef = entry.getValue();
            if (null == schemaElDef) {
                result.addError("Edge group " + group + " does not exist in the schema");
            } else {
                for (final String transProp : viewElDef.getTransientProperties()) {
                    if (schemaElDef.containsProperty(transProp)) {
                        result.addError("Transient property " + transProp + " for edge group " + group + " is not transient as it has been found in the schema");
                    }
                }
                result.add(validateAgainstStoreTraits(viewElDef, storeTraits));
                if (!Boolean.parseBoolean(view.getConfig(SKIP_VIEW_VALIDATION))) {
                    result.add(validateFunctionArgumentTypes(viewElDef.getPreAggregationFilter(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getAggregator(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getPostAggregationFilter(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getTransformer(), viewElDef, schemaElDef));
                    result.add(validateFunctionArgumentTypes(viewElDef.getPostTransformFilter(), viewElDef, schemaElDef));
                }
                result.add(validateGroupBy(isStoreOrdered, group, viewElDef, schemaElDef));
            }
        }
    }
}
Also used : ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) Map(java.util.Map)

Example 19 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.

the class ElementValidator method validateAgainstViewFilter.

private boolean validateAgainstViewFilter(final Element element, final FilterType filterType) {
    if (null == element) {
        return false;
    }
    if (null == view) {
        return true;
    }
    final ViewElementDefinition elementDef = view.getElement(element.getGroup());
    if (null == elementDef) {
        return false;
    }
    final ElementFilter validator = getElementFilter(elementDef, filterType);
    return null == validator || validator.test(element);
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)

Example 20 with ViewElementDefinition

use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition 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);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Aggregations

ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)27 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Test (org.junit.jupiter.api.Test)10 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)6 HashMap (java.util.HashMap)5 GlobalViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition)5 Graph (uk.gov.gchq.gaffer.graph.Graph)5 Set (java.util.Set)4 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3 Element (uk.gov.gchq.gaffer.data.element.Element)3 TestStore (uk.gov.gchq.gaffer.integration.store.TestStore)3 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)3 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)3 Store (uk.gov.gchq.gaffer.store.Store)3 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)3