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());
}
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");
}
}
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());
}
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());
}
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);
}
}
}
Aggregations