Search in sources :

Example 6 with NamedViewDetail

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNamedViewAndMergeAnotherNamedView.

@Test
public void shouldResolveNamedViewAndMergeAnotherNamedView() throws CacheOperationFailedException {
    // Given
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    final NamedView namedViewToMerge = new NamedView.Builder().name(NAMED_VIEW_NAME + 1).edge(TestGroups.EDGE).build();
    final NamedViewDetail namedViewDetailToMerge = new NamedViewDetail.Builder().name(namedViewToMerge.getName()).view(namedViewToMerge).build();
    final View mergedView = new View.Builder().merge(FULL_VIEW).edge(TestGroups.EDGE).build();
    given(CACHE.getNamedView(NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willReturn(namedViewDetailToMerge);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(namedViewToMerge).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    GetElements getElements = (GetElements) opChain.getOperations().get(0);
    // Then
    JsonAssert.assertEquals(mergedView.toCompactJson(), getElements.getView().toCompactJson());
}
Also used : NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Example 7 with NamedViewDetail

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNamedViewWithParameter.

@Test
public void shouldResolveNamedViewWithParameter() throws CacheOperationFailedException {
    Map<String, Object> paramMap = Maps.newHashMap();
    paramMap.put(EDGE_NAME_PARAM_KEY, TestGroups.EDGE_2);
    ViewParameterDetail param = new ViewParameterDetail.Builder().defaultValue(TestGroups.EDGE).description("edge name param").valueClass(String.class).build();
    Map<String, ViewParameterDetail> paramDetailMap = Maps.newHashMap();
    paramDetailMap.put(EDGE_NAME_PARAM_KEY, param);
    // Make a real View with a parameter
    final View extendedView = new View.Builder().edge("${" + EDGE_NAME_PARAM_KEY + "}", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new ExampleFilterFunction()).build()).build()).build();
    final NamedViewDetail extendedNamedViewDetail = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME).view(extendedView).parameters(paramDetailMap).build();
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(extendedNamedViewDetail);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    GetElements getElements = (GetElements) opChain.getOperations().get(0);
    // Then
    assertTrue(getElements.getView().getEdge(TestGroups.EDGE) != null);
    assertTrue(getElements.getView().getEdge(TestGroups.EDGE_2) == null);
    final OperationChain<?> opChain1 = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).parameters(paramMap).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain1, CONTEXT);
    GetElements getElements1 = (GetElements) opChain1.getOperations().get(0);
    // Then
    assertTrue(getElements1.getView().getEdge(TestGroups.EDGE_2) != null);
}
Also used : ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) Test(org.junit.jupiter.api.Test)

Example 8 with NamedViewDetail

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNamedViewWithParametersToMakeCompleteFilter.

@Test
public void shouldResolveNamedViewWithParametersToMakeCompleteFilter() throws CacheOperationFailedException {
    Map<String, Object> paramMap = Maps.newHashMap();
    paramMap.put(IS_MORE_THAN_X_PARAM_KEY, 7L);
    ViewParameterDetail param = new ViewParameterDetail.Builder().defaultValue(2L).description("more than filter").valueClass(Long.class).build();
    Map<String, ViewParameterDetail> paramDetailMap = Maps.newHashMap();
    paramDetailMap.put(IS_MORE_THAN_X_PARAM_KEY, param);
    // Make a real View with a parameter
    final View extendedView = new View.Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsMoreThan("${" + IS_MORE_THAN_X_PARAM_KEY + "}")).build()).build()).build();
    final NamedViewDetail extendedNamedViewDetail = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME).view(extendedView).parameters(paramDetailMap).build();
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(extendedNamedViewDetail);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    GetElements getElements = (GetElements) opChain.getOperations().get(0);
    // Then
    assertTrue(new String(getElements.getView().toCompactJson()).contains(VALUE_JSON_STRING + 2));
    final OperationChain<?> opChain1 = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).parameters(paramMap).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain1, CONTEXT);
    GetElements getElements1 = (GetElements) opChain1.getOperations().get(0);
    // Then
    assertTrue(new String(getElements1.getView().toCompactJson()).contains(VALUE_JSON_STRING + 7));
}
Also used : ViewParameterDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 9 with NamedViewDetail

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.

the class NamedViewResolverTest method shouldBuildFullViewWhenANamedViewNeedingToBeResolvedAndMergedIsSupplied.

