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();
}
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();
}
Aggregations