Search in sources :

Example 6 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class ExportToOtherAuthorisedGraphHandlerTest method shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths.

@Test
public void shouldThrowExceptionWithParentStorePropertiesIdWithNoParentSchemaIdAndAuths(@TempDir Path tmpPath) {
    GraphLibrary graphLibrary = new FileGraphLibrary(tmpPath.toString());
    // Given
    Schema schema1 = new Schema.Builder().build();
    graphLibrary.addOrUpdate(GRAPH_ID + 1, schema, 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);
    idAuths.put(STORE_PROPS_ID, opAuths);
    final ExportToOtherAuthorisedGraph export = new ExportToOtherAuthorisedGraph.Builder().graphId(GRAPH_ID + 2).parentStorePropertiesId(STORE_PROPS_ID).build();
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> createGraph(export)).withMessageContaining("parentSchemaIds must be specified with parentStorePropertiesId");
}
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 7 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class FederatedAddGraphWithHooksHandlerTest method shouldAddGraphUsingLibrary.

@Test
public void shouldAddGraphUsingLibrary() throws Exception {
    store.initialise(FEDERATEDSTORE_GRAPH_ID, null, federatedStoreProperties);
    Schema expectedSchema = new Schema.Builder().build();
    assertEquals(0, store.getGraphs(testUser, null, ignore).size());
    assertEquals(0, store.getGraphs(testUser, null, ignore).size());
    FederatedAddGraphWithHooksHandler federatedAddGraphWithHooksHandler = new FederatedAddGraphWithHooksHandler();
    federatedAddGraphWithHooksHandler.doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID).schema(expectedSchema).storeProperties(PROPERTIES).build(), new Context(testUser), store);
    Collection<Graph> graphs = store.getGraphs(testUser, null, ignore);
    assertThat(graphs).hasSize(1);
    Graph next = graphs.iterator().next();
    assertEquals(EXPECTED_GRAPH_ID, next.getGraphId());
    assertEquals(expectedSchema, next.getSchema());
    final GraphLibrary library = new HashMapGraphLibrary();
    library.add(EXPECTED_GRAPH_ID_3, expectedSchema, PROPERTIES);
    store.setGraphLibrary(library);
    federatedAddGraphWithHooksHandler.doOperation(new AddGraphWithHooks.Builder().graphId(EXPECTED_GRAPH_ID_3).build(), new Context(testUser), store);
    graphs = store.getGraphs(testUser, null, ignore);
    assertThat(graphs).hasSize(2);
    Iterator<Graph> iterator = graphs.iterator();
    final HashSet<String> set = Sets.newHashSet();
    while (iterator.hasNext()) {
        set.add(iterator.next().getGraphId());
    }
    assertThat(set).contains(EXPECTED_GRAPH_ID, EXPECTED_GRAPH_ID_3);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) AddGraphWithHooks(uk.gov.gchq.gaffer.federatedstore.operation.AddGraphWithHooks) Graph(uk.gov.gchq.gaffer.graph.Graph) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) Test(org.junit.jupiter.api.Test)

Example 8 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class GraphTest method shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig.

@Test
public void shouldBuildGraphFromConfigAndMergeConfigWithExistingConfig() throws Exception {
    // Given
    final StoreProperties storeProperties = new StoreProperties();
    storeProperties.setStoreClass(TestStoreImpl.class.getName());
    final String graphId1 = "graphId1";
    final String graphId2 = "graphId2";
    final GraphLibrary library1 = mock(GraphLibrary.class);
    final GraphLibrary library2 = mock(GraphLibrary.class);
    final View view1 = new View.Builder().entity(TestGroups.ENTITY).build();
    final View view2 = new View.Builder().edge(TestGroups.EDGE).build();
    final GraphHook hook1 = mock(GraphHook.class);
    final GraphHook hook2 = mock(GraphHook.class);
    final GraphHook hook3 = mock(GraphHook.class);
    // When
    final GraphConfig config = new GraphConfig.Builder().graphId(graphId2).library(library2).addHook(hook2).view(view2).build();
    final Graph graph = new Graph.Builder().graphId(graphId1).library(library1).view(view1).storeProperties(storeProperties).addSchemas(StreamUtil.schemas(getClass())).addHook(hook1).config(config).addHook(hook3).build();
    // Then
    assertEquals(graphId2, graph.getGraphId());
    assertEquals(view2, graph.getView());
    assertEquals(library2, graph.getGraphLibrary());
    assertEquals(Arrays.asList(NamedViewResolver.class, hook1.getClass(), hook2.getClass(), hook3.getClass(), FunctionAuthoriser.class), graph.getGraphHooks());
}
Also used : GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 9 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class GraphConfigTest method getTestObject.

@Override
protected GraphConfig getTestObject() {
    final String graphId = "graphId";
    final GraphLibrary library = new HashMapGraphLibrary();
    final View view = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).build();
    final GraphHook hook1 = new AddOperationsToChain();
    final GraphHook hook2 = new OperationChainLimiter();
    return new GraphConfig.Builder().graphId(graphId).library(library).description("testGraphConfig").addHook(hook1).addHook(hook2).view(view).build();
}
Also used : HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) AddOperationsToChain(uk.gov.gchq.gaffer.graph.hook.AddOperationsToChain) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationChainLimiter(uk.gov.gchq.gaffer.graph.hook.OperationChainLimiter)

Example 10 with GraphLibrary

use of uk.gov.gchq.gaffer.store.library.GraphLibrary in project Gaffer by gchq.

the class GraphDelegate method createGraphSerialisable.

public GraphSerialisable createGraphSerialisable(final Store store, final String graphId, final Schema schema, final StoreProperties storeProperties, final List<String> parentSchemaIds, final String parentStorePropertiesId, final GraphHook[] hooks) {
    final GraphLibrary graphLibrary = store.getGraphLibrary();
    final Pair<Schema, StoreProperties> existingGraphPair = null != graphLibrary ? graphLibrary.get(graphId) : null;
    validateGraph(store, graphId, schema, storeProperties, parentSchemaIds, parentStorePropertiesId, existingGraphPair);
    final Schema resolvedSchema = resolveSchemaForGraph(store, schema, parentSchemaIds, existingGraphPair);
    final StoreProperties resolvedStoreProperties = resolveStorePropertiesForGraph(store, storeProperties, parentStorePropertiesId, existingGraphPair);
    return new GraphSerialisable.Builder().config(new GraphConfig.Builder().graphId(graphId).library(graphLibrary).addHooks(hooks).build()).schema(resolvedSchema).properties(resolvedStoreProperties).build();
}
Also used : GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Schema(uk.gov.gchq.gaffer.store.schema.Schema) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties)

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