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;
}
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;
}
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);
}
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
}
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();
}
Aggregations