Search in sources :

Example 86 with EntityId

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

the class AggregationSchemaLoader 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);
            entity.putProperty(TestPropertyNames.PROP_1, 1);
            entity.putProperty(TestPropertyNames.PROP_2, 1L);
            entity.putProperty(TestPropertyNames.PROP_3, "1");
            entity.putProperty(TestPropertyNames.VISIBILITY, "public");
            addToMap(entity, entities);
        }
        final Entity secondEntity = new Entity(TestGroups.ENTITY, SOURCE + i);
        secondEntity.putProperty(TestPropertyNames.COUNT, 1L);
        secondEntity.putProperty(TestPropertyNames.PROP_1, 1);
        secondEntity.putProperty(TestPropertyNames.PROP_2, 1L);
        secondEntity.putProperty(TestPropertyNames.PROP_3, "1");
        secondEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
        addToMap(secondEntity, entities);
        final Entity thirdEntity = new Entity(TestGroups.ENTITY, DEST + i);
        thirdEntity.putProperty(TestPropertyNames.COUNT, 1L);
        thirdEntity.putProperty(TestPropertyNames.PROP_1, 1);
        thirdEntity.putProperty(TestPropertyNames.PROP_2, 1L);
        thirdEntity.putProperty(TestPropertyNames.PROP_3, "1");
        thirdEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
        addToMap(thirdEntity, entities);
        final Entity fourthEntity = new Entity(TestGroups.ENTITY, SOURCE_DIR + i);
        fourthEntity.putProperty(TestPropertyNames.COUNT, 1L);
        fourthEntity.putProperty(TestPropertyNames.PROP_1, 1);
        fourthEntity.putProperty(TestPropertyNames.PROP_2, 1L);
        fourthEntity.putProperty(TestPropertyNames.PROP_3, "1");
        fourthEntity.putProperty(TestPropertyNames.VISIBILITY, "public");
        addToMap(fourthEntity, entities);
        final Entity fifthEntity = new Entity(TestGroups.ENTITY, DEST_DIR + i);
        fifthEntity.putProperty(TestPropertyNames.COUNT, 1L);
        fifthEntity.putProperty(TestPropertyNames.PROP_1, 1);
        fifthEntity.putProperty(TestPropertyNames.PROP_2, 1L);
        fifthEntity.putProperty(TestPropertyNames.PROP_3, "1");
        fifthEntity.putProperty(TestPropertyNames.VISIBILITY, "private");
        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 87 with EntityId

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

the class AbstractCoreKeyRangeFactory method getRange.

private List<Range> getRange(final ElementId elementId, final GraphFilters operation, final SeededGraphFilters.IncludeIncomingOutgoingType inOutType) throws RangeFactoryException {
    if (elementId instanceof EntityId) {
        return getRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
    } else {
        final EdgeId edgeId = (EdgeId) elementId;
        final List<Range> ranges = new ArrayList<>();
        if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
            // EQUALS and RELATED seed matching.
            final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
            ranges.addAll(getRange(edgeId.getSource(), edgeId.getDestination(), directed, operation, inOutType));
        }
        // Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
        final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatching.SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
        if (doRelated && operation.getView().hasEntities()) {
            // Get Entities related to EdgeIds
            ranges.addAll(getRange(edgeId.getSource(), operation, false));
            ranges.addAll(getRange(edgeId.getDestination(), operation, false));
        }
        return ranges;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) Range(org.apache.accumulo.core.data.Range)

Example 88 with EntityId

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

the class RowRangeFactory method getRowRange.

@SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "If an element is not an Entity it must be an Edge")
public List<RowRange> getRowRange(final ElementId elementId, final GraphFilters operation) throws SerialisationException {
    if (elementId instanceof EntityId) {
        return getRowRange(((EntityId) elementId).getVertex(), operation, operation.getView().hasEdges());
    } else {
        final EdgeId edgeId = (EdgeId) elementId;
        final List<RowRange> ranges = new ArrayList<>();
        if (operation.getView().hasEdges() && DirectedType.areCompatible(operation.getDirectedType(), edgeId.getDirectedType())) {
            // Get Edges with the given EdgeSeed - This is applicable for
            // EQUALS and RELATED seed matching.
            final DirectedType directed = DirectedType.and(operation.getDirectedType(), edgeId.getDirectedType());
            // To do that we need to create 2 ranges
            if (DirectedType.isEither(directed)) {
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), false, true), true));
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), true, true), true));
            } else {
                ranges.add(new RowRange(getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), false), true, getEdgeRowId(edgeId.getSource(), edgeId.getDestination(), directed.isDirected(), true), true));
            }
        }
        // Do related - if operation doesn't have seed matching or it has seed matching equal to RELATED
        final boolean doRelated = !(operation instanceof SeedMatching) || !SeedMatchingType.EQUAL.equals(((SeedMatching) operation).getSeedMatching());
        if (doRelated && operation.getView().hasEntities()) {
            // Get Entities related to EdgeIds
            ranges.addAll(getRowRange(edgeId.getSource(), operation, false));
            ranges.addAll(getRowRange(edgeId.getDestination(), operation, false));
        }
        return ranges;
    }
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) RowRange(org.apache.hadoop.hbase.filter.MultiRowRangeFilter.RowRange) EdgeId(uk.gov.gchq.gaffer.data.element.id.EdgeId) ArrayList(java.util.ArrayList) DirectedType(uk.gov.gchq.gaffer.data.element.id.DirectedType) SeedMatching(uk.gov.gchq.gaffer.operation.SeedMatching) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 89 with EntityId

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

the class GetAdjacentIdsHandlerTest method shouldReturnHBaseRetriever.

@Test
public void shouldReturnHBaseRetriever() throws OperationException, StoreException {
    // Given
    final Iterable<EntityId> ids = mock(Iterable.class);
    final Context context = mock(Context.class);
    final User user = mock(User.class);
    final HBaseStore store = mock(HBaseStore.class);
    final HBaseRetriever<GetElements> hbaseRetriever = mock(HBaseRetriever.class);
    final GetAdjacentIdsHandler handler = new GetAdjacentIdsHandler();
    final GetAdjacentIds getAdjacentIds = new GetAdjacentIds.Builder().inputIds(ids).option("option1", "optionValue").inOutType(SeededGraphFilters.IncludeIncomingOutgoingType.INCOMING).directedType(DirectedType.DIRECTED).view(new View()).build();
    given(context.getUser()).willReturn(user);
    final ArgumentCaptor<GetElements> getElementsCaptor = ArgumentCaptor.forClass(GetElements.class);
    given(store.createRetriever(getElementsCaptor.capture(), eq(user), eq(ids), eq(true))).willReturn(hbaseRetriever);
    // When
    final GetAdjacentIdsHandler.ExtractDestinationEntityId result = (GetAdjacentIdsHandler.ExtractDestinationEntityId) handler.doOperation(getAdjacentIds, context, store);
    // Then
    assertSame(hbaseRetriever, result.getInput());
    final GetElements getElements = getElementsCaptor.getValue();
    assertSame(ids, getElements.getInput());
    assertTrue(getElements.getView().getEntities().isEmpty());
    assertEquals(getAdjacentIds.getDirectedType(), getElements.getDirectedType());
    assertEquals(getAdjacentIds.getIncludeIncomingOutGoing(), getElements.getIncludeIncomingOutGoing());
    assertEquals("optionValue", getElements.getOption("option1"));
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) User(uk.gov.gchq.gaffer.user.User) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) HBaseStore(uk.gov.gchq.gaffer.hbasestore.HBaseStore) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Test(org.junit.jupiter.api.Test)

Example 90 with EntityId

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

the class GetElementsHandlerTest method shouldThrowExceptionIfAnOldOperationOptionIsUsed.

@Test
public void shouldThrowExceptionIfAnOldOperationOptionIsUsed() throws OperationException, StoreException {
    // Given
    final Iterable<EntityId> ids = mock(Iterable.class);
    final GetElementsHandler handler = new GetElementsHandler();
    final GetElements getElements = new GetElements.Builder().input(ids).option("hbasestore.operation.return_matched_id_as_edge_source", "true").build();
    // When / Then
    assertThatIllegalArgumentException().isThrownBy(() -> handler.doOperation(getElements, new Context(), null)).withMessageContaining("return_matched_id_as_edge_source");
}
Also used : EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) Context(uk.gov.gchq.gaffer.store.Context) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) 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