@Test
public void shouldBuildFullViewWhenANamedViewNeedingToBeResolvedAndMergedIsSupplied() throws CacheOperationFailedException, SerialisationException {
    // Given
    final View viewToMerge = new View.Builder().edge(TestGroups.EDGE).build();
    final NamedViewDetail namedViewDetailToMerge = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME + 2).view(viewToMerge).build();
    final View finalExpectedView = new View.Builder().edge(TestGroups.EDGE).merge(FULL_VIEW).build();
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    given(CACHE.getNamedView(NAMED_VIEW_NAME + 2, CONTEXT.getUser())).willReturn(namedViewDetailToMerge);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(new NamedView.Builder().name(NAMED_VIEW_NAME + 2).build()).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    // Then
    JsonAssert.assertEquals(finalExpectedView.toCompactJson(), ((OperationView) opChain.getOperations().get(0)).getView().toCompactJson());
}
Also used : OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) Test(org.junit.jupiter.api.Test)

Example 10 with NamedViewDetail

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNestedNamedViews.

@Test
public void shouldResolveNestedNamedViews() throws CacheOperationFailedException {
    // Given
    final NamedView nestedNamedView = new NamedView.Builder().name(NESTED_NAMED_VIEW_NAME).entity(TestGroups.ENTITY_2).build();
    final NamedViewDetail nestedNamedViewDetail = new NamedViewDetail.Builder().name(nestedNamedView.getName()).view(new View.Builder().entity(TestGroups.ENTITY_2).build()).build();
    final NamedView nestedNamedView1 = new NamedView.Builder().name(NESTED_NAMED_VIEW_NAME + 1).edge(TestGroups.EDGE).merge(nestedNamedView).build();
    final NamedViewDetail nestedNamedView1Detail = new NamedViewDetail.Builder().name(nestedNamedView.getName()).view(new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY_2).build()).build();
    final NamedView namedViewWithNestedNamedView = new NamedView.Builder().name(NAMED_VIEW_NAME).merge(nestedNamedView1).entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.PROP_1).execute(new ExampleFilterFunction()).build()).build()).build();
    final NamedViewDetail namedViewWithNestedNamedViewDetail = new NamedViewDetail.Builder().name(NAMED_VIEW_NAME).view(namedViewWithNestedNamedView).build();
    assertEquals(2, namedViewWithNestedNamedView.getMergedNamedViewNames().size());
    assertTrue(namedViewWithNestedNamedView.getMergedNamedViewNames().contains(NESTED_NAMED_VIEW_NAME));
    assertTrue(namedViewWithNestedNamedView.getMergedNamedViewNames().contains(NESTED_NAMED_VIEW_NAME + 1));
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(namedViewWithNestedNamedViewDetail);
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(nestedNamedViewDetail);
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willReturn(nestedNamedView1Detail);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    GetElements getElements = (GetElements) opChain.getOperations().get(0);
    namedViewWithNestedNamedView.setName(null);
    final View mergedView = new View.Builder().merge(namedViewWithNestedNamedView).build();
    // Then
    JsonAssert.assertEquals(mergedView.toCompactJson(), getElements.getView().toCompactJson());
}
Also used : ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ExampleFilterFunction(uk.gov.gchq.gaffer.function.ExampleFilterFunction) NamedViewDetail(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.jupiter.api.Test)

Aggregations

NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)22 Test (org.junit.jupiter.api.Test)16 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)10 NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)9 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)7 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)7 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)5 ViewParameterDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewParameterDetail)4 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)3 AccessPredicate (uk.gov.gchq.gaffer.access.predicate.AccessPredicate)2 UnrestrictedAccessPredicate (uk.gov.gchq.gaffer.access.predicate.UnrestrictedAccessPredicate)2 NamedViewWriteAccessPredicate (uk.gov.gchq.gaffer.data.elementdefinition.view.access.predicate.NamedViewWriteAccessPredicate)2 ExampleFilterFunction (uk.gov.gchq.gaffer.function.ExampleFilterFunction)2 GetAllNamedViews (uk.gov.gchq.gaffer.named.view.GetAllNamedViews)2 HashSet (java.util.HashSet)1 CustomUserPredicate (uk.gov.gchq.gaffer.access.predicate.user.CustomUserPredicate)1 WrappedCloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable)1 RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator (uk.gov.gchq.gaffer.doc.user.generator.RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 AddNamedView (uk.gov.gchq.gaffer.named.view.AddNamedView)1