Search in sources :

Example 81 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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 82 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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 83 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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)

Example 84 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class FilterToOperationConverterTest method testSpecifyVertexAndPropertyFilter.

@Test
public void testSpecifyVertexAndPropertyFilter() {
    final Schema schema = getSchema();
    final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
    // Specify vertex and a filter on property1
    Filter[] filters = new Filter[2];
    filters[0] = new GreaterThan("property1", 5);
    filters[1] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
    FiltersToOperationConverter converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
    Operation operation = converter.getOperation();
    assertTrue(operation instanceof GetRDDOfElements);
    assertEquals(1, ((GraphFilters) operation).getView().getEntityGroups().size());
    assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
    final Set<EntityId> seeds = new HashSet<>();
    for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
        seeds.add((EntitySeed) seed);
    }
    assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
    View opView = ((GraphFilters) operation).getView();
    List<TupleAdaptedPredicate<String, ?>> entityPostAggFilters = opView.getEntity(ENTITY_GROUP).getPostAggregationFilterFunctions();
    assertThat(entityPostAggFilters).hasSize(1);
    final ArrayList<String> expectedProperties = new ArrayList<>();
    expectedProperties.add("property1");
    assertThat(entityPostAggFilters.get(0).getSelection()).hasSize(1);
    assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection()[0]);
    final ArrayList<Predicate> expectedFunctions = new ArrayList<>();
    expectedFunctions.add(new IsMoreThan(5, false));
    assertEquals(expectedFunctions.get(0), entityPostAggFilters.get(0).getPredicate());
    // Specify vertex and filters on properties property1 and property4
    filters = new Filter[3];
    filters[0] = new GreaterThan("property1", 5);
    filters[1] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
    filters[2] = new LessThan("property4", 8);
    converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
    operation = converter.getOperation();
    assertTrue(operation instanceof GetRDDOfElements);
    assertEquals(1, ((GraphFilters) operation).getView().getEntityGroups().size());
    assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
    seeds.clear();
    for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
        seeds.add((EntitySeed) seed);
    }
    assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
    opView = ((GraphFilters) operation).getView();
    entityPostAggFilters = opView.getEntity(ENTITY_GROUP).getPostAggregationFilterFunctions();
    assertThat(entityPostAggFilters).hasSize(2);
    expectedProperties.clear();
    expectedProperties.add("property1");
    expectedProperties.add("property4");
    assertThat(entityPostAggFilters.get(0).getSelection()).hasSize(1);
    assertEquals(expectedProperties.get(0), entityPostAggFilters.get(0).getSelection()[0]);
    assertThat(entityPostAggFilters.get(1).getSelection()).hasSize(1);
    assertEquals(expectedProperties.get(1), entityPostAggFilters.get(1).getSelection()[0]);
    expectedFunctions.clear();
    expectedFunctions.add(new IsMoreThan(5, false));
    expectedFunctions.add(new IsLessThan(8, false));
    assertEquals(expectedFunctions.get(0), entityPostAggFilters.get(0).getPredicate());
    assertEquals(expectedFunctions.get(1), entityPostAggFilters.get(1).getPredicate());
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) Schema(uk.gov.gchq.gaffer.store.schema.Schema) ArrayList(java.util.ArrayList) GraphFilters(uk.gov.gchq.gaffer.operation.graph.GraphFilters) Operation(uk.gov.gchq.gaffer.operation.Operation) TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) Predicate(java.util.function.Predicate) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) LessThan(org.apache.spark.sql.sources.LessThan) IsLessThan(uk.gov.gchq.koryphe.impl.predicate.IsLessThan) GreaterThan(org.apache.spark.sql.sources.GreaterThan) GetRDDOfElements(uk.gov.gchq.gaffer.spark.operation.scalardd.GetRDDOfElements) HashSet(java.util.HashSet) TupleAdaptedPredicate(uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EqualTo(org.apache.spark.sql.sources.EqualTo) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Filter(org.apache.spark.sql.sources.Filter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan) Test(org.junit.jupiter.api.Test)

Example 85 with EntitySeed

use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.

the class FilterToOperationConverterTest method testSpecifyVertex.

@Test
public void testSpecifyVertex() {
    final Schema schema = getSchema();
    final SparkSession sparkSession = SparkSessionProvider.getSparkSession();
    final Filter[] filters = new Filter[1];
    filters[0] = new EqualTo(SchemaToStructTypeConverter.VERTEX_COL_NAME, "0");
    final FiltersToOperationConverter converter = new FiltersToOperationConverter(getViewFromSchema(schema), schema, filters);
    final Operation operation = converter.getOperation();
    assertTrue(operation instanceof GetRDDOfElements);
    assertEquals(Collections.singleton(ENTITY_GROUP), ((GraphFilters) operation).getView().getEntityGroups());
    assertEquals(0, ((GraphFilters) operation).getView().getEdgeGroups().size());
    final Set<EntityId> seeds = new HashSet<>();
    for (final Object seed : ((GetRDDOfElements) operation).getInput()) {
        seeds.add((EntitySeed) seed);
    }
    assertEquals(Collections.singleton(new EntitySeed("0")), seeds);
}
Also used : SparkSession(org.apache.spark.sql.SparkSession) Schema(uk.gov.gchq.gaffer.store.schema.Schema) GraphFilters(uk.gov.gchq.gaffer.operation.graph.GraphFilters) Operation(uk.gov.gchq.gaffer.operation.Operation) EqualTo(org.apache.spark.sql.sources.EqualTo) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Filter(org.apache.spark.sql.sources.Filter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetRDDOfElements(uk.gov.gchq.gaffer.spark.operation.scalardd.GetRDDOfElements) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)284 Test (org.junit.jupiter.api.Test)122 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)122 Element (uk.gov.gchq.gaffer.data.element.Element)102 User (uk.gov.gchq.gaffer.user.User)92 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)90 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)87 HashSet (java.util.HashSet)71 Graph (uk.gov.gchq.gaffer.graph.Graph)69 Entity (uk.gov.gchq.gaffer.data.element.Entity)65 Edge (uk.gov.gchq.gaffer.data.element.Edge)61 Test (org.junit.Test)58 ArrayList (java.util.ArrayList)55 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)46 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)41 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)40 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)38 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)36 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)36 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)35