Search in sources :

Example 26 with ElementId

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

the class GetElementsTest method shouldSetSeedMatchingTypeToRelated.

@Test
public void shouldSetSeedMatchingTypeToRelated() {
    final ElementId elementId1 = new EntitySeed("identifier");
    final ElementId elementId2 = new EdgeSeed("source2", "destination2", true);
    // When
    final GetElements op = new GetElements.Builder().input(elementId1, elementId2).seedMatching(SeedMatchingType.RELATED).build();
    // Then
    assertEquals(SeedMatchingType.RELATED, op.getSeedMatching());
}
Also used : EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) OperationTest(uk.gov.gchq.gaffer.operation.OperationTest) Test(org.junit.jupiter.api.Test)

Example 27 with ElementId

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

the class OperationUtilTest method shouldConvertObjectArrayToElementIds.

@Test
public void shouldConvertObjectArrayToElementIds() {
    // Given
    final Object[] input = { 1, "2", new EntitySeed("3"), new Entity("group", "4"), new EdgeSeed("5", 6), new Edge("group", 7L, 8, true), null };
    // When
    final Iterable<? extends ElementId> output = OperationUtil.toElementIds(input);
    // Then
    final ArrayList<ElementId> expected = Lists.newArrayList(new EntitySeed(1), new EntitySeed("2"), new EntitySeed("3"), new Entity("group", "4"), new EdgeSeed("5", 6), new Edge("group", 7L, 8, true), null);
    assertEquals(expected, Lists.newArrayList(output));
}
Also used : Entity(uk.gov.gchq.gaffer.data.element.Entity) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Example 28 with ElementId

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

the class ForEachIT method shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput.

@Test
public void shouldReturnEmptyIterableWithOperationThatDoesntImplementOutput() throws OperationException {
    // Given
    final ForEach<ElementSeed, Element> op = new ForEach.Builder<ElementSeed, Element>().operation(new DiscardOutput.Builder().build()).input(Collections.singletonList(new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true))).build();
    // When
    final Iterable<? extends Element> results = graph.execute(op, getUser());
    // Then
    ElementUtil.assertElementEquals(Sets.newHashSet((ElementId) null), results);
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) ElementSeed(uk.gov.gchq.gaffer.operation.data.ElementSeed) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) ForEach(uk.gov.gchq.gaffer.operation.impl.ForEach) Test(org.junit.Test)

Example 29 with ElementId

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

the class GetElementsIT method shouldGetElements.

private void shouldGetElements(final Collection<Element> expectedElements, final SeedMatchingType seedMatching, final DirectedType directedType, final boolean includeEntities, final boolean includeEdges, final IncludeIncomingOutgoingType inOutType, final Iterable<ElementId> seeds) throws IOException, OperationException {
    // Given
    final User user = new User();
    final View.Builder viewBuilder = new View.Builder();
    if (includeEntities) {
        viewBuilder.entity(TestGroups.ENTITY);
    }
    if (includeEdges) {
        viewBuilder.edge(TestGroups.EDGE);
    }
    final GetElements opSeed = new GetElements.Builder().input(seeds).directedType(directedType).inOutType(inOutType).view(viewBuilder.build()).seedMatching(seedMatching).build();
    Collection<ElementId> seedCollection = StreamSupport.stream(seeds.spliterator(), false).collect(Collectors.toList());
    final GetElements opElement = new GetElements.Builder().input(getElements(seedCollection, null)).directedType(directedType).inOutType(inOutType).view(viewBuilder.build()).seedMatching(seedMatching).build();
    // When
    final CloseableIterable<? extends Element> resultsSeed = graph.execute(opSeed, user);
    final CloseableIterable<? extends Element> resultsElement = graph.execute(opElement, user);
    // Then
    ElementUtil.assertElementEquals(expectedElements, resultsSeed, true);
    ElementUtil.assertElementEquals(expectedElements, resultsElement, true);
}
Also used : User(uk.gov.gchq.gaffer.user.User) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId)

Example 30 with ElementId

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

the class GetElementsIT method getElements.

private static Collection<Element> getElements(final Collection<ElementId> seeds, final Boolean direction) {
    final Set<Element> elements = new HashSet<>(seeds.size());
    for (final ElementId seed : seeds) {
        if (seed instanceof EntityId) {
            final Entity entity = new Entity(TestGroups.ENTITY, ((EntityId) seed).getVertex());
            entity.putProperty(TestPropertyNames.COUNT, 1L);
            entity.putProperty(TestPropertyNames.SET, CollectionUtil.treeSet("3"));
            elements.add(entity);
        } else {
            if (DirectedType.isEither(((EdgeId) seed).getDirectedType())) {
                if (BooleanUtils.isNotTrue(direction)) {
                    final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).matchedVertex(((EdgeId) seed).getMatchedVertex()).directed(false).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
                    elements.add(edge);
                }
                if (BooleanUtils.isNotFalse(direction)) {
                    final Edge edgeDir = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).matchedVertex(((EdgeId) seed).getMatchedVertex()).directed(true).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
                    elements.add(edgeDir);
                }
            } else {
                final Edge edge = new Edge.Builder().group(TestGroups.EDGE).source(((EdgeId) seed).getSource()).dest(((EdgeId) seed).getDestination()).directed(((EdgeId) seed).isDirected()).matchedVertex(((EdgeId) seed).getMatchedVertex()).property(TestPropertyNames.INT, 1).property(TestPropertyNames.COUNT, 1L).build();
                elements.add(edge);
            }
        }
    }
    return elements;
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) Edge(uk.gov.gchq.gaffer.data.element.Edge) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) HashSet(java.util.HashSet)

Aggregations

ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)58 Test (org.junit.jupiter.api.Test)32 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)29 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)19 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)19 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)17 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)14 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)14 HashSet (java.util.HashSet)11 Entity (uk.gov.gchq.gaffer.data.element.Entity)9 User (uk.gov.gchq.gaffer.user.User)9 ArrayList (java.util.ArrayList)7 IteratorSettingException (uk.gov.gchq.gaffer.accumulostore.key.exception.IteratorSettingException)7 OperationTest (uk.gov.gchq.gaffer.operation.OperationTest)7 Test (org.junit.Test)6 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)6 TraitRequirement (uk.gov.gchq.gaffer.integration.TraitRequirement)5 Key (org.apache.accumulo.core.data.Key)4