Search in sources :

Example 1 with NamedView

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView 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 2 with NamedView

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

the class NamedViewResolverTest method shouldThrowExceptionWhenNamedViewToBeMergedIsNotInCache.

@Test
public void shouldThrowExceptionWhenNamedViewToBeMergedIsNotInCache() throws CacheOperationFailedException {
    // Given
    given(CACHE.getNamedView(NAMED_VIEW_NAME, CONTEXT.getUser())).willReturn(FULL_NAMED_VIEW_DETAIL);
    given(CACHE.getNamedView(NAMED_VIEW_NAME + 1, CONTEXT.getUser())).willThrow(new CacheOperationFailedException("No NamedView with the name namedViewName1 exists in the cache"));
    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 + 1).build()).build()).build()).build();
    // When / Then
    try {
        RESOLVER.preExecute(opChain, CONTEXT);
        fail("Exception expected");
    } catch (final RuntimeException e) {
        assert e.getMessage().contains("No NamedView with the name namedViewName1 exists in the cache");
    }
}
Also used : NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) CacheOperationFailedException(uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException) Test(org.junit.jupiter.api.Test)

Example 3 with NamedView

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView 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 4 with NamedView

use of uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView 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)

Example 5 with NamedView

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

the class Graph method updateOperationChainView.

private void updateOperationChainView(final Operations<?> operations) {
    for (final Operation operation : operations.getOperations()) {
        if (operation instanceof Operations) {
            updateOperationChainView((Operations) operation);
        } else if (operation instanceof OperationView) {
            View opView = ((OperationView) operation).getView();
            if (null == opView) {
                opView = config.getView();
            } else if (!(opView instanceof NamedView) && !opView.hasGroups() && !opView.isAllEdges() && !opView.isAllEntities()) {
                // merge with both Entities and Edges
                if (!isEmpty(opView.getGlobalElements()) || (isEmpty(opView.getGlobalEdges()) && isEmpty(opView.getGlobalEntities()))) {
                    opView = new View.Builder().merge(config.getView()).merge(opView).build();
                } else {
                    // We have either global edges or entities in
                    // opView, but not both
                    final View originalView = opView;
                    final View partialConfigView = new View.Builder().merge(config.getView()).removeEdges((x -> isEmpty(originalView.getGlobalEdges()))).removeEntities((x -> isEmpty(originalView.getGlobalEntities()))).build();
                    opView = new View.Builder().merge(partialConfigView).merge(opView).build();
                }
            } else if (opView.isAllEdges() || opView.isAllEntities()) {
                View.Builder opViewBuilder = new View.Builder().merge(opView);
                if (opView.isAllEdges()) {
                    opViewBuilder.edges(getSchema().getEdgeGroups());
                }
                if (opView.isAllEntities()) {
                    opViewBuilder.entities(getSchema().getEntityGroups());
                }
                opView = opViewBuilder.build();
            }
            opView.expandGlobalDefinitions();
            ((OperationView) operation).setView(opView);
        }
    }
}
Also used : Job(uk.gov.gchq.gaffer.jobtracker.Job) LoggerFactory(org.slf4j.LoggerFactory) SchemaException(uk.gov.gchq.gaffer.data.elementdefinition.exception.SchemaException) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) URI(java.net.URI) Path(java.nio.file.Path) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) Pair(uk.gov.gchq.gaffer.commonutil.pair.Pair) Set(java.util.Set) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) Store(uk.gov.gchq.gaffer.store.Store) ReflectionUtil(uk.gov.gchq.koryphe.util.ReflectionUtil) List(java.util.List) Context(uk.gov.gchq.gaffer.store.Context) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) CloseableUtil(uk.gov.gchq.gaffer.commonutil.CloseableUtil) NamedOperationResolver(uk.gov.gchq.gaffer.graph.hook.NamedOperationResolver) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) Operations(uk.gov.gchq.gaffer.operation.Operations) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) JSONSerialiser(uk.gov.gchq.gaffer.jsonserialisation.JSONSerialiser) StoreException(uk.gov.gchq.gaffer.store.StoreException) User(uk.gov.gchq.gaffer.user.User) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) UpdateViewHook(uk.gov.gchq.gaffer.graph.hook.UpdateViewHook) ArrayList(java.util.ArrayList) GraphLibrary(uk.gov.gchq.gaffer.store.library.GraphLibrary) Lists(com.google.common.collect.Lists) Output(uk.gov.gchq.gaffer.operation.io.Output) NoGraphLibrary(uk.gov.gchq.gaffer.store.library.NoGraphLibrary) StreamUtil(uk.gov.gchq.gaffer.commonutil.StreamUtil) Logger(org.slf4j.Logger) Properties(java.util.Properties) NamedViewResolver(uk.gov.gchq.gaffer.graph.hook.NamedViewResolver) Files(java.nio.file.Files) FileUtils(org.apache.commons.io.FileUtils) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) IOException(java.io.IOException) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) CollectionUtils.isEmpty(org.apache.commons.collections.CollectionUtils.isEmpty) FunctionAuthoriser(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriser) FunctionAuthoriserUtil(uk.gov.gchq.gaffer.graph.hook.FunctionAuthoriserUtil) Collections(java.util.Collections) InputStream(java.io.InputStream) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) NamedOperation(uk.gov.gchq.gaffer.named.operation.NamedOperation) Operation(uk.gov.gchq.gaffer.operation.Operation) Operations(uk.gov.gchq.gaffer.operation.Operations) NamedView(uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView)

Aggregations

NamedView (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedView)10 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)8 OperationView (uk.gov.gchq.gaffer.operation.graph.OperationView)6 Test (org.junit.jupiter.api.Test)5 NamedViewDetail (uk.gov.gchq.gaffer.data.elementdefinition.view.NamedViewDetail)5 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)4 CacheOperationFailedException (uk.gov.gchq.gaffer.named.operation.cache.exception.CacheOperationFailedException)2 AddNamedView (uk.gov.gchq.gaffer.named.view.AddNamedView)2 Lists (com.google.common.collect.Lists)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Properties (java.util.Properties)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1