use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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.operation.data.EntitySeed in project Gaffer by gchq.
the class AddElementsHandler method updateElementIndex.
private void updateElementIndex(final Element element, final MapImpl mapImpl) {
if (element instanceof Entity) {
final Entity entity = (Entity) element;
final EntitySeed entitySeed = new EntitySeed(entity.getVertex());
mapImpl.addIndex(entitySeed, element);
} else {
final Edge edge = (Edge) element;
edge.setIdentifiers(edge.getSource(), edge.getDestination(), edge.isDirected(), EdgeSeed.MatchedVertex.SOURCE);
final EntitySeed sourceEntitySeed = new EntitySeed(edge.getSource());
mapImpl.addIndex(sourceEntitySeed, edge);
final Edge destMatchedEdge = new Edge(edge.getGroup(), edge.getSource(), edge.getDestination(), edge.isDirected(), EdgeSeed.MatchedVertex.DESTINATION, edge.getProperties());
final EntitySeed destinationEntitySeed = new EntitySeed(edge.getDestination());
mapImpl.addIndex(destinationEntitySeed, destMatchedEdge);
final EdgeSeed edgeSeed = new EdgeSeed(edge.getSource(), edge.getDestination(), edge.isDirected());
mapImpl.addIndex(edgeSeed, edge);
}
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed 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.operation.data.EntitySeed in project Gaffer by gchq.
the class IfTest method shouldJsonSerialiseAndDeserialiseWithSingleValue.
@Test
public void shouldJsonSerialiseAndDeserialiseWithSingleValue() {
// Given
final If op = new If.Builder<>().input(new EntitySeed("1")).condition(true).then(new GetElements()).otherwise(new GetAllElements()).build();
// When
final byte[] json = toJson(op);
JsonAssert.assertEquals(String.format("{%n" + " \"class\" : \"uk.gov.gchq.gaffer.operation.impl.If\",%n" + " \"input\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.operation.data.EntitySeed\",%n" + " \"class\" : \"uk.gov.gchq.gaffer.operation.data.EntitySeed\",%n" + " \"vertex\" : \"1\"%n" + " }, %n" + " \"condition\" : true,%n" + " \"then\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetElements\"%n" + " },%n" + " \"otherwise\" : {%n" + " \"class\" : \"uk.gov.gchq.gaffer.operation.impl.get.GetAllElements\"%n" + " }%n" + "}"), StringUtil.toString(json));
final If deserialisedObj = fromJson(json);
// Then
assertNotNull(deserialisedObj);
assertEquals(new EntitySeed("1"), deserialisedObj.getInput());
}
use of uk.gov.gchq.gaffer.operation.data.EntitySeed in project Gaffer by gchq.
the class IfTest method shouldThrowErrorForTryingToUpdateOperationsWithTooFewOps.
@Test
public void shouldThrowErrorForTryingToUpdateOperationsWithTooFewOps() {
// Given
final GetElements getElements = new GetElements.Builder().input(new EntitySeed("1")).build();
final If<Object, Object> ifOp = new If.Builder<>().condition(false).build();
final Collection<Operation> opList = Lists.newArrayList(getElements);
// When / Then
assertThatIllegalArgumentException().isThrownBy(() -> ifOp.updateOperations(opList)).withMessage("Unable to update operations - exactly 3 operations are required. Received 1 operations");
}
Aggregations