use of uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition in project Gaffer by gchq.
the class ExamplesService method generateViewBuilder.
protected View.Builder generateViewBuilder() {
final View.Builder viewBuilder = new View.Builder();
if (hasEntities()) {
final ViewElementDefinition viewElement;
if (null == getAnEntityPropertyName()) {
viewElement = new ViewElementDefinition();
} else {
viewElement = new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(getAnEntityPropertyName()).execute(new ExampleFilterFunction()).build()).build();
}
viewBuilder.entity(getAnEntityGroup(), viewElement);
}
if (hasEdges()) {
final ViewElementDefinition viewElement;
if (null == getAnEdgePropertyName()) {
viewElement = new ViewElementDefinition();
} else {
viewElement = new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(getAnEdgePropertyName()).execute(new ExampleFilterFunction()).build()).build();
}
viewBuilder.edge(getAnEdgeGroup(), viewElement);
}
viewBuilder.globalElements(new GlobalViewElementDefinition.Builder().groupBy().build());
return viewBuilder;
}
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 != schema) {
return validateWithSchema(element);
}
final ViewElementDefinition elementDef = view.getElement(element.getGroup());
if (null == elementDef) {
return false;
}
final ElementFilter validator = getElementFilter(elementDef, filterType);
return null == validator || validator.filter(element);
}
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;
}
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.filter(elm)).willReturn(true);
// When
final boolean isValid = validator.validate(elm);
// Then
assertTrue(isValid);
}
Aggregations