Search in sources :

Example 11 with SchemaElementDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.

the class ExamplesService method getEdge.

protected Edge getEdge(final int uniqueId1, final int uniqueId2) {
    final String group = getAnEdgeGroup();
    final SchemaElementDefinition edgeDef = getSchema().getEdge(group);
    final Edge edge = new Edge(group);
    edge.setSource(getExampleVertex(edgeDef.getIdentifierClass(IdentifierType.SOURCE), uniqueId1));
    edge.setDestination(getExampleVertex(edgeDef.getIdentifierClass(IdentifierType.DESTINATION), uniqueId2));
    edge.setDirected(isAnEdgeDirected());
    populateProperties(edge, edgeDef, uniqueId1);
    return edge;
}
Also used : Edge(uk.gov.gchq.gaffer.data.element.Edge) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 12 with SchemaElementDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.

the class ExamplesService method getEntity.

protected Entity getEntity(final int uniqueId) {
    final String group = getAnEntityGroup();
    final SchemaElementDefinition entityDef = getSchema().getEntity(group);
    final Entity entity = new Entity(group);
    entity.setVertex(getExampleVertex(entityDef.getIdentifierClass(IdentifierType.VERTEX), uniqueId));
    populateProperties(entity, entityDef, uniqueId);
    return entity;
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 13 with SchemaElementDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.

the class ExamplesService method getAnEdgePropertyName.

protected String getAnEdgePropertyName() {
    final SchemaElementDefinition edgeDef = getSchema().getEdge(getAnEdgeGroup());
    final String propertyName;
    if (null != edgeDef && !edgeDef.getProperties().isEmpty()) {
        propertyName = edgeDef.getProperties().iterator().next();
    } else {
        propertyName = "examplePropertyName";
    }
    return propertyName;
}
Also used : SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 14 with SchemaElementDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition in project Gaffer by gchq.

the class ExamplesService method getAnEntityPropertyName.

protected String getAnEntityPropertyName() {
    final SchemaElementDefinition entityDef = getSchema().getEntity(getAnEntityGroup());
    String propertyName = null;
    if (null != entityDef && !entityDef.getProperties().isEmpty()) {
        propertyName = entityDef.getProperties().iterator().next();
    }
    return propertyName;
}
Also used : SchemaElementDefinition(uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)

Example 15 with SchemaElementDefinition

use of uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition 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)

Aggregations

SchemaElementDefinition (uk.gov.gchq.gaffer.store.schema.SchemaElementDefinition)19 AccumuloElementConversionException (uk.gov.gchq.gaffer.accumulostore.key.exception.AccumuloElementConversionException)7 Element (uk.gov.gchq.gaffer.data.element.Element)5 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)5 Schema (uk.gov.gchq.gaffer.store.schema.Schema)5 TypeDefinition (uk.gov.gchq.gaffer.store.schema.TypeDefinition)5 Test (org.junit.Test)4 Properties (uk.gov.gchq.gaffer.data.element.Properties)4 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)4 Serialisation (uk.gov.gchq.gaffer.serialisation.Serialisation)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Value (org.apache.accumulo.core.data.Value)1 DataType (org.apache.spark.sql.types.DataType)1