Search in sources :

Example 1 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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.");
}
Also used : AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)

Example 2 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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.");
}
Also used : AccumuloProperties(uk.gov.gchq.gaffer.accumulostore.AccumuloProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Element(uk.gov.gchq.gaffer.data.element.Element) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) TypeDefinition(uk.gov.gchq.gaffer.store.schema.TypeDefinition) ExportToOtherGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) IsTrue(uk.gov.gchq.koryphe.impl.predicate.IsTrue) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)

Example 3 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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");
}
Also used : ExportToOtherAuthorisedGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.jupiter.api.Test)

Example 4 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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());
}
Also used : ExportToOtherAuthorisedGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph) Graph(uk.gov.gchq.gaffer.graph.Graph) ExportToOtherAuthorisedGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 5 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary 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");
}
Also used : ExportToOtherAuthorisedGraph(uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) FileGraphLibrary(uk.gov.gchq.gaffer.store.library.FileGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Test(org.junit.jupiter.api.Test)

Aggregations

GraphLibrary (uk.gov.gchq.gaffer.store.library.GraphLibrary)26 Test (org.junit.jupiter.api.Test)17 Schema (uk.gov.gchq.gaffer.store.schema.Schema)14 FileGraphLibrary (uk.gov.gchq.gaffer.store.library.FileGraphLibrary)13 ExportToOtherAuthorisedGraph (uk.gov.gchq.gaffer.operation.export.graph.ExportToOtherAuthorisedGraph)9 Graph (uk.gov.gchq.gaffer.graph.Graph)7 HashMapGraphLibrary (uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary)7 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)5 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)5 AccumuloProperties (uk.gov.gchq.gaffer.accumulostore.AccumuloProperties)3 SchemaException (uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException)3 GraphHook (uk.gov.gchq.gaffer.graph.hook.GraphHook)3 StoreException (uk.gov.gchq.gaffer.store.StoreException)3 ArrayList (java.util.ArrayList)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 FederatedGetTraitsHandlerTest (uk.gov.gchq.gaffer.federatedstore.operation.handler.impl.FederatedGetTraitsHandlerTest)2 FunctionAuthoriser (uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser)2 NamedViewResolver (uk.gov.gchq.gaffer.graph.hook.NamedViewResolver)2 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)2 OperationException (uk.gov.gchq.gaffer.operation.OperationException)2