Search in sources :

Example 71 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements 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 72 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNamedViewAndMergeAnotherView.

@Test
public void shouldResolveNamedViewAndMergeAnotherView() throws CacheOperationFailedException {
    // Given
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    final View viewToMerge = new View.Builder().edge(TestGroups.EDGE).build();
    final View mergedView = new View.Builder().merge(FULL_VIEW).merge(viewToMerge).build();
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(NAMED_VIEW_NAME).merge(viewToMerge).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) 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 73 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveNamedView.

@Test
public void shouldResolveNamedView() throws CacheOperationFailedException {
    // Given
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    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
    JsonAssert.assertEquals(FULL_VIEW.toCompactJson(), getElements.getView().toCompactJson());
}
Also used : GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 74 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements 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)

Example 75 with GetElements

use of uk.gov.gchq.gaffer.operation.impl.get.GetElements in project Gaffer by gchq.

the class NamedViewResolverTest method shouldResolveMultipleNestedNamedViews.

@Test
public void shouldResolveMultipleNestedNamedViews() 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(nestedNamedView).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(nestedNamedView1.getName()).view(nestedNamedView1).build();
    final NamedView nestedNamedView2 = new NamedView.Builder().name(NESTED_NAMED_VIEW_NAME + 2).edge(TestGroups.EDGE_2).merge(nestedNamedView1).build();
    final NamedViewDetail nestedNamedView2Detail = new NamedViewDetail.Builder().name(nestedNamedView2.getName()).view(nestedNamedView2).build();
    final NamedView nestedNamedView3 = new NamedView.Builder().name(NESTED_NAMED_VIEW_NAME + 3).edge(TestGroups.EDGE_3).merge(nestedNamedView2).build();
    final NamedViewDetail nestedNamedView3Detail = new NamedViewDetail.Builder().name(nestedNamedView3.getName()).view(nestedNamedView3).build();
    assertEquals(3, nestedNamedView3.getMergedNamedViewNames().size());
    assertTrue(nestedNamedView3.getMergedNamedViewNames().contains(NESTED_NAMED_VIEW_NAME));
    assertTrue(nestedNamedView3.getMergedNamedViewNames().contains(NESTED_NAMED_VIEW_NAME + 1));
    assertTrue(nestedNamedView3.getMergedNamedViewNames().contains(NESTED_NAMED_VIEW_NAME + 2));
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(nestedNamedViewDetail);
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willReturn(nestedNamedView1Detail);
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME + 2, CONTEXT.getUser())).willReturn(nestedNamedView2Detail);
    given(CACHE.getNamedView(NESTED_NAMED_VIEW_NAME + 3, CONTEXT.getUser())).willReturn(nestedNamedView3Detail);
    final OperationChain<?> opChain = new OperationChain.Builder().first(new GetElements.Builder().view(new NamedView.Builder().name(nestedNamedView3.getName()).build()).build()).build();
    // When
    RESOLVER.preExecute(opChain, CONTEXT);
    GetElements getElements = (GetElements) opChain.getOperations().get(0);
    nestedNamedView3.setName(null);
    final View mergedView = new View.Builder().merge(nestedNamedView3).build();
    // 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)

Aggregations

GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)256 Test (org.junit.jupiter.api.Test)153 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)112 User (uk.gov.gchq.gaffer.user.User)102 Element (uk.gov.gchq.gaffer.data.element.Element)91 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)84 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)83 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)67 Context (uk.gov.gchq.gaffer.store.Context)60 Test (org.junit.Test)56 HashSet (java.util.HashSet)52 Graph (uk.gov.gchq.gaffer.graph.Graph)49 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 Entity (uk.gov.gchq.gaffer.data.element.Entity)42 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)38 Operation (uk.gov.gchq.gaffer.operation.Operation)35 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)35 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)34 Edge (uk.gov.gchq.gaffer.data.element.Edge)32 ArrayList (java.util.ArrayList)31