Search in sources :

Example 21 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class LoadAndQuery3Test method shouldReturnExpectedEdgesViaJson.

@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
    // Given
    final User user = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
    final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
    // Setup graph
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
    // When
    // Execute the add operation chain on the graph
    graph.execute(addElements, user);
    // Execute the query operation on the graph.
    final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
    // Then
    verifyResults(results);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 22 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class LoadAndQuery4Test method shouldReturnExpectedEdgesViaJson.

@Test
public void shouldReturnExpectedEdgesViaJson() throws OperationException, SerialisationException {
    // Given
    final User user = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final AddElements addElements = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), AddElements.class);
    final GetEdges<?> getRelatedEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetEdges.class);
    // Setup graph
    final Graph graph = new Graph.Builder().storeProperties(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_PREFIX + "mockaccumulostore.properties")).addSchemas(StreamUtil.openStreams(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "schema")).build();
    // When
    // Execute the add operation chain on the graph
    graph.execute(addElements, user);
    // Execute the query operation on the graph.
    final CloseableIterable<Edge> results = graph.execute(getRelatedEdges, user);
    // Then
    verifyResults(results);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Example 23 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project Gaffer by gchq.

the class ArrayListStoreTest method addElementsToGraph.

private void addElementsToGraph(final Graph graph) throws OperationException {
    final OperationChain<Void> opChain = new OperationChain.Builder().first(new GenerateElements.Builder<>().objects(getDomainObjects()).generator(new SimpleGenerator()).build()).then(new AddElements()).build();
    // execute the operation
    graph.execute(opChain, new User());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) SimpleGenerator(uk.gov.gchq.gaffer.arrayliststore.data.generator.SimpleGenerator)

Example 24 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project gaffer-doc by gchq.

the class FederatedStoreWalkThrough method run.

