use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class DefaultGraphFactory method createGraphBuilder.
public Graph.Builder createGraphBuilder() {
final Path storePropertiesPath = Paths.get(System.getProperty(SystemProperty.STORE_PROPERTIES_PATH));
if (null == storePropertiesPath) {
throw new SchemaException("The path to the Store Properties was not found in system properties for key: " + SystemProperty.STORE_PROPERTIES_PATH);
}
final Graph.Builder builder = new Graph.Builder();
builder.storeProperties(storePropertiesPath);
for (final Path path : getSchemaPaths()) {
builder.addSchema(path);
}
final OperationAuthoriser opAuthoriser = createOpAuthoriser();
if (null != opAuthoriser) {
builder.addHook(opAuthoriser);
}
return builder;
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class StoreTest method shouldThrowExceptionIfOperationViewIsInvalid.
@Test
public void shouldThrowExceptionIfOperationViewIsInvalid() throws OperationException, StoreException {
// Given
// Given
final Schema schema = createSchemaMock();
final StoreProperties properties = mock(StoreProperties.class);
final AddElements addElements = new AddElements();
final View view = mock(View.class);
final ViewValidator viewValidator = mock(ViewValidator.class);
final StoreImpl store = new StoreImpl(viewValidator);
addElements.setView(view);
given(schema.validate()).willReturn(true);
given(viewValidator.validate(view, schema, true)).willReturn(false);
store.initialise(schema, properties);
// When / Then
try {
store.execute(addElements, user);
fail("Exception expected");
} catch (final SchemaException e) {
verify(viewValidator).validate(view, schema, true);
assertTrue(e.getMessage().contains("View"));
}
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class StoreTest method shouldThrowExceptionWhenPropertyIsNotSerialisable.
@Test
public void shouldThrowExceptionWhenPropertyIsNotSerialisable() throws StoreException {
// Given
final Schema mySchema = new Schema.Builder().edge(TestGroups.EDGE, new SchemaEdgeDefinition.Builder().property(TestPropertyNames.PROP_1, "invalidType").build()).type("invalidType", new TypeDefinition.Builder().clazz(Object.class).serialiser(new StringSerialiser()).build()).build();
final StoreProperties properties = mock(StoreProperties.class);
final StoreImpl store = new StoreImpl();
// When
try {
store.initialise(mySchema, properties);
fail();
} catch (final SchemaException exception) {
assertNotNull(exception.getMessage());
}
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class Store method validateSchemas.
public void validateSchemas() {
boolean valid = schema.validate();
final HashMap<String, SchemaElementDefinition> schemaElements = new HashMap<>();
schemaElements.putAll(getSchema().getEdges());
schemaElements.putAll(getSchema().getEntities());
for (final Entry<String, SchemaElementDefinition> schemaElementDefinitionEntry : schemaElements.entrySet()) {
for (final String propertyName : schemaElementDefinitionEntry.getValue().getProperties()) {
Class propertyClass = schemaElementDefinitionEntry.getValue().getPropertyClass(propertyName);
Serialisation serialisation = schemaElementDefinitionEntry.getValue().getPropertyTypeDef(propertyName).getSerialiser();
if (null == serialisation) {
valid = false;
LOGGER.error("Could not find a serialiser for property '" + propertyName + "' in the group '" + schemaElementDefinitionEntry.getKey() + "'.");
} else if (!serialisation.canHandle(propertyClass)) {
valid = false;
LOGGER.error("Schema serialiser (" + serialisation.getClass().getName() + ") for property '" + propertyName + "' in the group '" + schemaElementDefinitionEntry.getKey() + "' cannot handle property found in the schema");
}
}
}
if (!valid) {
throw new SchemaException("Schema is not valid. Check the logs for more information.");
}
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class AbstractElementFilter method validateOptions.
@Override
public boolean validateOptions(final Map<String, String> options) {
if (!super.validateOptions(options)) {
return false;
}
if (!options.containsKey(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS)) {
throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
}
if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
}
validator = getElementValidator(options);
final Schema schema;
try {
schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SchemaException("Unable to deserialise the schema from JSON", e);
}
try {
final Class<?> elementConverterClass = Class.forName(options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS));
elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new ElementFilterException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
}
return true;
}
Aggregations