Search in sources :

Example 26 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class AddElementsExample method addElements.

public void addElements() throws OperationException {
    log("#### " + getMethodNameAsSentence(0) + "\n");
    printGraph();
    final AddElements operation = new AddElements.Builder().elements(new Entity.Builder().group("entity").vertex(6).property("count", 1).build(), new Edge.Builder().group("edge").source(5).dest(6).directed(true).property("count", 1).build()).build();
    printJava("new AddElements.Builder()\n" + "                .elements(new Entity.Builder()\n" + "                                .group(\"entity\")\n" + "                                .vertex(6)\n" + "                                .property(\"count\", 1)\n" + "                                .build(),\n" + "                        new Edge.Builder()\n" + "                                .group(\"edge\")\n" + "                                .source(5).dest(6).directed(true)\n" + "                                .property(\"count\", 1)\n" + "                                .build())\n" + "                .build();");
    printAsJson(operation);
    printOperationClass(operation);
    getGraph().execute(operation, new User("user01"));
    log("Updated graph:");
    log("```");
    log("    --> 4 <--");
    log("  /     ^     \\");
    log(" /      |      \\");
    log("1  -->  2  -->  3");
    log("         \\");
    log("           -->  5  -->  6");
    log("```");
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User)

Example 27 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class OperationExample method runExampleNoResult.

protected void runExampleNoResult(final Operation<?, Void> operation) {
    log("#### " + getMethodNameAsSentence(1) + "\n");
    printJava(JavaSourceUtil.getRawJavaSnippet(getClass(), "example/example-graph", " " + getMethodName(1) + "() {", String.format("---%n"), "// ----"));
    printAsJson(operation);
    printOperationClass(operation);
    try {
        getGraph().execute(operation, new User("user01"));
    } catch (OperationException e) {
        throw new RuntimeException(e);
    }
    log(METHOD_DIVIDER);
}
Also used : User(uk.gov.gchq.gaffer.user.User) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 28 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class LoadAndQuery6Test method shouldReturnExpectedStringsViaJson.

@Test
public void shouldReturnExpectedStringsViaJson() throws OperationException, SerialisationException {
    // Given
    final User user01 = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
    final OperationChain<CloseableIterable<String>> queryOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), OperationChain.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(addOpChain, user01);
    // Execute the query operation on the graph.
    final CloseableIterable<String> results = graph.execute(queryOpChain, user01);
    // Then
    verifyResults(results);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Test(org.junit.Test)

Example 29 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class LoadAndQuery7Test method shouldReturnExpectedStringsViaJson.

@Test
public void shouldReturnExpectedStringsViaJson() throws OperationException, SerialisationException {
    // Given
    final User user01 = new User("user01");
    final JSONSerialiser serialiser = new JSONSerialiser();
    final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
    final OperationChain<Iterable<Edge>> queryOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), OperationChain.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(addOpChain, user01);
    // Execute the query operation on the graph.
    final Iterable<Edge> results = graph.execute(queryOpChain, user01);
    // Then
    verifyResults(results);
}
Also used : 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 30 with User

use of uk.gov.gchq.gaffer.user.User in project Gaffer by gchq.

the class LoadAndQuery8Test method shouldReturnExpectedStringsViaJson.

@Test
public void shouldReturnExpectedStringsViaJson() throws OperationException, SerialisationException {
    // Given
    final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
    final JSONSerialiser serialiser = new JSONSerialiser();
    final OperationChain<?> addOpChain = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/load.json"), OperationChain.class);
    final GetAllEdges getAllEdges = serialiser.deserialise(StreamUtil.openStream(LoadAndQuery.class, RESOURCE_EXAMPLE_PREFIX + "json/query.json"), GetAllEdges.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(addOpChain, publicUser);
    // Execute the query operation on the graph.
    final Iterable<Edge> results = graph.execute(getAllEdges, publicUser);
    // Then
    verifyResults(results);
}
Also used : User(uk.gov.gchq.gaffer.user.User) Graph(uk.gov.gchq.gaffer.graph.Graph) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test)

Aggregations

User (uk.gov.gchq.gaffer.user.User)378 Test (org.junit.jupiter.api.Test)188 Graph (uk.gov.gchq.gaffer.graph.Graph)155 Element (uk.gov.gchq.gaffer.data.element.Element)143 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)128 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)110 HashSet (java.util.HashSet)109 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)104 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)103 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)98 Edge (uk.gov.gchq.gaffer.data.element.Edge)85 Context (uk.gov.gchq.gaffer.store.Context)85 Entity (uk.gov.gchq.gaffer.data.element.Entity)77 Test (org.junit.Test)61 ArrayList (java.util.ArrayList)57 OperationException (uk.gov.gchq.gaffer.operation.OperationException)52 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)49 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)48 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)45 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)43