Search in sources :

Example 41 with GetElements

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

the class AbstractLoaderIT method shouldGetElementsWithMatchedVertexFilter.

@TraitRequirement({ StoreTrait.MATCHED_VERTEX, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetElementsWithMatchedVertexFilter() throws Exception {
    // Then
    final View view = new Builder().edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.ADJACENT_MATCHED_VERTEX.name()).execute(new IsIn(DEST_DIR_1, DEST_DIR_2, DEST_DIR_3)).build()).build()).build();
    final GetElements op = new GetElements.Builder().input(new EntitySeed(SOURCE_DIR_1), new EntitySeed(DEST_DIR_2), new EntitySeed(SOURCE_DIR_3)).view(view).build();
    // When
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    assertElementEquals(getQuerySummarisedEdges(view).stream().filter(Edge::isDirected).filter(edge -> {
        final List<String> vertices = Lists.newArrayList(SOURCE_DIR_1, DEST_DIR_2, SOURCE_DIR_3);
        return vertices.contains(edge.getMatchedVertexValue());
    }).filter(edge -> {
        final List<String> vertices = Lists.newArrayList(DEST_DIR_1, DEST_DIR_2, DEST_DIR_3);
        return vertices.contains(edge.getAdjacentMatchedVertexValue());
    }).collect(toList()), results);
}
Also used : Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IsEqual(uk.gov.gchq.koryphe.impl.predicate.IsEqual) Element(uk.gov.gchq.gaffer.data.element.Element) ArrayList(java.util.ArrayList) JsonUtil(uk.gov.gchq.gaffer.commonutil.JsonUtil) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Lists(com.google.common.collect.Lists) ElementUtil.assertElementEquals(uk.gov.gchq.gaffer.data.util.ElementUtil.assertElementEquals) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) Edge(uk.gov.gchq.gaffer.data.element.Edge) TestGroups(uk.gov.gchq.gaffer.commonutil.TestGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) TestPropertyNames(uk.gov.gchq.gaffer.commonutil.TestPropertyNames) EmptyClosableIterable(uk.gov.gchq.gaffer.commonutil.iterable.EmptyClosableIterable) Test(org.junit.Test) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) AbstractStoreIT(uk.gov.gchq.gaffer.integration.AbstractStoreIT) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement) VisibilityUser(uk.gov.gchq.gaffer.integration.VisibilityUser) Consumer(java.util.function.Consumer) IdentifierType(uk.gov.gchq.gaffer.data.element.IdentifierType) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Operation(uk.gov.gchq.gaffer.operation.Operation) Schema(uk.gov.gchq.gaffer.store.schema.Schema) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) OperationException(uk.gov.gchq.gaffer.operation.OperationException) StoreTrait(uk.gov.gchq.gaffer.store.StoreTrait) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsIn(uk.gov.gchq.koryphe.impl.predicate.IsIn) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 42 with GetElements

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

the class VisibilityIT method shouldAccessMissingVisibilityGroups.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMissingVisibilityGroups() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    // Do NOT add an explicit visibility property
    // entity1.putProperty(AccumuloPropertyNames.VISIBILITY, "");
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().input(elements).build();
    graph.execute(addElements, getUser());
    final GetElements get = new GetElements.Builder().input(new EntitySeed("A")).build();
    final CloseableIterable<? extends Element> iterable = graph.execute(get, getUser());
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
    for (final Element e : results) {
        // Check that all visible entities contain the visibility property
        assertThat(e.getProperties()).as("Visibility property should be visible.").containsKey(TestTypes.VISIBILITY);
        assertThat(e.getProperties().get(TestTypes.VISIBILITY).toString()).withFailMessage("Visibility property should contain an empty String.").isEmpty();
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 43 with GetElements

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

the class VisibilityIT method shouldAccessMultipleVisibilityGroups_or.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMultipleVisibilityGroups_or() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "B");
    entity1.putProperty(TestTypes.VISIBILITY, "vis1|vis2");
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().input(elements).build();
    graph.execute(addElements, new User());
    final GetElements get = new GetElements.Builder().input(new EntitySeed("B")).build();
    final CloseableIterable<? extends Element> iterable = graph.execute(get, new User(User.UNKNOWN_USER_ID, Sets.newHashSet("vis1")));
    final List<Element> results = Lists.newArrayList(iterable);
    assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
    for (final Element e : results) {
        assertThat(e.getProperties()).containsKey(TestTypes.VISIBILITY);
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 44 with GetElements

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

the class VisibilityIT method shouldAccessMissingVisibilityGroupsWithNoVisibilityPropertyInSchema.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMissingVisibilityGroupsWithNoVisibilityPropertyInSchema() throws OperationException {
    graph = createGraphWithNoVisibility();
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().input(elements).build();
    graph.execute(addElements, getUser());
    final GetElements get = new GetElements.Builder().input(new EntitySeed("A")).build();
    final CloseableIterable<? extends Element> iterable = graph.execute(get, getUser());
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
    for (final Element e : results) {
        // Check that all visible entities do not contain the visibility property
        assertThat(e.getProperties()).as("Visibility property should not be visible.").doesNotContainKey(TestTypes.VISIBILITY);
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 45 with GetElements

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

the class VisibilityIT method shouldAccessNullVisibilityGroups.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessNullVisibilityGroups() throws OperationException {
    final Set<Element> elements = new HashSet<>();
    final Entity entity1 = new Entity(TestGroups.ENTITY, "A");
    entity1.putProperty(TestTypes.VISIBILITY, null);
    elements.add(entity1);
    final AddElements addElements = new AddElements.Builder().input(elements).build();
    graph.execute(addElements, getUser());
    final GetElements get = new GetElements.Builder().input(new EntitySeed("A"), new EntitySeed("B")).build();
    final CloseableIterable<? extends Element> iterable = graph.execute(get, getUser());
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat(results).withFailMessage("Results do not contain all expected entities.").hasSize(1);
    for (final Element e : results) {
        // Check that all visible entities contain the visibility property
        assertThat(e.getProperties()).as("Visibility property should be visible.").containsKey(TestTypes.VISIBILITY);
        assertThat(e.getProperties().get(TestTypes.VISIBILITY).toString()).withFailMessage("Visibility property should contain an empty String.").isEmpty();
    }
    iterable.close();
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

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