Search in sources :

Example 1 with AddNamedView

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);
    }
}
Also used : ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 2 with AddNamedView

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);
    }
}
Also used : DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 3 with AddNamedView

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);
}
Also used : ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) DeleteNamedView(uk.gov.gchq.gaffer.named.view.DeleteNamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with AddNamedView

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) AddNamedOperation(uk.gov.gchq.gaffer.named.operation.AddNamedOperation) Test(org.junit.Test)

Example 5 with AddNamedView

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;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator(uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator) ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) GetAllNamedViews(uk.gov.gchq.gaffer.named.view.GetAllNamedViews) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) AddNamedView(uk.gov.gchq.gaffer.named.view.AddNamedView) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Aggregations

AddNamedView (uk.gov.gchq.gaffer.named.view.AddNamedView)7 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)4 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)4 ViewParameterDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail)3 DeleteNamedView (uk.gov.gchq.gaffer.named.view.DeleteNamedView)3 OperationException (uk.gov.gchq.gaffer.operation.OperationException)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)2 StoreProperties (uk.gov.gchq.gaffer.store.StoreProperties)2 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)1 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)1 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)1 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator)1