Search in sources :

Example 1 with EdgeId

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

the class EdgeIdSerialiserTest method testCanSerialiseEdgeId.

@Test
public void testCanSerialiseEdgeId() throws SerialisationException {
    // Given
    final EdgeId edgeId = new EdgeSeed("source", "destination", true);
    // When
    final byte[] serialisedEdgeId = serialiser.serialise(edgeId);
    final EdgeId deserialisedEdgeId = serialiser.deserialise(serialisedEdgeId);
    // Then
    assertEquals(edgeId, deserialisedEdgeId);
}
Also used : EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Test(org.junit.jupiter.api.Test)

Example 2 with EdgeId

use of uk.gov.gchq.gaffer.data.element.id.EdgeId 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;
}
Also used : User(uk.gov.gchq.gaffer.user.User) LoggerFactory(org.slf4j.LoggerFactory) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) Element(uk.gov.gchq.gaffer.data.element.Element) Authorisations(uk.gov.gchq.gaffer.commonutil.elementvisibilityutil.Authorisations) HashSet(java.util.HashSet) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) ElementTransformer(uk.gov.gchq.gaffer.data.element.function.ElementTransformer) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) SeedMatchingType(uk.gov.gchq.gaffer.operation.SeedMatching.SeedMatchingType) VisibilityParseException(uk.gov.gchq.gaffer.commonutil.elementvisibilityutil.exception.VisibilityParseException) StreamSupport(java.util.stream.StreamSupport) Edge(uk.gov.gchq.gaffer.data.element.Edge) IncludeIncomingOutgoingType(uk.gov.gchq.gaffer.operation.graph.SeededGraphFilters.IncludeIncomingOutgoingType) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Logger(org.slf4j.Logger) ElementVisibility(uk.gov.gchq.gaffer.commonutil.elementvisibilityutil.ElementVisibility) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) AggregatorUtil(uk.gov.gchq.gaffer.store.util.AggregatorUtil) VisibilityEvaluator(uk.gov.gchq.gaffer.commonutil.elementvisibilityutil.VisibilityEvaluator) Predicate(java.util.function.Predicate) Collection(java.util.Collection) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) Set(java.util.Set) Entity(uk.gov.gchq.gaffer.data.element.Entity) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) 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) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) Collections(java.util.Collections) Entity(uk.gov.gchq.gaffer.data.element.Entity) Element(uk.gov.gchq.gaffer.data.element.Element) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Example 3 with EdgeId

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

the class EntitySeedTest method shouldBeRelatedToEdgeIdWhenSourceEqualsVertex.

@Test
public void shouldBeRelatedToEdgeIdWhenSourceEqualsVertex() {
    // Given
    final String source = "source";
    final String destination = "destination";
    final EntityId seed = new EntitySeed(source);
    final EdgeId relatedSeed = mock(EdgeId.class);
    given(relatedSeed.getSource()).willReturn(source);
    given(relatedSeed.getDestination()).willReturn(destination);
    // Then
    assertTrue(seed.isRelated((ElementId) relatedSeed).isMatch());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 4 with EdgeId

use of uk.gov.gchq.gaffer.data.element.id.EdgeId 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);
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ElementId(uk.gov.gchq.gaffer.data.element.id.ElementId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 5 with EdgeId

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

the class EntitySeedTest method shouldNotBeRelatedToEdgeIdWhenVertexNotEqualToSourceOrDestination.

@Test
public void shouldNotBeRelatedToEdgeIdWhenVertexNotEqualToSourceOrDestination() {
    // Given
    final String source = "source";
    final String destination = "destination";
    final boolean directed = true;
    final EntityId seed = new EntitySeed("other vertex");
    final EdgeId relatedSeed = mock(EdgeId.class);
    given(relatedSeed.getSource()).willReturn(source);
    given(relatedSeed.getDestination()).willReturn(destination);
    given(relatedSeed.isDirected()).willReturn(directed);
    // Then
    assertFalse(seed.isRelated((ElementId) relatedSeed).isMatch());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeId (uk.gov.gchq.gaffer.data.element.id.EdgeId)40 Test (org.junit.jupiter.api.Test)27 JSONSerialisationTest (uk.gov.gchq.gaffer.JSONSerialisationTest)18 EntityId (uk.gov.gchq.gaffer.data.element.id.EntityId)15 Edge (uk.gov.gchq.gaffer.data.element.Edge)14 ElementId (uk.gov.gchq.gaffer.data.element.id.ElementId)14 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)8 HashMap (java.util.HashMap)5 Key (org.apache.accumulo.core.data.Key)4 FreqMap (uk.gov.gchq.gaffer.types.FreqMap)4 ArrayList (java.util.ArrayList)3 DirectedType (uk.gov.gchq.gaffer.data.element.id.DirectedType)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 HashSet (java.util.HashSet)2 Element (uk.gov.gchq.gaffer.data.element.Element)2 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 SeedMatching (uk.gov.gchq.gaffer.operation.SeedMatching)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 Schema (uk.gov.gchq.gaffer.store.schema.Schema)2 Collection (java.util.Collection)1