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;
}
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());
}
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);
}
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;
}
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);
}
Aggregations