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