Search in sources :

Example 71 with EntityId

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

the class BasicSchemaLoader method createEntities.

@Override
public Map<EntityId, Entity> createEntities() {
    final Map<EntityId, Entity> entities = new HashMap<>();
    for (int i = 0; i <= 10; i++) {
        for (int j = 0; j < VERTEX_PREFIXES.length; j++) {
            final Entity entity = new Entity(TestGroups.ENTITY, VERTEX_PREFIXES[j] + i);
            entity.putProperty(TestPropertyNames.COUNT, 1L);
            addToMap(entity, entities);
        }
        final Entity secondEntity = new Entity(TestGroups.ENTITY, SOURCE + i);
        secondEntity.putProperty(TestPropertyNames.COUNT, 1L);
        addToMap(secondEntity, entities);
        final Entity thirdEntity = new Entity(TestGroups.ENTITY, DEST + i);
        thirdEntity.putProperty(TestPropertyNames.COUNT, 1L);
        addToMap(thirdEntity, entities);
        final Entity fourthEntity = new Entity(TestGroups.ENTITY, SOURCE_DIR + i);
        fourthEntity.putProperty(TestPropertyNames.COUNT, 1L);
        addToMap(fourthEntity, entities);
        final Entity fifthEntity = new Entity(TestGroups.ENTITY, DEST_DIR + i);
        fifthEntity.putProperty(TestPropertyNames.COUNT, 1L);
        addToMap(fifthEntity, entities);
    }
    return entities;
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Entity(uk.gov.gchq.gaffer.data.element.Entity) HashMap(java.util.HashMap)

Example 72 with EntityId

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

the class GetAdjacentIdsIT method shouldGetEntityIds.

private void shouldGetEntityIds(final List<String> expectedResultSeeds, final IncludeIncomingOutgoingType inOutType, final DirectedType directedType) throws OperationException {
    // Given
    final User user = new User();
    final List<EntityId> seeds = new ArrayList<>();
    for (final String seed : SEEDS) {
        seeds.add(new EntitySeed(seed));
    }
    final GetAdjacentIds operation = new GetAdjacentIds.Builder().input(seeds).directedType(directedType).inOutType(inOutType).build();
    // When
    final CloseableIterable<? extends EntityId> results = graph.execute(operation, user);
    // Then
    List<String> resultSeeds = new ArrayList<>();
    for (final EntityId result : results) {
        resultSeeds.add((String) result.getVertex());
    }
    Collections.sort(resultSeeds);
    Collections.sort(expectedResultSeeds);
    assertThat(resultSeeds.toArray()).as("InOut=" + inOutType + ", directedType=" + directedType + ".\nExpected: \n  " + StringUtils.join(expectedResultSeeds, "\n  ") + " \nbut got: \n  " + StringUtils.join(resultSeeds, "\n  ")).containsExactly(expectedResultSeeds.toArray());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 73 with EntityId

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

the class GetElementsIT method shouldGetRelatedElements.

private void shouldGetRelatedElements(final boolean includeEntities, final boolean includeEdges, final DirectedType directedType, final IncludeIncomingOutgoingType inOutType) throws Exception {
    final Set<ElementId> expectedElementIds = new HashSet<>();
    final Set<Element> expectedElements = new HashSet<>();
    if (includeEntities) {
        for (final Object identifier : ALL_SEED_VERTICES) {
            final EntityId entityId = new EntitySeed(identifier);
            expectedElementIds.add(entityId);
        }
    }
    if (includeEdges) {
        expectedElementIds.addAll(EDGE_SEEDS_BOTH);
        if (DirectedType.UNDIRECTED != directedType) {
            expectedElementIds.add(new EdgeSeed(SOURCE_DIR_1, DEST_DIR_1, true));
            if (null == inOutType || IncludeIncomingOutgoingType.EITHER == inOutType || IncludeIncomingOutgoingType.OUTGOING == inOutType) {
                expectedElementIds.add(new EdgeSeed(SOURCE_DIR_2, DEST_DIR_2, true));
            }
            if (null == inOutType || IncludeIncomingOutgoingType.EITHER == inOutType || IncludeIncomingOutgoingType.INCOMING == inOutType) {
                expectedElementIds.add(new EdgeSeed(SOURCE_DIR_3, DEST_DIR_3, true, EdgeId.MatchedVertex.DESTINATION));
            }
        }
        if (DirectedType.DIRECTED != directedType) {
            expectedElementIds.add(new EdgeSeed(SOURCE_1, DEST_1, false));
            expectedElementIds.add(new EdgeSeed(SOURCE_2, DEST_2, false));
            expectedElementIds.add(new EdgeSeed(SOURCE_3, DEST_3, false, EdgeId.MatchedVertex.DESTINATION));
        }
    }
    expectedElements.addAll(getElements(expectedElementIds, null));
    if (DirectedType.DIRECTED == directedType) {
        expectedElements.removeIf(e -> e instanceof Edge && ((Edge) e).isUndirected());
    }
    if (DirectedType.UNDIRECTED == directedType) {
        expectedElements.removeIf(e -> e instanceof Edge && ((Edge) e).isDirected());
    }
    shouldGetElements(expectedElements, SeedMatchingType.RELATED, directedType, includeEntities, includeEdges, inOutType, ALL_SEEDS);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Element(uk.gov.gchq.gaffer.data.element.Element) 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) HashSet(java.util.HashSet)

Example 74 with EntityId

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

the class ExamplesService method getAdjacentIds.

@Override
public GetAdjacentIds getAdjacentIds() {
    final GetAdjacentIds op = new GetAdjacentIds();
    final List<EntityId> seeds = new ArrayList<>();
    if (hasEntities()) {
        seeds.add(getEntityId(1));
    } else if (hasEdges()) {
        seeds.add(new EntitySeed(getEdgeId(1, 2).getSource()));
    }
    op.setInput(seeds);
    populateOperation(op);
    return op;
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ArrayList(java.util.ArrayList) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Example 75 with EntityId

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

the class AbstractExamplesFactoryTest method shouldUseSchemaToCreateGetAdjacentIdsInput.

@Test
public void shouldUseSchemaToCreateGetAdjacentIdsInput() throws InstantiationException, IllegalAccessException {
    // Given
    TestExamplesFactory examplesFactory = new TestExamplesFactory(SCHEMA);
    // When
    GetAdjacentIds operation = (GetAdjacentIds) examplesFactory.generateExample(GetAdjacentIds.class);
    // Then
    int size = 0;
    for (ElementId e : operation.getInput()) {
        size++;
        if (e instanceof EntityId) {
            assertEquals(String.class, ((EntityId) e).getVertex().getClass());
        } else {
            throw new RuntimeException("Expected operation only to contain entity ids");
        }
    }
    assertEquals(1, size);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Test(org.junit.jupiter.api.Test)

Aggregations

EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)93 Test (org.junit.jupiter.api.Test)60 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)41 HashSet (java.util.HashSet)22 User (uk.gov.gchq.gaffer.user.User)21 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)15 Entity (uk.gov.gchq.gaffer.data.element.Entity)15 EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)15 View (uk.gov.gchq.gaffer.data.elementdefinition.view.View)15 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 Element (uk.gov.gchq.gaffer.data.element.Element)14 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)14 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)13 GetAdjacentIds (uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds)13 GetElements (uk.gov.gchq.gaffer.operation.impl.get.GetElements)12 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)10 ArrayList (java.util.ArrayList)8 ViewElementDefinition (uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition)7 Graph (uk.gov.gchq.gaffer.graph.Graph)7 Context (uk.gov.gchq.gaffer.store.Context)7