use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testDirectedEdgeIdQueries.
private void testDirectedEdgeIdQueries(final AccumuloStore store) throws StoreException {
setupGraph(store, NUM_ENTRIES);
final User user = new User();
// Create set to query for
final Set<ElementId> ids = new HashSet<>();
for (int i = 0; i < NUM_ENTRIES; i++) {
ids.add(new EdgeSeed("" + i, "B", false));
ids.add(new EdgeSeed("" + i, "C", true));
}
final View view = new View.Builder().edge(TestGroups.EDGE).build();
AccumuloSingleIDRetriever<?> retriever = null;
final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
operation.setDirectedType(DirectedType.DIRECTED);
try {
retriever = new AccumuloSingleIDRetriever<>(store, operation, user);
} catch (final IteratorSettingException e) {
throw new RuntimeException(e);
}
for (final Element element : retriever) {
Edge edge = (Edge) element;
assertEquals("C", edge.getDestination());
}
// Should find 1000 only A-C
assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEdgesAndEntities.
private void testEntityIdQueryEdgesAndEntities(final AccumuloStore store) throws AccumuloException, StoreException {
setupGraph(store, NUM_ENTRIES);
final User user = new User();
// Create set to query for
final Set<ElementId> ids = new HashSet<>();
for (int i = 0; i < NUM_ENTRIES; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().edge(TestGroups.EDGE).entity(TestGroups.ENTITY).build();
final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
try {
final AccumuloSingleIDRetriever retriever = new AccumuloSingleIDRetriever(store, operation, new User());
assertEquals(NUM_ENTRIES * 3, Iterables.size(retriever));
} catch (final IteratorSettingException e) {
fail("Unable to construct SingleID Retriever");
}
// Should find both i-B and i-C edges and entities i
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class AccumuloSingleIDRetrieverTest method testEntityIdQueryEntitiesOnly.
private void testEntityIdQueryEntitiesOnly(final AccumuloStore store) throws StoreException {
setupGraph(store, NUM_ENTRIES);
final User user = new User();
// Create set to query for
final Set<ElementId> ids = new HashSet<>();
for (int i = 0; i < NUM_ENTRIES; i++) {
ids.add(new EntitySeed("" + i));
}
final View view = new View.Builder().entity(TestGroups.ENTITY).build();
AccumuloSingleIDRetriever retriever = null;
final GetElements operation = new GetElements.Builder().view(view).input(ids).build();
try {
retriever = new AccumuloSingleIDRetriever(store, operation, user);
} catch (final IteratorSettingException e) {
throw new RuntimeException(e);
}
// Should find only the entities i
assertEquals(NUM_ENTRIES, Iterables.size(retriever));
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class GetElementsUtil method getRelevantElements.
public static Set<Element> getRelevantElements(final MapImpl mapImpl, final ElementId elementId, final View view, final DirectedType directedType, final IncludeIncomingOutgoingType inOutType, final SeedMatchingType seedMatchingType) {
final Set<Element> relevantElements;
final Set<String> groups = view.getGroups();
Predicate<Element> isFiltered = e -> !groups.contains(e.getGroup());
if (elementId instanceof EntityId) {
final Collection<Element> elements = mapImpl.lookup(new EntitySeed(((EntityId) elementId).getVertex()));
if (elements.isEmpty()) {
return Collections.emptySet();
}
relevantElements = new HashSet<>(elements);
// Apply inOutType options - if option is EITHER then nothing to do
if (inOutType == IncludeIncomingOutgoingType.INCOMING) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected() && (EdgeId.MatchedVertex.SOURCE == ((Edge) e).getMatchedVertex()));
} else if (inOutType == IncludeIncomingOutgoingType.OUTGOING) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected() && (EdgeId.MatchedVertex.DESTINATION == ((Edge) e).getMatchedVertex()));
}
// Apply seedMatching option - if option is RELATED then nothing to do
if (seedMatchingType == SeedMatchingType.EQUAL) {
isFiltered = isFiltered.or(e -> e instanceof Edge);
}
} else {
relevantElements = new HashSet<>();
final EdgeId edgeId = (EdgeId) elementId;
if (DirectedType.isEither(edgeId.getDirectedType())) {
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), false)));
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), true)));
} else {
relevantElements.addAll(mapImpl.lookup(new EdgeSeed(edgeId.getSource(), edgeId.getDestination(), edgeId.getDirectedType())));
}
mapImpl.lookup(new EntitySeed(edgeId.getSource())).stream().filter(e -> e instanceof Entity).forEach(relevantElements::add);
mapImpl.lookup(new EntitySeed(edgeId.getDestination())).stream().filter(e -> e instanceof Entity).forEach(relevantElements::add);
// If option is RELATED then nothing to do
if (seedMatchingType == SeedMatchingType.EQUAL) {
isFiltered = isFiltered.or(e -> e instanceof Entity);
}
}
// Apply directedType flag
if (directedType == DirectedType.DIRECTED) {
isFiltered = isFiltered.or(e -> e instanceof Edge && !((Edge) e).isDirected());
} else if (directedType == DirectedType.UNDIRECTED) {
isFiltered = isFiltered.or(e -> e instanceof Edge && ((Edge) e).isDirected());
}
relevantElements.removeIf(isFiltered);
return relevantElements;
}
use of uk.gov.gchq.gaffer.data.element.id.ElementId in project Gaffer by gchq.
the class EntitySeedTest method shouldBeRelatedToEdgeIdWhenDestinationEqualsVertex.
@Test
public void shouldBeRelatedToEdgeIdWhenDestinationEqualsVertex() {
// Given
final String source = "source";
final String destination = "destination";
final EntityId seed = new EntitySeed(destination);
final EdgeId relatedSeed = mock(EdgeId.class);
given(relatedSeed.getSource()).willReturn(source);
given(relatedSeed.getDestination()).willReturn(destination);
// When
final boolean isRelated = seed.isRelated((ElementId) relatedSeed).isMatch();
// Then
assertTrue(isRelated);
}
Aggregations