Search in sources :

Example 76 with EntitySeed

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

the class ToEntityIdTest method shouldReturnEntitySeedIfInputIsAnObject.

@Test
public void shouldReturnEntitySeedIfInputIsAnObject() {
    // Given
    final Object input = "item";
    final ToEntityId function = new ToEntityId();
    // When
    final EntityId output = function.apply(input);
    // Then
    assertEquals(new EntitySeed(input), output);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Test(org.junit.jupiter.api.Test)

Example 77 with EntitySeed

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

the class Queries method runFullExample.

private void runFullExample(final Graph graph, final User user) throws OperationException {
    final OperationChain<Iterable<? extends String>> opChain = new OperationChain.Builder().first(new GetAdjacentIds.Builder().input(new EntitySeed("South West")).view(new View.Builder().edge("RegionContainsLocation").build()).build()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("LocationContainsRoad").build()).build()).then(new ToSet<>()).then(new GetAdjacentIds.Builder().view(new View.Builder().edge("RoadHasJunction").build()).build()).then(new GetElements.Builder().view(new View.Builder().globalElements(new GlobalViewElementDefinition.Builder().groupBy().build()).entity("JunctionUse", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate", "endDate").execute(new InDateRangeDual.Builder().start("2000/01/01").end("2001/01/01").build()).build()).postAggregationFilter(new ElementFilter.Builder().select("countByVehicleType").execute(new PredicateMap<>("BUS", new IsMoreThan(1000L))).build()).transientProperty("busCount", Long.class).transformer(new ElementTransformer.Builder().select("countByVehicleType").execute(new FreqMapExtractor("BUS")).project("busCount").build()).build()).build()).inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.OUTGOING).build()).then(new Sort.Builder().comparators(new ElementPropertyComparator.Builder().groups("JunctionUse").property("busCount").reverse(true).build()).resultLimit(2).deduplicate(true).build()).then(new ToCsv.Builder().generator(new CsvGenerator.Builder().vertex("Junction").property("busCount", "Bus Count").build()).build()).build();
    final Iterable<? extends String> results = graph.execute(opChain, user);
    System.out.println("Full example results:");
    for (final String result : results) {
        System.out.println(result);
    }
}
Also used : GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) Builder(uk.gov.gchq.gaffer.graph.Graph.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) ToSet(uk.gov.gchq.gaffer.operation.impl.output.ToSet) Sort(uk.gov.gchq.gaffer.operation.impl.compare.Sort) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) FreqMapExtractor(uk.gov.gchq.gaffer.types.function.FreqMapExtractor) CsvGenerator(uk.gov.gchq.gaffer.data.generator.CsvGenerator) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementPropertyComparator(uk.gov.gchq.gaffer.data.element.comparison.ElementPropertyComparator) InDateRangeDual(uk.gov.gchq.koryphe.impl.predicate.range.InDateRangeDual) ElementFilter(uk.gov.gchq.gaffer.data.element.function.ElementFilter) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) IsMoreThan(uk.gov.gchq.koryphe.impl.predicate.IsMoreThan)

Example 78 with EntitySeed

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

the class AbstractLoaderIT method shouldGetElementsWithMatchedVertex.

@TraitRequirement({ StoreTrait.MATCHED_VERTEX, StoreTrait.QUERY_AGGREGATION })
@Test
public void shouldGetElementsWithMatchedVertex() throws Exception {
    // Then
    final View view = new Builder().edge(TestGroups.EDGE).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();
    final CloseableIterable<? extends Element> results = graph.execute(op, getUser());
    assertElementEquals(getQuerySummarisedEdges(view).stream().filter(Edge::isDirected).filter(edge -> {
        final List<String> vertices = Lists.newArrayList(SOURCE_DIR_1, SOURCE_DIR_2, SOURCE_DIR_3);
        return vertices.contains(edge.getMatchedVertexValue());
    }).collect(toList()), results);
}
Also used : Builder(uk.gov.gchq.gaffer.data.elementdefinition.view.View.Builder) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) Test(org.junit.Test) TraitRequirement(uk.gov.gchq.gaffer.integration.TraitRequirement)

Example 79 with EntitySeed

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

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

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