Search in sources :

Example 6 with SchemaException

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;
}
Also used : Path(java.nio.file.Path) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) OperationAuthoriser(uk.gov.gchq.gaffer.graph.hook.OperationAuthoriser) Graph(uk.gov.gchq.gaffer.graph.Graph)

Example 7 with SchemaException

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"));
    }
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) ViewValidator(uk.gov.gchq.gaffer.store.schema.ViewValidator) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test)

Example 8 with SchemaException

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());
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) StringSerialiser(uk.gov.gchq.gaffer.serialisation.implementation.StringSerialiser) Schema(uk.gov.gchq.gaffer.store.schema.Schema) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) Test(org.junit.Test)

Example 9 with SchemaException

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.");
    }
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Serialisation(uk.gov.gchq.gaffer.serialisation.Serialisation) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 10 with SchemaException

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

SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)13 Schema (uk.gov.gchq.gaffer.store.schema.Schema)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Test (org.junit.Test)4 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 AggregationException (uk.gov.gchq.gaffer.accumulostore.key.exception.AggregationException)2 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)2 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)2 SchemaEdgeDefinition (uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition)2 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Configuration (org.apache.hadoop.conf.Configuration)1 ElementFilterException (uk.gov.gchq.gaffer.accumulostore.key.exception.ElementFilterException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 StringConcat (uk.gov.gchq.gaffer.function.aggregate.StringConcat)1 Sum (uk.gov.gchq.gaffer.function.aggregate.Sum)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1