Search in sources :

Example 11 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId 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 12 with EntityId

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

the class EntitySeedTest method shouldBeRelatedToEntityId.

@Test
public void shouldBeRelatedToEntityId() {
    // Given
    final EntityId seed1 = new EntitySeed("vertex");
    final EntityId seed2 = new EntitySeed("vertex");
    // Then
    assertTrue(seed1.isRelated(seed2).isMatch());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 13 with EntityId

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

the class EntitySeedTest method shouldBeEqualWhenVerticesEqual.

@Test
public void shouldBeEqualWhenVerticesEqual() {
    // Given
    final String vertex = "vertex";
    final EntityId seed1 = new EntitySeed(vertex);
    final EntityId seed2 = new EntitySeed(vertex);
    // Then
    assertEquals(seed1, seed2);
    assertEquals(seed1.hashCode(), seed2.hashCode());
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JSONSerialisationTest(uk.gov.gchq.gaffer.JSONSerialisationTest) Test(org.junit.jupiter.api.Test)

Example 14 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId 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 15 with EntityId

use of uk.gov.gchq.gaffer.data.element.id.EntityId 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)

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