Search in sources :

Example 56 with User

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

the class Views 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 user = 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 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalities/data.txt"))).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    print("The elements have been added.");
    // [view with groups]
    // ---------------------------------------------------------
    final View viewWithGroups = new View.Builder().edge("RoadUse").edge("RoadHasJunction").entity("Cardinality").build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GROUPS", viewWithGroups);
    // [view with filters]
    // ---------------------------------------------------------
    final View viewWithFilters = new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2L)).build()).build()).entity("Cardinality", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(5L)).select("hllp").execute(new HyperLogLogPlusIsLessThan(10L)).build()).build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_FILTERS", viewWithFilters);
    // [view with removed properties]
    // ---------------------------------------------------------
    final View viewWithRemovedProperties = new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().properties("count").build()).entity("Cardinality", new ViewElementDefinition.Builder().excludeProperties("hllp", "edgeGroups").build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_REMOVED_PROPERTIES", viewWithRemovedProperties);
    // [view with global filter] run query with a global filter to return only elements with a count more than 2
    // ---------------------------------------------------------
    final View viewWithGlobalFilter = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2L)).build()).build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_FILTER", viewWithGlobalFilter);
    // [view with global and specific filters]
    // ---------------------------------------------------------
    final View globalAndSpecificView = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(0L)).build()).build()).edge("RoadUse", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2L)).build()).build()).entity("Cardinality").build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_AND_SPECIFIC_FILTERS", globalAndSpecificView);
    // [view with global and specific filters expanded]
    // ---------------------------------------------------------
    final View globalAndSpecificViewExpanded = new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(2L)).select("count").execute(new IsMoreThan(0L)).build()).build()).entity("Cardinality", new ViewElementDefinition.Builder().postAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(0L)).build()).build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_AND_SPECIFIC_FILTERS_EXPANDED", globalAndSpecificViewExpanded);
    // [view with global removed properties]
    // ---------------------------------------------------------
    final View viewWithGlobalRemovedProperties = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().properties("count").build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_REMOVED_PROPERTIES", viewWithGlobalRemovedProperties);
    // [view with global and specific removed properties]
    // ---------------------------------------------------------
    final View viewWithGlobalAndSpecificRemovedProperties = new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().properties("count").build()).edge("RoadUse").entity("Cardinality", new ViewElementDefinition.Builder().properties("hllp").build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_AND_SPECIFIC_REMOVED_PROPERTIES", viewWithGlobalAndSpecificRemovedProperties);
    // [view with global and specific removed properties expanded]
    // ---------------------------------------------------------
    final View viewWithGlobalAndSpecificRemovedPropertiesExpanded = new View.Builder().edge("RoadUse", new ViewElementDefinition.Builder().properties("count").build()).entity("Cardinality", new ViewElementDefinition.Builder().properties("hllp").build()).build();
    // ---------------------------------------------------------
    printJsonAndPythonWithClass("VIEW_WITH_GLOBAL_AND_SPECIFIC_REMOVED_PROPERTIES_EXPANDED", viewWithGlobalAndSpecificRemovedPropertiesExpanded);
    return null;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) HyperLogLogPlusIsLessThan(uk.gov.gchq.gaffer.sketches.clearspring.cardinality.predicate.HyperLogLogPlusIsLessThan) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 57 with User

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

the class BoundedTimestampSetWalkthrough method run.

@Override
public CloseableIterable<? extends Element> run() throws OperationException {
    // / [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 user = new User("user01");
    // ---------------------------------------------------------
    // [add] addElements - add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new BoundedTimestampSetElementGenerator()).input(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    print("Added an edge A-B 3 times, each time with a BoundedTimestampSet containing a random time in 2017.");
    // [get] Get all edges
    // ---------------------------------------------------------
    CloseableIterable<? extends Element> allEdges = graph.execute(new GetAllElements(), user);
    // ---------------------------------------------------------
    print("\nAll edges:");
    for (final Element edge : allEdges) {
        print("GET_ALL_EDGES_RESULT", edge.toString());
    }
    return null;
}
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) BoundedTimestampSetElementGenerator(uk.gov.gchq.gaffer.doc.properties.generator.BoundedTimestampSetElementGenerator) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)

Example 58 with User

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

the class OperationAuthoriserTest method shouldReturnResultWithoutModification.

@Test
public void shouldReturnResultWithoutModification() {
    // Given
    final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
    final Object result = mock(Object.class);
    final OperationChain opChain = new OperationChain.Builder().first(new GenerateObjects<>()).build();
    final User user = new User.Builder().opAuths("NoScore").build();
    // When
    final Object returnedResult = hook.postExecute(result, opChain, new Context(user));
    // Then
    assertSame(result, returnedResult);
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) GenerateObjects(uk.gov.gchq.gaffer.operation.impl.generate.GenerateObjects) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.jupiter.api.Test)

Example 59 with User

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

the class OperationAuthoriserTest method shouldAcceptOperationChainWhenUserHasAllOpAuthsForAddNamedOperation.

@Test
public void shouldAcceptOperationChainWhenUserHasAllOpAuthsForAddNamedOperation() {
    // Given
    final OperationAuthoriser hook = fromJson(OP_AUTHS_PATH);
    final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain("{\"operations\":[{\"class\": \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\", \"options\": {\"optionKey\": \"${testParameter}\"}}]}").description("Test Named Operation").name("Test").overwrite(false).parameter("testParameter", new ParameterDetail.Builder().description("the seed").defaultValue("seed1").valueClass(String.class).required(false).build()).score(2).build();
    final OperationChain opChain = new OperationChain.Builder().first(addNamedOperation).build();
    final User user = new User.Builder().opAuths("SuperUser", "ReadUser", "User").build();
    // When
    hook.preExecute(opChain, new Context(user));
// Then - no exceptions
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) Test(org.junit.jupiter.api.Test)

Example 60 with User

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

the class UpdateViewHookTest method shouldNotMergeWithWrongUser.

@Test
public void shouldNotMergeWithWrongUser() throws Exception {
    updateViewHook.setViewToMerge(viewToMerge);
    updateViewHook.setWithOpAuth(Sets.newHashSet("opA"));
    opChain = new OperationChain<>(new GetAllElements());
    updateViewHook.preExecute(opChain, new Context(new User()));
    Object op = opChain.getOperations().get(0);
    assertThat(op).isInstanceOf(OperationView.class);
    assertThat(((OperationView) op).getView()).isNull();
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Test(org.junit.jupiter.api.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