use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class RowIDAggregator method validateOptions.
@Override
public boolean validateOptions(final Map<String, String> options) {
if (!options.containsKey(AccumuloStoreConstants.SCHEMA)) {
throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.SCHEMA);
}
if (!options.containsKey(AccumuloStoreConstants.COLUMN_FAMILY)) {
throw new IllegalArgumentException("Must specify the " + AccumuloStoreConstants.COLUMN_FAMILY);
}
try {
schema = Schema.fromJson(options.get(AccumuloStoreConstants.SCHEMA).getBytes(CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SchemaException("Unable to deserialise the schema", 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 AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
}
group = options.get(AccumuloStoreConstants.COLUMN_FAMILY);
aggregator = schema.getElement(group).getAggregator();
return true;
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class SampleDataForSplitPointsMapper method setup.
protected void setup(final Context context) {
super.setup(context);
proportionToSample = context.getConfiguration().getFloat(SampleDataForSplitPointsJobFactory.PROPORTION_TO_SAMPLE, 0.001f);
final Schema schema;
try {
schema = Schema.fromJson(context.getConfiguration().get(SampleDataForSplitPointsJobFactory.SCHEMA).getBytes(CommonConstants.UTF_8));
} catch (final UnsupportedEncodingException e) {
throw new SchemaException("Unable to deserialise Store Schema from JSON", e);
}
final String converterClass = context.getConfiguration().get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS);
try {
final Class<?> elementConverterClass = Class.forName(converterClass);
elementConverter = (AccumuloElementConverter) elementConverterClass.getConstructor(Schema.class).newInstance(schema);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new IllegalArgumentException("Element converter could not be created: " + converterClass, e);
}
}
use of uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException in project Gaffer by gchq.
the class AggregatorIterator 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);
}
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 AggregationException("Failed to load element converter from class name provided : " + options.get(AccumuloStoreConstants.ACCUMULO_ELEMENT_CONVERTER_CLASS), e);
}
return true;
}
Aggregations