public CloseableIterable<? extends Element> run() throws Exception {
    final Schema schema = new Schema.Builder().json(StreamUtil.openStreams(getClass(), schemaPath)).build();
    final HashMapGraphLibrary library = new HashMapGraphLibrary();
    library.addProperties("mapStore", getMapStoreProperties());
    library.addProperties("accumuloStore", getAccumuloStoreProperties());
    library.addSchema("roadTraffic", schema);
    // [creating a federatedstore] create a store that federates to a MapStore and AccumuloStore
    // ---------------------------------------------------------
    final Graph federatedGraph = new Graph.Builder().config(new GraphConfig.Builder().graphId(getClass().getSimpleName()).library(library).build()).storeProperties(getFederatedStoreProperties()).build();
    // ---------------------------------------------------------
    // [federatedstore properties]
    // ---------------------------------------------------------
    final FederatedStoreProperties exampleFederatedProperty = new FederatedStoreProperties();
    exampleFederatedProperty.setCacheProperties(HashMapCacheService.class.getName());
    // ---------------------------------------------------------
    printJson("FED_PROP", getFederatedStoreProperties());
    final User user = new User("user01");
    final AddGraph addMapGraph = new AddGraph.Builder().graphId("mapGraph").schema(new Schema.Builder().json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/entities.json")).json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json")).build()).storeProperties(getMapStoreProperties()).isPublic(true).build();
    federatedGraph.execute(addMapGraph, user);
    final AddGraph addAccumuloGraph = new AddGraph.Builder().graphId("accumuloGraph").schema(new Schema.Builder().json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/edges.json")).json(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalitiesForFederatedStore/schema/types.json")).build()).storeProperties(getAccumuloStoreProperties()).isPublic(true).build();
    federatedGraph.execute(addAccumuloGraph, user);
    // [add another graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph addAnotherGraph = new AddGraph.Builder().graphId("AnotherGraph").schema(schema).storeProperties(getMapStoreProperties()).build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(addAnotherGraph);
    addAccumuloGraph.setGraphAuths(null);
    printJson("ADD_GRAPH", addAnotherGraph);
    // [remove graph] remove a graph from the federated store.
    // ---------------------------------------------------------
    RemoveGraph removeGraph = new RemoveGraph.Builder().graphId("AnotherGraph").build();
    federatedGraph.execute(removeGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(removeGraph);
    printJson("REMOVE_GRAPH", removeGraph);
    // [get all graph ids] Get a list of all the graphId within the FederatedStore.
    // ---------------------------------------------------------
    final GetAllGraphIds getAllGraphIDs = new GetAllGraphIds();
    Iterable<? extends String> graphIds = federatedGraph.execute(getAllGraphIDs, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(getAllGraphIDs);
    printJson("GET_ALL_GRAPH_IDS", getAllGraphIDs);
    print("GRAPH_IDS", graphIds.toString());
    // [add elements] Create a data generator and add the edges to the federated graphs using an operation chain consisting of:
    // generateElements - generating edges from the data (note these are directed edges)
    // addElements - add the edges to the graph
    // ---------------------------------------------------------
    final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalities/data.txt"))).build()).then(new AddElements()).build();
    federatedGraph.execute(addOpChain, user);
    // ---------------------------------------------------------
    printJsonAndPython("ADD_ELEMENTS", addOpChain);
    // [get elements]
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<? extends Element>> getOpChain = new OperationChain.Builder().first(new GetElements.Builder().input(new EntitySeed("10")).build()).build();
    CloseableIterable<? extends Element> elements = federatedGraph.execute(getOpChain, user);
    for (final Element element : elements) {
        print("ELEMENTS", element.toString());
    }
    printJsonAndPython("GET_ELEMENTS", getOpChain);
    // [get elements from accumulo graph]
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<? extends Element>> getOpChainOnAccumuloGraph = new OperationChain.Builder().first(new GetElements.Builder().input(new EntitySeed("10")).option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "accumuloGraph").build()).build();
    CloseableIterable<? extends Element> elementsFromAccumuloGraph = federatedGraph.execute(getOpChainOnAccumuloGraph, user);
    for (final Element element : elementsFromAccumuloGraph) {
        print("ELEMENTS_FROM_ACCUMULO_GRAPH", element.toString());
    }
    // [select graphs for operations]
    // ---------------------------------------------------------
    GetAllElements selectGraphsForOperations = new Builder().option(FederatedStoreConstants.KEY_OPERATION_OPTIONS_GRAPH_IDS, "graphId1, graphId2").build();
    // ---------------------------------------------------------
    printJsonAndPython("SELECT_GRAPHS_FOR_OPERATIONS", selectGraphsForOperations);
    // [do not skip failed execution]
    // ---------------------------------------------------------
    GetAllElements doNotSkipFailedExecution = new Builder().option(FederatedStoreConstants.KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE, "false").build();
    // ---------------------------------------------------------
    printJsonAndPython("DO_NOT_SKIP_FAILED_EXECUTION", doNotSkipFailedExecution);
    // [add public graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph publicGraph = new AddGraph.Builder().graphId("publicGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").isPublic(// <-- public access
    true).graphAuths(// <-- used but irrelevant as graph has public access
    "Auth1").build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(publicGraph);
    printJson("ADD_PUBLIC_GRAPH", publicGraph);
    // [add private graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph privateGraph = new AddGraph.Builder().graphId("privateGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").build();
    federatedGraph.execute(addAnotherGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(privateGraph);
    printJson("ADD_PRIVATE_GRAPH", privateGraph);
    // [add secure graph] add a graph to the federated store.
    // ---------------------------------------------------------
    AddGraph addSecureGraph = new AddGraph.Builder().graphId("SecureGraph").parentSchemaIds(Lists.newArrayList("roadTraffic")).parentPropertiesId("mapStore").graphAuths("Auth1", "Auth2", "Auth3").build();
    federatedGraph.execute(addSecureGraph, user);
    // ---------------------------------------------------------
    improveReadabilityOfJson(addSecureGraph);
    printJson("ADD_SECURE_GRAPH", addSecureGraph);
    // [disallow public access]
    // ---------------------------------------------------------
    FederatedStoreProperties disallowPublicProperties = new FederatedStoreProperties();
    disallowPublicProperties.setGraphsCanHavePublicAccess(false);
    // ---------------------------------------------------------
    printJson("DISALLOW_PUBLIC_ACCESS", disallowPublicProperties.getProperties());
    // [limit custom properties]
    // ---------------------------------------------------------
    FederatedStoreProperties limitCustomProperties = new FederatedStoreProperties();
    limitCustomProperties.setCustomPropertyAuths("Auth1, Auth2, Auth3");
    // ---------------------------------------------------------
    printJson("LIMIT_CUSTOM_PROPERTIES", limitCustomProperties.getProperties());
    return elements;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) FederatedStoreProperties(uk.gov.gchq.gaffer.federatedstore.FederatedStoreProperties) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Builder(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements.Builder) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashMapCacheService(uk.gov.gchq.gaffer.cache.impl.HashMapCacheService) GetAllGraphIds(uk.gov.gchq.gaffer.federatedstore.operation.GetAllGraphIds) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) HashMapGraphLibrary(uk.gov.gchq.gaffer.store.library.HashMapGraphLibrary) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Graph(uk.gov.gchq.gaffer.graph.Graph) RemoveGraph(uk.gov.gchq.gaffer.federatedstore.operation.RemoveGraph) AddGraph(uk.gov.gchq.gaffer.federatedstore.operation.AddGraph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 25 with AddElements

use of uk.gov.gchq.gaffer.operation.impl.add.AddElements in project gaffer-doc by gchq.

the class Visibilities method run.

public CloseableIterable<? extends Element> run() throws OperationException, IOException {
    // / [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
    // ---------------------------------------------------------
    // [user] Create a user
    // ---------------------------------------------------------
    final User basicUser = new User("user01");
    // ---------------------------------------------------------
    // [add] Create a data generator and add the edges to the graph using an operation chain consisting of:
    // generateElements - generating edges from the data (note these are directed edges)
    // addElements - add the edges to the graph
    // ---------------------------------------------------------
    final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseWithSecurityElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithSecurity/data.txt"))).build()).then(new AddElements()).build();
    graph.execute(addOpChain, basicUser);
    // ---------------------------------------------------------
    print("\nNow run a simple query to get edges\n");
    // [get simple] get all the edges that contain the vertex "10" or "23"
    // ---------------------------------------------------------
    final GetElements getEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
    final CloseableIterable<? extends Element> resultsWithBasicUser = graph.execute(getEdges, basicUser);
    // ---------------------------------------------------------
    for (final Element e : resultsWithBasicUser) {
        print("GET_ELEMENTS_RESULT", e.toString());
    }
    print("We get nothing back");
    print("\nGet edges with the public visibility. We shouldn't see any of the private ones.\n");
    // [get public] get all the edges that contain the vertex "10" or "23"
    // ---------------------------------------------------------
    final User publicUser = new User.Builder().userId("publicUser").dataAuth("public").build();
    final GetElements getPublicRelatedEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
    final CloseableIterable<? extends Element> publicResults = graph.execute(getPublicRelatedEdges, publicUser);
    // ---------------------------------------------------------
    for (final Element e : publicResults) {
        print("GET_PUBLIC_EDGES_RESULT", e.toString());
    }
    print("\nGet edges with the private visibility. We should get the public edges too.\n");
    // [get private] get all the edges that contain the vertex "10" or "23"
    // ---------------------------------------------------------
    final User privateUser = new User.Builder().userId("privateUser").dataAuth("private").build();
    final GetElements getPrivateRelatedEdges = new GetElements.Builder().input(new EntitySeed("10"), new EntitySeed("23")).view(new View.Builder().edge("RoadUse").build()).build();
    final CloseableIterable<? extends Element> privateResults = graph.execute(getPrivateRelatedEdges, privateUser);
    // ---------------------------------------------------------
    for (final Element e : privateResults) {
        print("GET_PRIVATE_EDGES_RESULT", e.toString());
    }
    return publicResults;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) RoadAndRoadUseWithSecurityElementGenerator(uk.gov.gchq.gaffer.doc.dev.generator.RoadAndRoadUseWithSecurityElementGenerator)

Aggregations

AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)157 Graph (uk.gov.gchq.gaffer.graph.Graph)99 User (uk.gov.gchq.gaffer.user.User)98 Element (uk.gov.gchq.gaffer.data.element.Element)88 Test (org.junit.jupiter.api.Test)74 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)72 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)63 Edge (uk.gov.gchq.gaffer.data.element.Edge)62 Entity (uk.gov.gchq.gaffer.data.element.Entity)51 ArrayList (java.util.ArrayList)49 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)47 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)47 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)39 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)37 OperationException (uk.gov.gchq.gaffer.operation.OperationException)36 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)35 IsMoreThan (uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)35 Test (org.junit.Test)30 Set (java.util.Set)28