use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedAggregateHandlerTest method shouldAggregateDuplicatesFromDiffStores.
@Test
public void shouldAggregateDuplicatesFromDiffStores() throws Exception {
FederatedStoreProperties federatedStoreProperties = FederatedStoreProperties.loadStoreProperties(StreamUtil.openStream(currentClass, "predefinedFederatedStore.properties"));
final Graph fed = new Graph.Builder().config(new GraphConfig("fed")).addSchema(new Schema()).storeProperties(federatedStoreProperties).build();
final String graphNameA = "a";
final String graphNameB = "b";
final Context context = new Context(new User());
fed.execute(new OperationChain.Builder().first(new AddGraph.Builder().graphId(graphNameA).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).then(new AddGraph.Builder().graphId(graphNameB).schema(new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("string").destination("string").build()).type("string", String.class).build()).storeProperties(PROPERTIES).build()).build(), context);
fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameA).build(), context);
fed.execute(new AddElements.Builder().input(new Edge.Builder().group("edge").source("s1").dest("d1").build()).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, graphNameB).build(), context);
final CloseableIterable<? extends Element> getAll = fed.execute(new GetAllElements(), context);
List<Element> list = new ArrayList<>();
getAll.forEach(list::add);
assertThat(list).hasSize(2);
final Iterable<? extends Element> getAggregate = fed.execute(new OperationChain.Builder().first(new GetAllElements()).then(new Aggregate()).build(), context);
list.clear();
getAggregate.forEach(list::add);
assertThat(list).hasSize(1);
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedRemoveGraphHandlerTest method shouldRemoveGraphForAddingUser.
@Test
public void shouldRemoveGraphForAddingUser() throws Exception {
FederatedStore store = new FederatedStore();
final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
store.addGraphs(testUser.getOpAuths(), testUser.getUserId(), false, new GraphSerialisable.Builder().config(new GraphConfig(EXPECTED_GRAPH_ID)).schema(new Schema.Builder().build()).properties(PROPERTIES).build());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
new FederatedRemoveGraphHandler().doOperation(new RemoveGraph.Builder().graphId(EXPECTED_GRAPH_ID).build(), new Context(testUser), store);
Collection<Graph> graphs = store.getGraphs(testUser, null, ignore);
assertThat(graphs).isEmpty();
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class FederatedRemoveGraphHandlerTest method shouldNotRemoveGraphForNonAddingUser.
@Test
public void shouldNotRemoveGraphForNonAddingUser() throws Exception {
FederatedStore store = new FederatedStore();
final FederatedStoreProperties federatedStoreProperties = new FederatedStoreProperties();
federatedStoreProperties.setCacheProperties(CACHE_SERVICE_CLASS_STRING);
store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
store.addGraphs(testUser.getOpAuths(), "other", false, new GraphSerialisable.Builder().config(new GraphConfig(EXPECTED_GRAPH_ID)).schema(new Schema.Builder().build()).properties(PROPERTIES).build());
assertEquals(1, store.getGraphs(testUser, null, ignore).size());
new FederatedRemoveGraphHandler().doOperation(new RemoveGraph.Builder().graphId(EXPECTED_GRAPH_ID).build(), new Context(testUser), store);
Collection<Graph> graphs = store.getGraphs(testUser, null, ignore);
assertThat(graphs).hasSize(1);
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class RoadTrafficDataLoader method main.
public static void main(final String[] args) {
if (args.length != 4) {
System.err.println("Usage: " + RoadTrafficDataLoader.class.getSimpleName() + " <graphConfigFile> <schemaDir> <storePropsFile> <roadTrafficDataFile.csv>");
System.exit(1);
}
final String graphConfigFile = args[0];
final String schemaDir = args[1];
final String storePropertiesFile = args[2];
final String dataFile = args[3];
final GraphConfig config = new GraphConfig.Builder().json(new File(graphConfigFile).toPath()).build();
final Schema schema = Schema.fromJson(new File(schemaDir).toPath());
final StoreProperties storeProperties = StoreProperties.loadStoreProperties(storePropertiesFile);
final Graph graph = new Graph.Builder().config(config).addSchemas(schema).storeProperties(storeProperties).build();
final User user = new User();
final RoadTrafficDataLoader dataLoader = new RoadTrafficDataLoader(graph, user);
LOGGER.info("Loading data");
try {
dataLoader.load(new File(dataFile));
LOGGER.info("Data has been loaded");
} catch (final Exception e) {
LOGGER.info("Unable to load data: " + e.getMessage());
throw new RuntimeException("Unable to load data", e);
}
}
use of uk.gov.gchq.gaffer.graph.GraphConfig in project Gaffer by gchq.
the class DoubleProxyTest method setUpStores.
@BeforeEach
public void setUpStores() throws OperationException {
SingleUseProxyMapStore.cleanUp();
ProxyProperties proxyProperties = new ProxyProperties();
proxyProperties.setStoreClass(SingleUseProxyMapStore.class);
// this direct Proxy to the RestMapStore can be ignored, unless adding elements is desired.
Graph ignore = new Graph.Builder().storeProperties(proxyProperties).config(new GraphConfig("RestApiGraph")).addSchema(Schema.fromJson(getClass().getResourceAsStream("/schema/basicEntitySchema.json"))).build();
federatedStoreGraph = new Graph.Builder().config(new GraphConfig("federatedStoreGraph")).storeProperties(new FederatedStoreProperties()).build();
connectGraphs("RestProxy1");
connectGraphs("RestProxy2");
}
Aggregations