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 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));
}
}
}
}
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));
}
}
}
}
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);
}
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);
}
Aggregations