Search in sources :

Example 1 with ElementFilterException

use of uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException 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;
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Schema(uk.gov.gchq.gaffer.store.schema.Schema) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ElementFilterException(uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ElementFilterException (uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException)1 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)1 Schema (uk.gov.gchq.gaffer.store.schema.Schema)1