Search in sources :

Example 6 with Builder

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

the class FederatedGraphStorage method getSchema.

public Schema getSchema(final Map<String, String> config, final User user) {
    if (null == user) {
        // no user then return an empty schema
        return new Schema();
    }
    final List<String> graphIds = FederatedStoreUtil.getGraphIds(config);
    final Stream<Graph> graphs = getStream(user, graphIds);
    final Builder schemaBuilder = new Builder();
    try {
        graphs.forEach(g -> schemaBuilder.merge(g.getSchema()));
    } catch (final SchemaException e) {
        final List<String> resultGraphIds = getStream(user, graphIds).map(Graph::getGraphId).collect(Collectors.toList());
        throw new SchemaException(String.format(UNABLE_TO_MERGE_THE_SCHEMAS_FOR_ALL_OF_YOUR_FEDERATED_GRAPHS, resultGraphIds, KEY_OPERATION_OPTIONS_GRAPH_IDS), e);
    }
    return schemaBuilder.build();
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) List(java.util.List)

Example 7 with Builder

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

the class FederatedGraphStorage method getSchema.

public Schema getSchema(final GetSchema operation, final Context context) {
    if (null == context || null == context.getUser()) {
        // no user then return an empty schema
        return new Schema();
    }
    if (null == operation) {
        return getSchema((Map<String, String>) null, context);
    }
    final List<String> graphIds = FederatedStoreUtil.getGraphIds(operation.getOptions());
    final Stream<Graph> graphs = getStream(context.getUser(), graphIds);
    final Builder schemaBuilder = new Builder();
    try {
        if (operation.isCompact()) {
            final GetSchema getSchema = new GetSchema.Builder().compact(true).build();
            graphs.forEach(g -> {
                try {
                    schemaBuilder.merge(g.execute(getSchema, context));
                } catch (final OperationException e) {
                    throw new RuntimeException("Unable to fetch schema from graph " + g.getGraphId(), e);
                }
            });
        } else {
            graphs.forEach(g -> schemaBuilder.merge(g.getSchema()));
        }
    } catch (final SchemaException e) {
        final List<String> resultGraphIds = getStream(context.getUser(), graphIds).map(Graph::getGraphId).collect(Collectors.toList());
        throw new SchemaException("Unable to merge the schemas for all of your federated graphs: " + resultGraphIds + ". You can limit which graphs to query for using the operation option: " + KEY_OPERATION_OPTIONS_GRAPH_IDS, e);
    }
    return schemaBuilder.build();
}
Also used : SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) Graph(uk.gov.gchq.gaffer.graph.Graph) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) Builder(uk.gov.gchq.gaffer.store.schema.Schema.Builder) List(java.util.List) GetSchema(uk.gov.gchq.gaffer.store.operation.GetSchema) CacheOperationException(uk.gov.gchq.gaffer.cache.exception.CacheOperationException) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

Builder (uk.gov.gchq.gaffer.store.schema.Schema.Builder)7 Test (org.junit.jupiter.api.Test)4 Schema (uk.gov.gchq.gaffer.store.schema.Schema)4 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)3 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)3 GetSchema (uk.gov.gchq.gaffer.store.operation.GetSchema)3 List (java.util.List)2 Graph (uk.gov.gchq.gaffer.graph.Graph)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2 CacheOperationException (uk.gov.gchq.gaffer.cache.exception.CacheOperationException)1 AddGraph (uk.gov.gchq.gaffer.federatedstore.operation.AddGraph)1 StoreException (uk.gov.gchq.gaffer.store.StoreException)1 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)1 GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)1 HashMapGraphLibrary (uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary)1