use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary in project gaffer-doc by gchq.
the class ExportToOtherGraphExample method simpleExportUsingGraphFromGraphLibrary.
public void simpleExportUsingGraphFromGraphLibrary() {
// ---------------------------------------------------------
// Setup the graphLibrary with an export graph
final GraphLibrary graphLibrary = new FileGraphLibrary("target/graphLibrary");
final AccumuloProperties exportStoreProperties = new AccumuloProperties();
// set other store property config here.
final Schema exportSchema = new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("int").destination("int").directed("true").property("count", "int").aggregate(false).build()).type("int", Integer.class).type("true", new TypeDefinition.Builder().clazz(Boolean.class).validateFunctions(new IsTrue()).build()).build();
graphLibrary.addOrUpdate("exportGraphId", exportSchema, exportStoreProperties);
final Graph graph = new Graph.Builder().config(StreamUtil.openStream(getClass(), "graphConfigWithLibrary.json")).addSchemas(StreamUtil.openStreams(getClass(), "operations/schema")).storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties")).build();
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(new GetAllElements.Builder().view(new View.Builder().edge("edge").build()).build()).then(new ExportToOtherGraph.Builder().graphId("exportGraphId").build()).build();
// ---------------------------------------------------------
showExample(opChain, "This example will export all Edges with group 'edge' to another existing graph 'exportGraphId' using a GraphLibrary." + "We demonstrate here that if we use a GraphLibrary, we can register a graph ID and reference it from the export operation. " + "This means the user does not have to proxy all the schema and store properties when they configure the export operation, they can just provide the ID.");
}
use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary in project gaffer-doc by gchq.
the class ExportToOtherGraphExample method exportToNewGraphBasedOnConfigFromGraphLibrary.
public void exportToNewGraphBasedOnConfigFromGraphLibrary() {
// ---------------------------------------------------------
// Setup the graphLibrary with a schema and store properties for exporting
final GraphLibrary graphLibrary = new FileGraphLibrary("target/graphLibrary");
final AccumuloProperties exportStoreProperties = new AccumuloProperties();
// set other store property config here.
graphLibrary.addProperties("exportStorePropertiesId", exportStoreProperties);
final Schema exportSchema = new Schema.Builder().edge("edge", new SchemaEdgeDefinition.Builder().source("int").destination("int").directed("true").property("count", "int").aggregate(false).build()).type("int", Integer.class).type("true", new TypeDefinition.Builder().clazz(Boolean.class).validateFunctions(new IsTrue()).build()).build();
graphLibrary.addSchema("exportSchemaId", exportSchema);
final Graph graph = new Graph.Builder().config(StreamUtil.openStream(getClass(), "graphConfigWithLibrary.json")).addSchemas(StreamUtil.openStreams(getClass(), "operations/schema")).storeProperties(StreamUtil.openStream(getClass(), "mockaccumulostore.properties")).build();
final OperationChain<Iterable<? extends Element>> opChain = new OperationChain.Builder().first(new GetAllElements.Builder().view(new View.Builder().edge("edge").build()).build()).then(new ExportToOtherGraph.Builder().graphId("newGraphId").parentSchemaIds("exportSchemaId").parentStorePropertiesId("exportStorePropertiesId").build()).build();
// ---------------------------------------------------------
showExample(opChain, "Similar to the previous example, this example will export all Edges with group 'edge' to another graph using a GraphLibrary. " + "But in this example we show that you can export to a new graph with id newGraphId by choosing any combination of schema and store properties registered in the GraphLibrary. " + "This is useful as a system administrator could register various different store properties, of different Accumulo/HBase clusters and a user could them just select which one to use by referring to the relevant store properties ID.");
}
use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentSchemaIdWithNoParentStorePropertiesIdAndAuths.
@Test
public void shouldThrowExceptionWithParentSchemaIdWithNoParentStorePropertiesIdAndAuths(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(GRAPH_ID + 2, opAuths);
idAuths.put(SCHEMA_ID_1, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentSchemaIds(SCHEMA_ID_1).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("parentStorePropertiesId must be specified with parentSchemaId");
}
use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldCreateGraphWithGraphIdInLibraryAndAuths.
@Test
public void shouldCreateGraphWithGraphIdInLibraryAndAuths(@TempDir Path tmpPath) {
// Given
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
graphLibrary.addOrUpdate(GRAPH_ID + 1, schema, storeProperties);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> graphIdAuths = new ArrayList<>();
graphIdAuths.add("auth1");
idAuths.put(GRAPH_ID + 1, graphIdAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 1).build();
// When
Graph graph = createGraph(export);
// Then
assertEquals(GRAPH_ID + 1, graph.getGraphId());
assertEquals(schema, graph.getSchema());
assertEquals(storeProperties, graph.getStoreProperties());
}
use of uk.gov.gchq.gaffer.store.library.FileGraphLibrary in project Gaffer by gchq.
the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentSchemaIdAndStorePropertiesIdAndNoSchemaAuths.
@Test
public void shouldThrowExceptionWithParentSchemaIdAndStorePropertiesIdAndNoSchemaAuths(@TempDir Path tmpPath) {
GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
// Given
Schema schema1 = new Schema.Builder().build();
graphLibrary.addOrUpdate(GRAPH_ID + 1, SCHEMA_ID, schema, STORE_PROPS_ID, storeProperties);
graphLibrary.addSchema(SCHEMA_ID_1, schema1);
given(store.getGraphLibrary()).willReturn(graphLibrary);
List<String> opAuths = Lists.newArrayList("auth1");
idAuths.put(GRAPH_ID + 2, opAuths);
idAuths.put(STORE_PROPS_ID, opAuths);
final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentSchemaIds(SCHEMA_ID_1).parentStorePropertiesId(STORE_PROPS_ID).build();
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("User is not authorised to export using schemaId");
}
Aggregations