Search in sources :

Example 61 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class VisibilityIT method shouldAccessMissingVisibilityGroupsWithNoVisibilityPropertyInSchema.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMissingVisibilityGroupsWithNoVisibilityPropertyInSchema() throws OperationException, JsonProcessingException {
    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().elements(elements).build();
    graph.execute(addElements, USER_DEFAULT);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, USER_DEFAULT);
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat("Results do not contain all expected entities.", results, hasSize(1));
    for (final Element e : results) {
        // Check that all visible entities do not contain the visibility property
        assertFalse("Visibility property should not be visible.", 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) Element(uk.gov.gchq.gaffer.data.element.Element) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 62 with Element

use of uk.gov.gchq.gaffer.data.element.Element 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().elements(elements).build();
    graph.execute(addElements, new User());
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("B")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, new User(User.UNKNOWN_USER_ID, Sets.newHashSet("vis1")));
    final List<Element> results = Lists.newArrayList(iterable);
    assertThat("Results do not contain all expected Elements.", results, hasSize(1));
    for (final Element e : results) {
        assertTrue(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) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 63 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class VisibilityIT method shouldAccessNullVisibilityGroups.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessNullVisibilityGroups() throws OperationException, JsonProcessingException {
    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().elements(elements).build();
    graph.execute(addElements, USER_DEFAULT);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).addSeed(new EntitySeed("B")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, USER_DEFAULT);
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat("Results do not contain all expected entities.", results, hasSize(1));
    for (final Element e : results) {
        // Check that all visible entities contain the visibility property
        assertTrue("Visibility property should be visible.", e.getProperties().containsKey(TestTypes.VISIBILITY));
        assertThat("Visibility property should contain an empty String.", e.getProperties().get(TestTypes.VISIBILITY).toString(), isEmptyString());
    }
    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 64 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class VisibilityIT method shouldAccessMissingVisibilityGroups.

@Test
@TraitRequirement(StoreTrait.VISIBILITY)
public void shouldAccessMissingVisibilityGroups() throws OperationException, JsonProcessingException {
    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().elements(elements).build();
    graph.execute(addElements, USER_DEFAULT);
    final GetElements<EntitySeed, Element> get = new GetElements.Builder<EntitySeed, Element>().addSeed(new EntitySeed("A")).build();
    final CloseableIterable<Element> iterable = graph.execute(get, USER_DEFAULT);
    final List<Element> results = Lists.newArrayList(iterable);
    // Check for all entities which should be visible
    assertThat("Results do not contain all expected entities.", results, hasSize(1));
    for (final Element e : results) {
        // Check that all visible entities contain the visibility property
        assertTrue("Visibility property should be visible.", e.getProperties().containsKey(TestTypes.VISIBILITY));
        assertThat("Visibility property should contain an empty String.", e.getProperties().get(TestTypes.VISIBILITY).toString(), isEmptyString());
    }
    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) HashSet(java.util.HashSet) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 65 with Element

use of uk.gov.gchq.gaffer.data.element.Element in project Gaffer by gchq.

the class FilteringIT method testFilteringProperties.

@Test
@TraitRequirement(StoreTrait.PRE_AGGREGATION_FILTERING)
public void testFilteringProperties() throws OperationException {
    // Given
    final List<ElementSeed> seeds = Arrays.asList(new EntitySeed("A3"), new EdgeSeed("A5", "B5", false));
    final GetElements<ElementSeed, Element> getElementsWithoutFiltering = new GetElements.Builder<>().seeds(seeds).build();
    final GetElements<ElementSeed, Element> getElementsWithFiltering = new GetElements.Builder<>().seeds(seeds).view(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(IdentifierType.VERTEX.name()).execute(new IsEqual("A5")).build()).build()).edge(TestGroups.EDGE, new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select(TestPropertyNames.INT).execute(new IsLessThan(2)).build()).build()).build()).build();
    // When - without filtering
    final List<Element> resultsWithoutFiltering = Lists.newArrayList(graph.execute(getElementsWithoutFiltering, getUser()));
    // When - with filtering
    final List<Element> resultsWithFiltering = Lists.newArrayList(graph.execute(getElementsWithFiltering, getUser()));
    // Then - without filtering
    assertNotNull(resultsWithoutFiltering);
    assertEquals(8, resultsWithoutFiltering.size());
    assertThat(resultsWithoutFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A3", "C3", false), getEdge("A3", "D3", false), getEdge("A5", "B5", false), getEntity("A5"), getEntity("B5")));
    // Then - with filtering
    assertNotNull(resultsWithFiltering);
    assertEquals(6, resultsWithFiltering.size());
    assertThat(resultsWithFiltering, IsCollectionContaining.hasItems(getEdge("A3", "A3", false), getEdge("A3", "B3", false), getEdge("A5", "B5", false), getEdge("A3", "D3", false), getEdge("A3", "C3", false), getEntity("A5")));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) IsEqual(uk.gov.gchq.gaffer.function.filter.IsEqual) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Aggregations

Element (uk.gov.gchq.gaffer.data.element.Element)182 Test (org.junit.Test)102 Edge (uk.gov.gchq.gaffer.data.element.Edge)72 User (uk.gov.gchq.gaffer.user.User)53 Entity (uk.gov.gchq.gaffer.data.element.Entity)52 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)50 HashSet (java.util.HashSet)47 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)42 ArrayList (java.util.ArrayList)33 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)32 ElementSeed (uk.gov.gchq.gaffer.operation.data.ElementSeed)26 Key (org.apache.accumulo.core.data.Key)23 Value (org.apache.accumulo.core.data.Value)23 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)21 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)17 Graph (uk.gov.gchq.gaffer.graph.Graph)16 HashMap (java.util.HashMap)14 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)14 Configuration (org.apache.hadoop.conf.Configuration)12 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)12