use of uk.gov.gchq.gaffer.named.view.AddNamedView in project gaffer-doc by gchq.
the class AddNamedViewExample method addNamedViewWithParameter.
public void addNamedViewWithParameter() {
// ---------------------------------------------------------
final String viewJson = "{\"edges\" : {\n" + " \"testEdge\" : {\n" + " \"preAggregationFilterFunctions\" : [ {\n" + " \"selection\" : [ \"count\" ],\n" + " \"predicate\" : {\n" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsMoreThan\",\n" + " \"orEqualTo\" : false,\n" + " \"value\" : \"${countThreshold}\"\n" + " }\n" + " } ]\n" + " }\n" + "}}";
final ViewParameterDetail param = new ViewParameterDetail.Builder().defaultValue(1L).description("count threshold").valueClass(Long.class).build();
final Map<String, ViewParameterDetail> paramMap = Maps.newHashMap();
paramMap.put("countThreshold", param);
final AddNamedView op = new AddNamedView.Builder().name("isMoreThan").description("example test NamedView").overwrite(true).view(viewJson).parameters(paramMap).writeAccessRoles("auth1").build();
// ---------------------------------------------------------
runExampleNoResult(op, null);
try {
getGraph().execute(new DeleteNamedView.Builder().name("isMoreThan").build(), createContext());
} catch (final OperationException e) {
throw new RuntimeException("Unable to delete named view: isMoreThan", e);
}
}
use of uk.gov.gchq.gaffer.named.view.AddNamedView in project gaffer-doc by gchq.
the class AddNamedViewExample method addNamedView.
public void addNamedView() {
// ---------------------------------------------------------
final AddNamedView op = new AddNamedView.Builder().name("isMoreThan10").description("example test NamedView").overwrite(true).view(new View.Builder().edge("testEdge", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("count").execute(new IsMoreThan(10)).build()).build()).build()).build();
// ---------------------------------------------------------
runExampleNoResult(op, null);
try {
getGraph().execute(new DeleteNamedView.Builder().name("isMoreThan10").build(), createContext());
} catch (final OperationException e) {
throw new RuntimeException("Unable to delete named view: isMoreThan", e);
}
}
use of uk.gov.gchq.gaffer.named.view.AddNamedView in project Gaffer by gchq.
the class DeleteNamedViewHandlerTest method before.
@BeforeEach
public void before() throws OperationException {
properties.set("gaffer.cache.service.class", "uk.gov.gchq.gaffer.cache.impl.HashMapCacheService");
CacheServiceLoader.initialise(properties.getProperties());
given(store.getProperties()).willReturn(new StoreProperties());
testParameters.put("testParam", mock(ViewParameterDetail.class));
view = new View.Builder().edge(TestGroups.EDGE).build();
addNamedView = new AddNamedView.Builder().name(testNamedViewName).view(view).writeAccessRoles(WRITE_ACCESS_ROLE).overwrite(false).build();
addNamedViewHandler.doOperation(addNamedView, context, store);
}
use of uk.gov.gchq.gaffer.named.view.AddNamedView in project Gaffer by gchq.
the class GraphHooksIT method shouldResolveNamedViewWithinNamedOperation.
@Test
public void shouldResolveNamedViewWithinNamedOperation() throws OperationException {
// Given
final Edge edge1 = getEdges().get(new EdgeSeed(SOURCE_1, DEST_1, false)).emptyClone();
edge1.putProperty(TestPropertyNames.INT, 100);
final Edge edge2 = edge1.emptyClone();
edge2.putProperty(TestPropertyNames.INT, 101);
graph.execute(new AddElements.Builder().input(edge1, edge2).build(), getUser());
final AddNamedView addNamedView = new AddNamedView.Builder().name("Test View").view(new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsIn(Arrays.asList((Object) 100))).build()).build()).build()).overwrite(true).build();
graph.execute(addNamedView, getUser());
final AddNamedOperation addNamedOperation = new AddNamedOperation.Builder().operationChain(new OperationChain.Builder().first(new GetAllElements.Builder().view(new NamedView.Builder().name("Test View").build()).build()).build()).description("named operation GetAllElements test query").name("GetAllElements test").labels(Arrays.asList("label 1", "Label 2")).overwrite(true).build();
graph.execute(addNamedOperation, getUser());
final NamedOperation<EntityId, CloseableIterable<? extends Element>> operation = new NamedOperation.Builder<EntityId, CloseableIterable<? extends Element>>().name("GetAllElements test").input(new EntitySeed("10")).build();
// When
final CloseableIterable<? extends Element> results = graph.execute(operation, getUser());
// Then
final List<Element> resultList = Lists.newArrayList(results);
assertThat(resultList).hasSize(1).contains((Element) edge1);
}
use of uk.gov.gchq.gaffer.named.view.AddNamedView in project gaffer-doc by gchq.
the class NamedViews method run.
@Override
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);
// ---------------------------------------------------------
// [add named view] add a NamedView to be reused
// ---------------------------------------------------------
final AddNamedView addNamedView = new AddNamedView.Builder().name("RoadUse edges").description("NamedView to get only RoadUse edges").view(new View.Builder().edge("RoadUse").build()).overwrite(false).build();
// ---------------------------------------------------------
printJsonAndPython("ADD_NAMED_VIEW", addNamedView);
graph.execute(addNamedView, user);
// [get all named views] Get all named views
// ---------------------------------------------------------
final GetAllNamedViews getAllNamedViews = new GetAllNamedViews();
// ---------------------------------------------------------
printJsonAndPython("GET_ALL_NAMED_VIEWS", new GetAllNamedViews());
final CloseableIterable<NamedViewDetail> namedViewDetails = graph.execute(getAllNamedViews, user);
for (final NamedViewDetail detail : namedViewDetails) {
print("ALL_NAMED_VIEW", detail.toString());
}
// [get elements with named view] create the operation using the NamedView
// ---------------------------------------------------------
final GetElements operation = new GetElements.Builder().view(new NamedView.Builder().name("RoadUse edges").build()).input(new EntitySeed("10")).build();
// ---------------------------------------------------------
printJsonAndPython("GET_ELEMENTS_WITH_NAMED_VIEW", operation);
final CloseableIterable<? extends Element> namedViewResults = graph.execute(operation, user);
for (final Object result : namedViewResults) {
print("GET_ELEMENTS_WITH_NAMED_VIEW_RESULTS", result.toString());
}
// [add named view with parameters] create an operation chain to be executed as a named operation
// with parameters
// ---------------------------------------------------------
final String viewJson = "{" + " \"edges\" : {" + " \"RoadUse\" : { " + " \"preAggregationFilterFunctions\" : [ {" + " \"predicate\" : {" + " \"class\" : \"uk.gov.gchq.koryphe.impl.predicate.IsMoreThan\"," + " \"orEqualTo\" : false," + " \"value\": {" + " \"java.lang.Long\" : \"${isMoreThan}\"" + " }" + " }," + " \"selection\" : [ \"${property}\" ]" + " } ] }" + " }," + " \"entities\" : { }" + "}";
final ViewParameterDetail propertyParam = new ViewParameterDetail.Builder().description("Property to select").valueClass(String.class).required(true).build();
final ViewParameterDetail valueParam = new ViewParameterDetail.Builder().description("Value for the is more than predicate").defaultValue(0L).valueClass(Long.class).build();
final Map<String, ViewParameterDetail> paramDetailMap = Maps.newHashMap();
paramDetailMap.put("property", propertyParam);
paramDetailMap.put("isMoreThan", valueParam);
final AddNamedView addNamedViewWithParams = new AddNamedView.Builder().name("customCountView").description("named View with count param").view(viewJson).parameters(paramDetailMap).overwrite(true).build();
// ---------------------------------------------------------
printJsonAndPython("ADD_NAMED_VIEW_WITH_PARAMETERS", addNamedViewWithParams);
graph.execute(addNamedViewWithParams, user);
// [get elements with named view with parameters] create the named operation with a parameter
// ---------------------------------------------------------
final Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("property", "count");
paramMap.put("isMoreThan", 1L);
final GetElements operationUsingParams = new GetElements.Builder().view(new NamedView.Builder().name("customCountView").parameters(paramMap).build()).input(new EntitySeed("10")).build();
// ---------------------------------------------------------
printJsonAndPython("GET_ELEMENTS_WITH_NAMED_VIEW_WITH_PARAMETERS", operationUsingParams);
final CloseableIterable<? extends Element> namedViewResultsWithParams = graph.execute(operationUsingParams, user);
for (final Object result : namedViewResultsWithParams) {
print("GET_ELEMENTS_WITH_NAMED_VIEW_WITH_PARAMETERS_RESULTS", result.toString());
}
return namedViewResultsWithParams;
}
Aggregations